Thursday, 5 September 2013

VB.NET: Nested If / Else

VB.NET: Nested If / Else

So I have a sub on a button click that does the following:
If the text entry within a combo box (cmbServerInstall.Text) is blank,
firstly it will force the user to make a selection before proceeding.
Else, a string (strGameServer) is populated with the text within the combo
box (cmbServerInstall.Text).
From here, a MessageBox will then show with a Yes/No option, asking if the
user wishes to proceed.
Here is where things are going wrong.
What I want to happen
If the user selects yes, then I want to use another if/else to determine
what was stored in the string strGameServer. Depending on what this is set
to, it will launch one of two batch files (I understand the file paths are
the same at the moment, I plan to update this at a later date).
If the user selects no, I want it to remove the selection from the
combobox cmbServerInstall.
What is happening as it stands
Basically the shell command launches the batch file REGARDLESS of whether
or not MsgBoxResult is Yes or No.
Could anyone kindly take a look at the code below and point me in the
direction of where I am going wrong? Nested IFs seem to be getting the
better of me.
Thanks
Damon
Dim strGameServer As String
If cmbServerInstall.Text = "" Then
MessageBox.Show("Please select a game server to install", "No game
server selected", MessageBoxButtons.OK,
MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Else
strGameServer = cmbServerInstall.Text
MessageBox.Show("You have chosen" + " " + strGameServer + "." + "
" + "Please confirm you wish to proceed with your selection.",
"Confirm game server selection", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
If MsgBoxResult.Yes Then
If strGameServer = "Counter-Strike: Global Offensive" Then
Shell("C:\Users\Damon\Desktop\YorkshaLAN Server
Creator\YorkshaLAN Server Setup.bat",
AppWinStyle.NormalFocus)
Else : strGameServer = "Team Fortress 2"
Shell("C:\Users\Damon\Desktop\YorkshaLAN Server
Creator\YorkshaLAN Server Setup.bat",
AppWinStyle.NormalFocus)
End If
Else
cmbServerInstall.Text = ""
End If
cmbServerInstall.Text = ""
cmbServerInstall.Enabled = False
btnServerGoInstall.Enabled = False
End If
End Sub

No comments:

Post a Comment