Results 1 to 2 of 2

Thread: Need advise in for loop

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    32

    Need advise in for loop

    Hi all,

    Recently, I have already ask a lot and here's another question. I wanted to use loop to loop Write_Text("A1", 1, 1), A2 = Write_Text("B1", 1, 1), ......


    Code:
    Private Sub Write_Text(ByRef A, ByVal B, ByVal C)
    
    List1.AddItem A & " | " & B & " | " & C
    
    End Sub
    
    Private Sub Run_Button_Click()
     
    Dim i As Integer
    
    for i = 1 To 2
    
    ' I wanted to go to Sub Data_Storage() and use loop to loop A1 and A2 in here
    
    next i
    
    End Sub
    
    Private Sub Data_Storage()
    
    A1 = Write_Text("A1", 102, 13)
    A2 = Write_Text("B1", 15, 19)
    A3 = Write_Text("B2", 19, 60)
                   :
                   :
    
    End Sub
    Need some advise.

    Thanks

  2. #2
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Need advise in for loop

    vb Code:
    1. 'create a User Defined Type to hold the parameters
    2. Private Type tIOCommand
    3.   sCmd as String
    4.   lValA as Long
    5.   lValB as Long
    6. End Type
    7.  
    8. Dim wtCmds() as tIOCommand 'declare a variable as the type
    9.  
    10. ReDim wtCmds(num_of_commands -1) 'dimension array, in case you have multiple lists
    11.  
    12. 'init the values
    13. wtCmds(0).sCmd = "A1"
    14. wtCmds(0).lValA = 102
    15. wtCmds(0).lValB = 13
    16. 'etc... do this for all of them... incrementing the index for each
    17.  
    18. Static lResumeOn as Long
    19. Dim i as Long
    20. 'Private? bolCancel as Boolean
    21. 'check to make sure it's valid...
    22. If lResumeOn > UBound(wtCmds) then lResumeOn = 0
    23.  
    24. For i = lResumeOn to UBound(wtCmds)
    25.   Write_Text(wtCmds(i).sCmd, wtCmds(i).lValA, wtCmds(i).lValB
    26.   DoEvents
    27.   If bolCancel = True then
    28.     lResumeOn = i + 1
    29.     Exit Sub
    30.   End If
    31. Next i
    32.  
    33. 'reset resume on
    34. lResumeOn = 0

    Experiment with that.

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