Hi,

I'm almost done with my coding and I'm trying to implement blocking the user from putting anything but numbers into one textbox and then autocaps'n everything put into another. I've been looking through the web and can't find anything to point me in the right direction.

Also, I can't figure out how to add an int to a string in a messagebox. my code that I have is:

Convert.ToString(totalScore);
                finalMessage = ("");
                //Displays the users final score along with a finished message.
                MessageBox.Show(finalMessage.ToString(), "Question 10/10", MessageBoxButtons.OK, MessageBoxIcon.Information);

or at least thats what im trying now, originally it was all in the message box but I need it to display the message then the totalScore int.

Any help would be great!

Recommended Answers

All 5 Replies

Strings and integers cannot be added together without operator overloading. If you want to validate a numerical value in a text box use this.

string str = someString.Text.Trim();

        int num;

        bool isNum = int.TryParse(str, out num);

        if (isNum)

           {
                //continue doing what you want
           }

// To convert a string to uppercase use
String.ToUpper();

Hi Youg, welcome :)
The simplest way to add an int to a string goes something like this: MyString + MyInt.ToString();
In the code snippet section here you will find different topics that handle your first question. Happy searching and happy computing!

Thanks for the speedy replies, and now the message box works like I wanted it to so thanks ddande for that!

I still cant get the text box to only allow the user to enter numbers in one and capitalised in the other. I'm making a quiz program which the user has to press submit for the answer to be counted. Do I put the code in the textbox or the submit button? Both pieces of code are below so you can see what I've got there already:

private void txtAnswerL_TextChanged(object sender, EventArgs e)
        {
            
        }
private void lblSubmitL_Click(object sender, EventArgs e)
        {
            userAnswerL = (txtAnswerL.Text);
            if (userAnswerL == CorrectAnswerL[activeQuL])
            {
                totalScoreL++;                

            }
        }

Did you not find this snippet?

no i did not... thank you for linking me, it has been a long night at staring at code lol.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.