Results 1 to 18 of 18

Thread: Is this really possible ?[Resolved]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Is this really possible ?[Resolved]

    I want to use Select Case in this way (evaluation two values at the same time) , is it legal (It works half way though )?


    VB Code:
    1. 'Class member variables
    2.  Dim a As Integer
    3.  Dim b As Integer
    4.  
    5.  
    6. 'Inside a method .
    7. Select Case a AndAlso b
    8.  
    9.             Case a = 20, b = 40
    10.  
    11.             Case a = 70, b = 30
    12.  
    13.             Case a = 0, b = 1
    14.  
    15.         End Select
    Last edited by Pirate; Feb 12th, 2004 at 08:49 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi

    I find that your code works all the time. Why do you say "Halfway"?


    A shorter way would be


    select case true

    .................
    Last edited by taxes; Feb 12th, 2004 at 08:02 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I don't think it's going to solve the problem but how would you write the cases to evalutate two variables ?

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    After trying your code I edited my first reply just as you were posting.


    If using Select Case True the leave the rest of your code as it was:


    Select Case True
    Case a = 20, b = 40

    Case a = 70, b = 30

    Case a = 0, b = 1

    End Select


    or

    Select Case a AndAlso b

    Case (a = 20, b = 40)

    Case (a = 70, b = 30)

    Case (a = 0, b = 1)

    End Select


    I have no problems with any of them
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by Pirate
    I don't think it's going to solve the problem but how would you write the cases to evalutate two variables ?
    VB Code:
    1. Select Case True
    2.  
    3.             Case a = 20 And b = 40
    4.  
    5.             Case a = 70 And b = 30
    6.  
    7.             Case a = 0 And b = 1
    8.  
    9. End Select

    Does that work?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    On looking at MSDN AndAlso, I see that it states a boolean comparison is required, so may be it does not work consistently with non boolean variables, but I have not found that to be correct yet. If you have, post a sample, please.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Cheers taxes , that works .

    Yes , crptcblade I used that and it works too.

  8. #8
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi crptcblade


    Yes, although the code I posted was OR I have tried it with AND.

    BUT see my last post and wait for Pirate's reply in case it is not consistent.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi Pirate,

    REf. my first response to you.


    "I find that your code works all the time. Why do you say "Halfway"?"



    Any enlightenment? Bearing in mind my subsequent comments on the MSDN notes.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  10. #10

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    It seems consistent after couple of testing .

  11. #11

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by taxes
    Hi Pirate,

    REf. my first response to you.

    "I find that your code works all the time. Why do you say "Halfway"?"

    Any enlightenment? Bearing in mind my subsequent comments on the MSDN notes.
    For example :

    When a = 0 and b =1
    If I check this case like this

    VB Code:
    1. Select Case a AndAlso b
    2.  
    3.             Case a = 0, b = 0
    4. msgbox "first case"
    5.             Case a = 0, b = 1
    6. msgbox "second case"
    7.         End Select

    This would returns msgbox "first case" . Because it evaluates a as true and forget about the rest .

  12. #12
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi Pirate,


    Of course it does,


    the "," is an OR operator not an AND
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  13. #13

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by taxes
    Hi Pirate,


    Of course it does,
    the "," is an OR operator not an AND
    Yes , it's true . But it's a bit confusing when I even tried this one and was the same result :
    VB Code:
    1. Case a = 0 AndAlso b = 1

    If clauses are usually better and safer but longer .

  14. #14
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi Pirate,

    "Yes , it's true . But it's a bit confusing when I even tried this one and was the same result :

    visual basic code:--------------------------------------------------------------------------------Case a = 0 AndAlso b = 1"


    We are going round in ever decreasing circles here. The above works perfectly O.K. although it is unnecessarliy long. You must be doing something else wrong in your code. Are you declaring your variables in a location which make them invisible to your Select Case procedure/method?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  15. #15

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This is how I used it anyway . I set the variables a and b from different locations and I made sure have been set to different values every time .

    VB Code:
    1. Private a As Integer
    2. Private b As Integer
    3.  
    4.  
    5.     Private Sub ValidateMe()
    6.         Select Case a AndAlso b
    7.             Case a = 0 And b = 0
    8.                 MsgBox("index0  index0")
    9.             Case a = 0 And b = 1
    10.                 MsgBox("index0  index1")
    11.             Case a = 0 And b = 2
    12.                 MsgBox("index0  index2")
    13.             Case a = 1 And b = 0
    14.                 MsgBox("index1  index0")
    15.         End Select
    16.     End Sub
    Last edited by Pirate; Feb 12th, 2004 at 10:27 AM.

  16. #16
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi Pirate,

    I think we are getting somewhere!


    It is the use of "0" (zero) which is causing the problem. The programme is confusing it with Boolean. Change your checks for numbers 1 & 2 and it will work.


    Man, I think we've both learned a bit here!
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  17. #17

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by taxes
    Hi Pirate,

    I think we are getting somewhere!


    It is the use of "0" (zero) which is causing the problem. The programme is confusing it with Boolean. Change your checks for numbers 1 & 2 and it will work.

    Man, I think we've both learned a bit here!
    What if I want to check if these vars has 0s ? I mean , my implementation depends on these 0s .

  18. #18
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Then you have to use the


    Select Case True

    Select Case True
    Case (a = 0 And b = 0)
    MsgBox("index0 index0")
    Case (a = 1 And b = 2)
    MsgBox("index1 index2")
    Case (a = 0 And b = 2)
    MsgBox("index0 index2")
    Case (a = 1 And b = 0)
    MsgBox("index1 index0")
    End Select

    It looks at though this is the reason for MSDN using the operator "AndAlso" as a Boolean.

    After all that I reckon were are ahead of the field on this one!!
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width