Question msg box help

sibby

Member
Joined
Mar 24, 2012
Messages
6
Programming Experience
Beginner
Hi all I am very new to programming and im using Microsoft visual studio 2010, im trying to make a game, I have made the gui but I need to make a message box appear when the user clicks the play button (btnPlay) if the two players names haven't been entered in either box at the top (lblPlayerName One) (lblPlayerNameTwo) anyone have any help they can give me on this ? Thanks.
 
Hi guys, rather than start a new thread I thought id use this one to ask another question as it is still related to message boxes.
I have my Game working now and the code sorted to figure out which player has won, I however want to change the text in the message box from player o (or player X) is the winner to the name that they have entered before they start the game in a text box, the text box is called txtPlayerName1 here is my current code:
MsgBox("player o is the winner")

I just want the o to be what the user has entered into the text box txtPlayerName1, I know its something simple, I just simply cant remember how to do it, any help would be greatly appreciated thanks guys.
 
I think ive figured it out, I just did this and it works

MsgBox("the winner is " & txtPlayerName1.Text)

thanks guys
 
You should be using the newer NET MessageBox.Show() method instead of the old legacy MsgBox() function:

MessageBox.Show("The winner is " & txtPlayerName1.Text)
 
Hi, thanks for your reply Ii am going to change it but could you explain why i should use messagebox.show() rather than msgbox() ? (this is purely for my own education since im fairly new to programming) thanks
 
The .NET methods work with all the languages in Visual Studio. So if you decide to code in C#, the newer .NET methods will work, but the old VB functions will not. Also, eventually at some point, Microsoft may decide to discontinue the old functions in future versions of Visual Studio. So it's a good idea to learn the newer methods from the start.
 
The .NET methods work with all the languages in Visual Studio. So if you decide to code in C#, the newer .NET methods will work, but the old VB functions will not. Also, eventually at some point, Microsoft may decide to discontinue the old functions in future versions of Visual Studio. So it's a good idea to learn the newer methods from the start.

ahh right thanks for that, I don't suppose you have any idea how I can get another message box to show up once the user has clicked OK in the previous message box do you ?
 
MessageBox arguments

You need to use more arguments in the MessageBox.Show() method. The first argument is the main text. The second is the title text. The third is the MessageBoxButtons option. It will display the programmed buttons on the MessageBox window which the user must click. You have several choices. For the third argument, type:

MessageBoxButtons.

After the dot, you will see a list of available button groups.
You need to save the result to an integer input. Here is an example:


VB.NET:
        Dim ans As Integer
        ans = MessageBox.Show("Did you pass the test?", "Math Test", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        MessageBox.Show("DialogResult: 6 = Yes; 7 = No", "Your answer was " & ans.ToString)
        If ans = DialogResult.Yes Then 
              MessageBox.Show("Satisfactory") 'same as If ans = 6
        ElseIf ans = DialogResult.No Then 
              MessageBox.Show("Unsatisfactory") 'same as If ans = 7
        End If
 
Back
Top