none
Help a noob day RRS feed

  • Question

  • using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                String[] nouns = "Man Woman Animal World".Split(' ');
                String[] adjs = "Funny Sleepy Boring Exciting".Split(' ');
                var rand = new Random();
                var noun = nouns[rand.Next(0, 3)];
                var adj = adjs[rand.Next(0, 3)];
                for (int i = 0; i < nouns.Length + adjs.Length; i++) ;
                richTextBox1.AppendText(string.Join(" ", nouns, adjs));

    • Edited by Brandonoobo Saturday, August 1, 2020 8:51 PM
    Saturday, August 1, 2020 5:33 PM

All replies

  • First of all, this is a Visual Basic foum, not a c# one - there are other forums available.

    Secondly: difficult to 'help' someone who just posts a piece of code' with no sign of a question.


    Regards Les, Livingston, Scotland

    Saturday, August 1, 2020 5:37 PM
  • That's odd I did put a description in at the top. I tried editing it because it wasn't looking right and then it said I was spamming after the third try. It is a visual basics question in my opinion and I would very much appreciate help. I am trying to figure out how to get two groups of values to randomly combine and print out into a richtextbox I can't seem to find anything so the code I posted is obviously wrong and was hoping someone could give me an example. I am getting system.string as the output in the richtextbox. Is there a C# section on this forum? I am using visual basics and C# to make a "random" gamer tag generator as a good learning tool. The "code" I wrote was just what I could come up with from examples of stuff I've seen so I knew it was wrong but maybe you could edit it for me and get my desired output because I know it's close, I just don't know where to find what I need.







    • Edited by Brandonoobo Saturday, August 1, 2020 8:56 PM
    Saturday, August 1, 2020 8:51 PM
  • Hi

    OK, here is an example that may help.  It probably isn't quite what you are wanting, but it could offer some pointers.

    This is a stand alone example. Needs a Form1 containing a RichTextBox1 and a Button1.  Each click of the Button will clear the RTB and show a new list (there are so few word so the list is very repetitive).  Once you add a whole bunch more nouns and adjectives you will get a better picture of what is going on.

    ' Form1 with a RichTextBox1
    ' and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
    	' declared here and can be used throughout
    	Dim rand As New Random
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		RichTextBox1.Clear()
    		Dim nouns() As String = "Man Woman Animal World".Split(" "c)
    		Dim adjs() As String = "Funny Sleepy Boring Exciting".Split(" "c)
    		For i As Integer = 0 To 19
    			RichTextBox1.AppendText(String.Join(" ", nouns(rand.Next(0, nouns.Count)), adjs(rand.Next(adjs.Count)), vbCrLf))
    		Next
    	End Sub
    End Class


    Regards Les, Livingston, Scotland


    Saturday, August 1, 2020 11:38 PM
  • THANK YOU!
    Sunday, August 2, 2020 1:19 AM
  • Hi Brandonoobo,

    If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 3, 2020 5:45 AM
    Moderator