如何在多个ListSubItems中使用单个Timer.请帮忙. [英] How to use single Timer in multiple ListSubItems. Help please.

查看:80
本文介绍了如何在多个ListSubItems中使用单个Timer.请帮忙.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更正此代码?我使用winsock和listview.我希望所有的子项目在每次ConnectionRequest更改时都添加为计时器刻度.当我运行此代码时,计时器仅在最后一个子项目中运行.

How to correct this code? I use winsock and listview. I want all subitems added every ConnectionRequest changes as timer ticks. When I run this code the Timer only runs in the last subitem.

Option Explicit

Dim wIndex, wPort As Integer
Dim sec As Integer
Dim LM As ListItems

Private Sub Form_Load()
    sec = 0
    wIndex = 1
    wPort = 1
End Sub

Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    wIndex = wIndex + 1
    wPort = wPort + 1
    Load Winsock1(wIndex)
    With Winsock1(wIndex)
            .Close
            .LocalPort = wPort
            .Accept requestID
    End With
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Set LM = ListView1.ListItems(Index)
            LM.SubItems(2) = sec + 1
End Sub

推荐答案

Set LM = ListView1.ListItems(Index)


在timer方法的上下文中,什么是Index?可能是您需要wIndex代替吗?另外,将Option Explicit放置在模块的开头,以避免此类错误.

祝你好运!




您正在使用Index,但未在任何地方定义它(在您的示例中我看不到它).因此,您需要设置多个计时器,例如以load形式:


What is Index in the context of the timer method? Could it be you need wIndex instead? Also, place Option Explicit at the beginning of the module to avoid errors like this one.

Good luck!




You are using Index but it isn''t defined anywhere (I can''t see it in your example). So you would need to setup multiple timers, for example in the form load:

For i=1 to 10
  Load Timer1(i)
  Timer1(i).interval = 100
  Timer1(i).enabled = true
Next i



事件处理程序将需要Index作为参数.像这样的东西:



The event handler would need the Index as parameter. Something like this:

Private Sub Timer1(Index As Integer)
 '' Timer code
End Sub


这篇关于如何在多个ListSubItems中使用单个Timer.请帮忙.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆