954,141 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

If, Else, and ElseIf in VB Button

Hello! I m struggling with this button and/or code to work. The button with Process.Start opens any folder I want if I do not use Ifs and Elses, but I do need to open folder based on user selection of name in the combobox and one choice from two radio buttons. Can someone help? I am knew not just to VB but to programming as a whole (I am doing it with VB Express Edition 2008) Thank you.

'Open folder pertaining to current person and task
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

If ComboBox1.Text = "Lastname, Firstname" Then
If RadioBtn1.Checked = True Then
Process.Start("C:\Employee Records\City\State1\Lastname, Firstname\2008")
Else
If ComboBox1.Text = "Lastname, Firstname" Then
If RadioBtn2.Checked = True Then
Process.Start("C:\Employee Records\City\State2\Lastname, Firstname\2008")
Else
End If
End If
End If
End If

If ComboBox1.Text = "Lastname2, Firstname" Then
If RadioBtn1.Checked = True Then
Process.Start("C:\Employee Records\City\State1\Lastname2, Firstname\2008")
Else
If ComboBox1.Text = "Lastname2, Firstname" Then
If RadioBtn2.Checked = True Then
Process.Start("C:\Employee Records\City\State2\Lastname2, Firstname\2008")
Else
End If
End If
End If
End If

End Sub


'the list would repeat many times

leokuz
Light Poster
36 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

try to modify your code like:

If ComboBox1.Text = "Lastname, Firstname" Then
            If RadioBtn1.Checked = True Then
                Process.Start("C:\Employee Records\City\State1\Lastname, Firstname\2008")
            ElseIf RadioBtn2.Checked = True Then
                Process.Start("C:\Employee Records\City\State2\Lastname, Firstname\2008")
            Else
            End If
ElseIf ComboBox1.Text = "Lastname2, Firstname" Then
           If RadioBtn1.Checked = True Then
                Process.Start("C:\Employee Records\City\State1\Lastname2, Firstname\2008")
            ElseIf RadioBtn2.Checked = True Then
                Process.Start("C:\Employee Records\City\State2\Lastname2, Firstname\2008")
            Else
            End If
End If
ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

if combo1.text <> "" then
If RadioBtn1.Checked = True Then
Process.Start("C:\Employee Records\City\State1\" & combo1.text &"\2008")
Else
Process.Start("C:\Employee Records\City\State2\" & combo1.text &"\2008")
end if
end if

cometburn
Junior Poster
122 posts since Feb 2008
Reputation Points: 12
Solved Threads: 19
 

you have posted your thread in wrong forum.
this forum is intended to visual basic 6 only.

move your thread from here and re-post it in vb.net forum. then only your question will be answered.

hope you got it.

choudhuryshouvi
Posting Pro
553 posts since May 2007
Reputation Points: 30
Solved Threads: 49
 

ryan_vietnow Wow! With your modification it works for second, third, etc. employees/names, but when I choose name that corresponds to first block/statement and click button nothing happens. Why do you think first statement (should I say block?) doesn't work?

leokuz
Light Poster
36 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

you have posted your thread in wrong forum. this forum is intended to visual basic 6 only.

move your thread from here and re-post it in vb.net forum. then only your question will be answered.

hope you got it.

Thank your for explaining this to me, and will do that of course (this is my first posting on this website), but since couple people already started helping me here and with some success then I'll wait couple more reply if it's OK. Thanks again.

leokuz
Light Poster
36 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

What do you mean by first statement? the first value of the combobox?

cometburn
Junior Poster
122 posts since Feb 2008
Reputation Points: 12
Solved Threads: 19
 

cometburn I have tried your way, but nothing happens. I'll check more maybe typo on my part.

leokuz
Light Poster
36 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 
What do you mean by first statement? the first value of the combobox?


I mean when I choose in my form person "Lastname, Firstname" that mentioned in the very begining of the code (following part) nothing happens:

'this part does not work
If ComboBox1.Text = "Lastname, Firstname" Then
If RadioBtn1.Checked = True Then
Process.Start("C:\Employee Records\City\State1\Lastname, Firstname\2008")
ElseIf RadioBtn2.Checked = True Then
Process.Start("C:\Employee Records\City\State2\Lastname, Firstname\2008")
Else
End If
'but this next part works when I click button
ElseIf ComboBox1.Text = "Lastname2, Firstname" Then
If RadioBtn1.Checked = True Then
Process.Start("C:\Employee Records\City\State1\Lastname2, Firstname\2008")
ElseIf RadioBtn2.Checked = True Then
Process.Start("C:\Employee Records\City\State2\Lastname2, Firstname\2008")
Else
End If
End If

leokuz
Light Poster
36 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 
What do you mean by first statement? the first value of the combobox?


Actually you said it better. Yes, when I choose the first value of the combobox and click button nothing happens (and yes I clicked one of the radio buttons also), but it may be important for you to know that the first value of combobox is also mentioned in the begining (first part) of code.

leokuz
Light Poster
36 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Never mind, the code does work. I don't know what I typed wrong first time, but I have copied the second part of working code to the first part and renamed directories (folders) and names and it works now very well. Thank you ryan_vietnow very much for help (it is your code that works) and all of you who replied to my post so quickly. I will surely want to come back again in the near future for your help guys. God bless!!!

leokuz
Light Poster
36 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

God bless you too.

cometburn
Junior Poster
122 posts since Feb 2008
Reputation Points: 12
Solved Threads: 19
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You