Results 1 to 4 of 4

Thread: Help with using Array and/or Loop

  1. #1

    Thread Starter
    Registered User
    Join Date
    Sep 2014
    Posts
    3

    Help with using Array and/or Loop

    This is my code:

    If circleChk(0) = True Then
    aff(0) = -1
    court(0) = 2
    obed(0) = 1
    hum(0) = 0
    und(0) = 0
    trust(0) = -2
    thou(0) = 1
    help(0) = 2
    End If

    If circleChk(1) = True Then
    aff(1) = 2
    court(1) = -1
    obed(1) = 0
    hum(1) = 1
    und(1) = 2
    trust(1) = 1
    thou(1) = -2
    help(1) = 1
    End If

    but I need to repeat this code up to circleChk(49) with all the values below different from each other. Is there a way to simplify the code? Because I need to do this again for triangle, square and star. My idea is to use array or loop, or a combination of both, but I can't seem to find the right code.

    Thanks in advance!

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Help with using Array and/or Loop

    Unless you have some way to calculate the value inside the if statement based on circleChk index, then I would say no a loop would not work. Not sure how you were thinking of using an array.

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,382

    Re: Help with using Array and/or Loop

    If the Values to be assigned (depending on the Index) are constant, an approach might be to use an INI-File and/or database (db could even be a small textfile with UDT's)

    Something like:

    Code:
    For i=1 to 49
    'Here code to read Record on Position i from INI/DB
    If circleChk(i) Then
    aff(i)=MyRecord.aff
    .
    .
    .
    help(i)=MyRecord.help
    End If
    Next
    Note: This is Aircode

    EDIT: Or you could Dim a 2D-Array with hardcoded values (filling the array at startup)
    something like
    Code:
    Dim MyArray(1 to 49, 1 To 8) As Long
    'Fill Up the Array
    
    For i=1 to 49
    
    If circleChk(i) Then
    aff(i)=MyArray(i, 1)
    .
    .
    .
    help(i)=MyArray(i, 8)
    End If
    
    Next
    Last edited by Zvoni; Sep 10th, 2014 at 08:50 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4

    Thread Starter
    Registered User
    Join Date
    Sep 2014
    Posts
    3

    Re: Help with using Array and/or Loop

    Quote Originally Posted by Zvoni View Post

    Or you could Dim a 2D-Array with hardcoded values (filling the array at startup)
    something like
    Code:
    Dim MyArray(1 to 49, 1 To 8) As Long
    'Fill Up the Array
    
    For i=1 to 49
    
    If circleChk(i) Then
    aff(i)=MyArray(i, 1)
    .
    .
    .
    help(i)=MyArray(i, 8)
    End If
    
    Next
    This would work. Thanks!

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