Results 1 to 5 of 5

Thread: ?? Select Case True ??

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    ?? Select Case True ??

    somebody recently told me that Select Case True is valid syntax and can be used as in the following.
    Code:
    Public Function Latitude(Y As Double,  X As Double) As Double
    
    'Function returns Radians in range -Pi/2 to Pi/2 (-90 to 90 degrees)
    'Quandrant assumed to be determined by sign of Y.
    'X assumed to be positive. Abs Function used to force positive value.
    'Hpi = Pi/2   Qpi = Pi/4  (90 & 45 degrees)
    
    Select Case True
        Case Abs(X) > Abs(Y)
            Latitude = Atn(Y / Abs(X))
        Case Abs(X) < Abs(Y)
            Latitude = Hpi - Atn(Abs(X) / Y)
        Case X = 0
            Latitude = 0
        Case Else
            Latitude = Qpi '45 degrees
      End If
    
    End Function
    I am going to try it. Does anybody know if this is going to work?

    It looks cleaner that ElseIf constructs.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  2. #2
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    What happens if more than one condition is met?
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    somebody recently told me that Select Case True is valid syntax and can be used as in the following.
    That statement is correct.

    An example:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Select Case True
    3.         Case 9 < 5
    4.             Print "one"
    5.         Case 5 < 9
    6.             Print "two"
    7.     End Select
    8. End Sub
    Or
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim a As Boolean, b As Boolean
    3. b = True
    4.  
    5.     Select Case True
    6.         Case a
    7.             Print "one"
    8.         Case b
    9.             Print "two"
    10.     End Select
    11.  
    12. End Sub
    ________
    Extreme q vaporizer
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:06 AM.

  4. #4
    Megatron
    Guest
    Originally posted by seoptimizer2001
    What happens if more than one condition is met?
    Then only the first condition that is met will be executed.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    Bruce Fox: Thanx for your reply. If I discover otherwise, I will post again. Meanwhile, I assume that two bright people cannot be wrong when they agree.

    It will be a while before I actually try it.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

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