locked
can I use if..else within select case??? RRS feed

  • Question

  • User1494693177 posted

    vb.net programming....

    can I use if..else withing select case..

    if yes.. why are my if..else statements always skipped ....?

     

    I mean the first if ..else statement was always executed  when a case is chosen, thus the second if..else stmt was always skipped even though the conditions matched

    or a better solution to this prob wld be appreciated...............

     

    heres my code snippets

     

     

     

    Select Case dropValue

    Case Is = 1

    If netID = 3 Then

    test.Text = "pc1 P network 3 "

     

    elseIf netID = 5 Then

    test.Text = "pc1 P network 5 "

    End If

    Case Is = 2

    If netID = 3 Then

    test.Text = "pc2/3 P network 3 "

    elseif netID =4 then

    test.Text = "pc2/3 P network 3 "

    End If

    Wednesday, July 2, 2008 4:32 AM

All replies

  • User312496708 posted

    Try the following code 

    Select Case dropValue
    Case Is = 1
    test.Text = "pc1 P network "
    Case Is = 2
    test.Text = "pc2/3 P network "

    If netID = 3 Then
    test.Text += " 3"
    elseIf netID = 5 Then
    test.Text += " 5 "
    elseif netID =4 then
    test.Text += " 3 "
    End If

    Wednesday, July 2, 2008 5:07 AM
  • User-990694832 posted

    A person could try this.

    Select dropValue

    Case Is = 1 AndAlso netID = 3

    test.Text = "pc1 P network 3 "

    Case Is = 1 AndAlso netID = 5

    test.Text = "pc1 P network 5 "

    Case Is = 2 AndAlso netID = 3

    test.Text = "pc2/3 P network 3 "

    Case Is = 2 AndAlso netID = 4

    test.Text = "pc2/3 P network 3 "

    End Select

     

    Hope this helps DK

    Wednesday, July 2, 2008 8:50 AM
  • User1494693177 posted

    unfortunately   none of that works for me....

    what went wrong....

    Wednesday, July 2, 2008 9:23 PM
  • User-990694832 posted

    Please verify the values going into dropvalue and netID.

    What is the context of this, might be a postback issue if a web app.

    What method is this in?

    DK 

    Thursday, July 3, 2008 8:17 AM