Results 1 to 20 of 20

Thread: loop list help

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    52

    loop list help

    Code:
    Dim i As Integer
    For i = 0 To List2.ListCount - 1
    msgbox(list2.list(i), "word")
    Next i
    list2.clear
    timer2.enabled = false
    it goes through the list timer2's interval. popups whatever the item is on. at the end of the list clears, and turns off the time. but its not working

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: loop list help

    What's not working? What's the problem?

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

    Re: loop list help

    If you want the selected item, the correct property is ListIndex.

    Code:
    Msgbox List2.list(list2.listindex)

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    19

    Re: loop list help

    Code:
    Private Sub Form_Initialize()
    For i = 0 To 10
     List1.AddItem i
    Next i
    End Sub
    
    Private Sub Timer1_Timer()
    Dim i As Integer
    For i = 0 To List1.ListCount - 1
    MsgBox List1.List(i), 64, "word"
    Next i
    List1.Clear
    Timer1.Enabled = False
    End Sub

  5. #5
    Junior Member
    Join Date
    May 2010
    Posts
    19

    Re: loop list help

    MsgBox List1.List(i), 64, "word"
    中间为64,参数不对,能运行么

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    52

    Re: loop list help

    hm no error on the loop list
    but does this look wrong at all

    Code:
    Private Sub Check3_Click()
    If Check3.Value = True Then
    Timer1.Enabled = True
    ElseIf Check3.Value = False Then
    Timer1.Enabled = False
    End If
    End Sub

  7. #7
    Junior Member
    Join Date
    May 2010
    Posts
    19

    Re: loop list help

    Code:
    Private Sub Check3_Click()
    If Check3.Value = 1 Then
    Timer1.Enabled = True
    Call Addstr
    ElseIf Check3.Value = 0 Then
    Timer1.Enabled = False
    End If
    End Sub
    
    Private Sub Form_Initialize()
    Check3.Value = 1
    End Sub
    
    Private Sub Timer1_Timer()
    Dim i As Integer
    If Check3.Value = 1 Then
    For i = 0 To List1.ListCount - 1
    MsgBox List1.List(i), 64, "word"
    Next i
    List1.Clear
    End If
    Timer1.Enabled = False
    End Sub
    
    Sub Addstr()
    For i = 0 To 10
     List1.AddItem i
    Next i
    End Sub

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: loop list help

    Quote Originally Posted by Hoppus View Post
    hm no error on the loop list
    but does this look wrong at all

    Code:
    Private Sub Check3_Click()
    If Check3.Value = True Then
       Timer1.Enabled = True
    ElseIf Check3.Value = False Then
       Timer1.Enabled = False
    End If
    End Sub
    Does it work?

  9. #9
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: loop list help

    You need to dim "i" outside of the timer event, then send one item each time the timer fires, then increment "i" after the "send" happens.

    For example:

    Code:
    Option Explicit
    
    Dim i As Integer
    
    Private Sub Timer1_Timer()
        sock.SendIM List2.List(i), "yep", False
        i = i + 1
        'also, check at this point to see if i is > than list2.listcount-1
    End Sub

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

    Re: loop list help

    Why not simply:

    vb Code:
    1. Timer1.Enabled = Check3.Value


  11. #11

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    52

    Re: loop list help

    well i dimmed i in form load.

    and

    Code:
    Private Sub Timer2_Timer()
    For i = 0 To List2.ListCount - 1
    sock.SendIM List2.List(i), "yep", False
    i = i + 1
    Next i
    'also, check at this point to see if i is > than list2.listcount-1
    End Sub
    and now it's only sock.sendim-ing to the first item on the list. :\

  12. #12
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: loop list help

    Take the For loop out of your timer event (refer back to my earlier post), and that should do it for you.

  13. #13

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    52

    Re: loop list help

    well when i take out that out, it errors on next i. and when i take that out. it only does sock.sendim for the first item in the list

  14. #14
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: loop list help


  15. #15
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: loop list help

    Can you post what code you now have?

    What you describe shouldn't be happening if 1) you dim i outside the timer event and 2) you take the For...Next out and increment i manually inside the timer event.

  16. #16
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: loop list help

    Duplicate Threads Merged

  17. #17

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    52

    Re: loop list help

    Quote Originally Posted by vbfbryce View Post
    Can you post what code you now have?

    What you describe shouldn't be happening if 1) you dim i outside the timer event and 2) you take the For...Next out and increment i manually inside the timer event.
    Code:
    Private Sub Timer2_Timer()
    sock.SendIM List2.List(i), "yep", False
    i = i + 1
    List2.Clear
    Timer2.Enabled = False
    End Sub
    Code:
    Private Sub Form_Load()
    Dim i As Integer
    End Sub
    I don't know if there's any specific way i should be adding items to the list. but this is what i have.

    Code:
    Dim lngIndex As Long
    Dim bFound As Boolean
    
    For lngIndex = 0 To List2.ListCount - 1
        If strUserName = List2.List(lngIndex) Then
            bFound = True
            Exit For
        End If
    Next
    
    If Not bFound Then
        List2.AddItem strUserName
    End If
    but yeah. when looping list, it only sock.sendim's to the first item in the list.

    help resolve?

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

    Re: loop list help

    See if this works for you
    Code:
    Private Sub Timer2_Timer()
    Static j As Integer
    
        sock.SendIM List2.List(j), "yep", False
        j = j + 1
        
        If j = List2.ListCount Then
            List2.Clear
            Timer2.Enabled = False
            j = 0
        End If
    End Sub

  19. #19

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    52

    Re: loop list help

    thanks markt. worked like a charm

  20. #20
    Hyperactive Member
    Join Date
    Sep 2009
    Location
    Lost in thought
    Posts
    349

    Re: loop list help

    The ''Dim i As Integer'' could not be seen in the Timer2 sub.

    It needed to look like this
    Code:
    Option Explicit
    Dim  i As Integer 'This is Public to the Form
    
    Private Sub Check3_Click()
     Timer1.Enabled = Check3.Value
    End Sub
    
    Private Sub Form_Load()
    Dim  i As Integer 'This is Private to the Form_Load
      i= 777
      Me.Caption = i
    End Sub
    
    Private Sub Timer1_Timer()
     i = i + 1
      If i > 3000 Then i = 0
      Me.Caption = i
    End Sub
    Note: Static j As Integer is best

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