2017-07-31 53 views
-1

我試圖在Visual Basic中做一個簡單的自動打字。我希望它以用戶選擇的時間間隔取得ListBox項目和輸出。Visual Basic Autotyper,輸出列表框項目

問題是我不知道如何使定時器的滴答事件發送每一行,並重新開始在列表的頂部,並繼續以這種方式循環。

表單設計:

enter image description here

我沒有列出太多的代碼,因爲實在是沒有太多列出呢。

Private Sub intervalTimer_Tick(sender As Object, e As EventArgs) Handles intervalTimer.Tick 

End Sub 
+1

你想在哪裏輸出?或者你只需​​要知道如何獲得第一行,並通過使用定時器循環? –

+0

帶有「秒」的TextBox不是讀取數字的好地方。你想接受像「4秒」,「5分鐘」和「0.15分鐘」的輸入嗎?您還需要考慮「4秒」,「4秒」和「ibfcweew」等輸入。改爲使用NumericUpDown控件,可能與填充了「分鐘」和「秒」的DropDown配對。 – djv

+0

'我希望它在用戶選擇的間隔時間內獲取ListBox項目和輸出。 – djv

回答

0

下面是一個代碼,但是你需要用ListView取代ListBox,這是相同的外觀,這只是工作代碼。

該代碼將從ListView中取出每行並使用MsgBox使用具有用戶選擇間隔的計時器輸出它,只需刪除消息框並在需要的地方輸出結果即可好:

首先在公共類中定義這個變量:

Dim ListedItems As String 

這是當你按下SET鍵設置間隔:

Try 
    intervalTimer.Interval = intervalTextBox1.Text * 1000 
Catch 
    MsgBox("The interval must be in purly seconds only!") 
End Try 

這裏是當你按下啓動按鈕:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    For Each LVI As ListViewItem In ListView1.Items 
     If ListedItems = "" Then 
      ListedItems = LVI.Text 
     Else 
      ListedItems &= vbLf & LVI.Text 
     End If 
    Next 
    Timer1.Start() 
End Sub 

這裏是當計時器滴答事件:

Private Sub intervalTimer_Tick(sender As Object, e As EventArgs) Handles intervalTimer.Tick 
    intervalTimer.Stop() 
    Dim SeprateLine As String 
    Dim Separator As Integer 
    If ListedItems.Contains(vbLf) Then 
     Separator = ListedItems.IndexOf(vbLf) 
     SeprateLine = ListedItems.Remove(Separator) 
     ListedItems = ListedItems.Substring(Separator + 1) 
    Else 
     SeprateLine = ListedItems 
     ListedItems = "" 
    End If 
    MsgBox(SeprateLine) 
    If ListedItems <> "" Then 
     intervalTimer.Start() 
    End If 
End Sub 

最後我希望這會幫助你,你需要什麼:)