Code 1: CaulacboVB
Set timer: 5000s
Code2: Stackoverflow
I think the issue you are having is the fact that the timer keeps firing before you have clicked on your message box, i.e. There is a re-entrancy issue.
If you disable the timer when you go into the sub routine and enable it at the end you will see that it does indeed cycle through the lines:
Set timer: 5000s
- Code:
Dim j As Integer = 0 'dùng để đếm số dòng của textbox Private Sub Timer1_Tick(sender As Object, e As EventArgs) HandlesTimer1.Tick
If j < txtcontent.Lines.Length - 1 Then MsgBox(txtcontent.Lines(j)) 'Nội dung dòng 1 j += 1 'thêm 1s End If
End Sub
Code2: Stackoverflow
I think the issue you are having is the fact that the timer keeps firing before you have clicked on your message box, i.e. There is a re-entrancy issue.
If you disable the timer when you go into the sub routine and enable it at the end you will see that it does indeed cycle through the lines:
- Code:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Static j As Integer = 0
Dim lineCount As Integer = txtContent.Lines.Length
If j <= lineCount - 1 Then
MsgBox(txtContent.Lines(j)) 'textbox line
End If
j += 1
Timer1.Enabled = True
End Sub
- Code:
Private _notePadProcess As Process = Nothing
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Static j As Integer = 0
Dim lineCount As Integer = txtContent.Lines.Length
If j <= lineCount - 1 Then
WriteLineToNotePad(txtContent.Lines(j))
End If
j += 1
Timer1.Enabled = True
End Sub
<DllImport("user32.dll")>
Private Shared Function SetForegroundWindow(hWnd As IntPtr) As Boolean
End Function
Private Sub WriteLineToNotePad(line As String)
If _notePadProcess Is Nothing OrElse _notePadProcess.HasExited OrElse _notePadProcess.MainWindowHandle = IntPtr.Zero Then
Dim startInfo As New ProcessStartInfo("notepad.exe")
_notePadProcess = Process.Start(startInfo)
Do Until _notePadProcess.MainWindowHandle <> IntPtr.Zero
'wait
Loop
End If
SetForegroundWindow(_notePadProcess.MainWindowHandle)
SendKeys.Send(line + vbCr)
End Sub