943,728 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Feb 22nd, 2008
-1

If, Else, and ElseIf in VB Button

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Feb 22nd, 2008
0

Re: If, Else, and ElseIf in VB Button

try to modify your code like:

vb Syntax (Toggle Plain Text)
  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
Reputation Points: 28
Solved Threads: 71
Posting Pro
ryan_vietnow is offline Offline
578 posts
since Aug 2007
Feb 22nd, 2008
0

Re: If, Else, and ElseIf in VB Button

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.
Reputation Points: 12
Solved Threads: 19
Junior Poster
cometburn is offline Offline
122 posts
since Feb 2008
Feb 22nd, 2008
0

Re: If, Else, and ElseIf in VB Button

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.
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Feb 22nd, 2008
0

Re: If, Else, and ElseIf in VB Button

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
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Feb 22nd, 2008
0

Re: If, Else, and ElseIf in VB Button

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Feb 22nd, 2008
0

Re: If, Else, and ElseIf in VB Button

What do you mean by first statement? the first value of the combobox?
Reputation Points: 12
Solved Threads: 19
Junior Poster
cometburn is offline Offline
122 posts
since Feb 2008
Feb 22nd, 2008
0

Re: If, Else, and ElseIf in VB Button

cometburn I have tried your way, but nothing happens. I'll check more maybe typo on my part.
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Feb 22nd, 2008
0

Re: If, Else, and ElseIf in VB Button

Click to Expand / Collapse  Quote originally posted by cometburn ...
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
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Feb 22nd, 2008
0

Re: If, Else, and ElseIf in VB Button

Click to Expand / Collapse  Quote originally posted by cometburn ...
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
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: adodb
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: I need a help about VB 6 -> reason





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC