none
How to get this to work? RRS feed

  • Question

  • Firstly, I am new to programming and new to this forum. I am using visual basics and C# to attempt to make a random gamer tag generator. I have found examples that are almost what I want but I do not know how to get two groups of values to randomly combine and print into a richtextbox. If you could either edit the code below or give me the desired example code that would be great. I have been trying for three days to find something to go off of so I just put this together from multiple examples and tried to make sense of it. I am currently getting system.string as the print out in the richtextbox so that must mean all of this code I tried to write is non sense.

    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));
    
    
    
    
    
    
    
    
    
    
    
            }
        }
    }
    If you can get me on the right track it'd really ease my mind.


    • Edited by Brandonoobo Saturday, August 1, 2020 9:03 PM error
    Saturday, August 1, 2020 9:02 PM

All replies

  • Hi Brandonoobo, 
    You need to use String.Join method to concatenate the elements of an array instead of the "nouns","adjs" array.
    Here is a code example you can refer to.

    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)];
        richTextBox1.AppendText(string.Join(" ", noun, adj));
    }

    The result:


    Best Regards,
    Daniel Zhang


    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.

    • Proposed as answer by BonnieBMVP Tuesday, August 4, 2020 4:49 AM
    Monday, August 3, 2020 2:00 AM
  • Hi Brandonoobo,
    Has your problem been solved? If it is resolved, we suggest that you mark it as the answer. So it can help other people who have the same problem find a solution quickly. 
    Best Regards,
    Daniel Zhang


    "Windows Forms General" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Windows Forms General" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Wednesday, August 5, 2020 9:32 AM