If, Else, and ElseIf in VB Button

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster

If, Else, and ElseIf in VB Button

 
0
  #1
Feb 22nd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 570
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: If, Else, and ElseIf in VB Button

 
0
  #2
Feb 22nd, 2008
try to modify your code like:

  1. If ComboBox1.Text = "Lastname, Firstname" Then
  2. If RadioBtn1.Checked = True Then
  3. Process.Start("C:\Employee Records\City\State1\Lastname, Firstname\2008")
  4. ElseIf RadioBtn2.Checked = True Then
  5. Process.Start("C:\Employee Records\City\State2\Lastname, Firstname\2008")
  6. Else
  7. End If
  8. ElseIf ComboBox1.Text = "Lastname2, Firstname" Then
  9. If RadioBtn1.Checked = True Then
  10. Process.Start("C:\Employee Records\City\State1\Lastname2, Firstname\2008")
  11. ElseIf RadioBtn2.Checked = True Then
  12. Process.Start("C:\Employee Records\City\State2\Lastname2, Firstname\2008")
  13. Else
  14. End If
  15. End If
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 122
Reputation: cometburn is an unknown quantity at this point 
Solved Threads: 19
cometburn's Avatar
cometburn cometburn is offline Offline
Junior Poster

Re: If, Else, and ElseIf in VB Button

 
0
  #3
Feb 22nd, 2008
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
Last edited by cometburn; Feb 22nd, 2008 at 2:02 am.
Proud to be Philippine made...
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 538
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: If, Else, and ElseIf in VB Button

 
0
  #4
Feb 22nd, 2008
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.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster

Re: If, Else, and ElseIf in VB Button

 
0
  #5
Feb 22nd, 2008
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?
Last edited by leokuz; Feb 22nd, 2008 at 3:22 am. Reason: To clarify and correct typo error
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster

Re: If, Else, and ElseIf in VB Button

 
0
  #6
Feb 22nd, 2008
Originally Posted by choudhuryshouvi View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 122
Reputation: cometburn is an unknown quantity at this point 
Solved Threads: 19
cometburn's Avatar
cometburn cometburn is offline Offline
Junior Poster

Re: If, Else, and ElseIf in VB Button

 
0
  #7
Feb 22nd, 2008
What do you mean by first statement? the first value of the combobox?
Proud to be Philippine made...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster

Re: If, Else, and ElseIf in VB Button

 
0
  #8
Feb 22nd, 2008
cometburn I have tried your way, but nothing happens. I'll check more maybe typo on my part.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster

Re: If, Else, and ElseIf in VB Button

 
0
  #9
Feb 22nd, 2008
Originally Posted by cometburn View Post
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
Last edited by leokuz; Feb 22nd, 2008 at 3:37 am. Reason: to better explain
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster

Re: If, Else, and ElseIf in VB Button

 
0
  #10
Feb 22nd, 2008
Originally Posted by cometburn View Post
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.
Last edited by leokuz; Feb 22nd, 2008 at 3:41 am. Reason: to explain better
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 6297 | Replies: 11
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC