Results 1 to 3 of 3

Thread: is there a way to shorten this code:

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    Code:
    Randomize
    retVal = Int((20 * Rnd) + 1)
    If retVal = 1 Then Call fun1
    If retVal = 2 Then Call fun2
    If retVal = 3 Then Call fun3
    If retVal = 4 Then Call fun4
    If retVal = 5 Then Call fun5
    If retVal = 6 Then Call fun6
    If retVal = 7 Then Call fun7
    If retVal = 8 Then Call fun8
    If retVal = 9 Then Call fun9
    If retVal = 10 Then Call fun10
    If retVal = 11 Then Call fun11
    If retVal = 12 Then Call fun12
    If retVal = 13 Then Call fun13
    If retVal = 14 Then Call fun14
    If retVal = 15 Then Call fun15
    If retVal = 16 Then Call fun16
    If retVal = 17 Then Call fun17
    If retVal = 18 Then Call fun18
    If retVal = 19 Then Call fun19
    If retVal = 20 Then Call fun20
    is there a way to shorten this code?
    NXSupport - Your one-stop source for computer help

  2. #2
    Guest
    One way is to just make 1 function called fun and structure it like so:
    Code:
    Function fun(ByVal chType as Byte) As Long
    
        Select Case chType
            Case 1
                'Code for fun1
            Case 2
                'Code for fun2
            Case 3
                'Code for fun3
            Case 4
                'Code for fun4
            
            '...
            
            Case 18
                'Code for fun18
            Case 19
                'Code for fun19
            Case 20
                'Code for fun20
    End Function
    Then you could shorten the code to
    Code:
    Randomize
    Call fun(Int((20 * Rnd) + 1))

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    ok, thanks
    NXSupport - Your one-stop source for computer help

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