Trả lời mọi thắc mắc của bạn


Liệt kê những bài viết mới nhất

Bài viết mớiNgười viếtVào lúc
paltalk code HdAd
Sun Mar 06, 2016 1:28 am
vb ListView HdAd
Sun Mar 06, 2016 1:00 am
Find occurent of character in string nth HdAd
Sat Jan 16, 2016 10:48 pm
Send listbox items to textbox HdAd
Wed Jan 13, 2016 9:55 pm
[VB] Find word in listbox items HdAd
Wed Jan 13, 2016 7:55 pm
code cho hint2 HdAd
Wed Jan 13, 2016 3:22 pm
[vb] Font RTB HdAd
Tue Dec 29, 2015 10:29 am
[vb] selected text RTB HdAd
Tue Dec 29, 2015 9:06 am
[vb] send unicode text HdAd
Tue Dec 29, 2015 9:03 am
[vb] format multi richtextbox HdAd
Tue Dec 29, 2015 9:01 am
Trang web tai cac bang sang che HdAd
Mon Dec 28, 2015 1:28 pm
[VB] Sử dụng resource của chính chương trình HdAd
Sat Dec 26, 2015 8:56 pm
[vb] Phân biệt class và Module HdAd
Thu Dec 24, 2015 2:39 pm
[VB] MY API and Functions declaration HdAd
Mon Dec 21, 2015 1:45 pm
[vb] Khai báo và sử dụng hàm Setforeground HdAd
Mon Dec 21, 2015 1:29 pm
[VB] Sử dụng hàm Sendmessage để gửi tiếng việt, và format richtextbox HdAd
Mon Dec 21, 2015 1:26 pm
[VB] Find menu context handle/ID by SPY++ HdAd
Fri Dec 18, 2015 1:20 pm
[VB] Find menu context handle/ID - Vu Hai Ninh HdAd
Fri Dec 18, 2015 1:00 pm
[VB] Find menu context handle/ID HdAd
Fri Dec 18, 2015 12:54 pm
[VB] Sleep in VB program HdAd
Thu Dec 17, 2015 7:48 pm
[VB] CLose window if found HdAd
Wed Dec 16, 2015 7:07 pm
[VB] Không cho thay đổi kích cỡ form khi chạy HdAd
Wed Dec 16, 2015 3:28 pm
[VB] Không cho thay đổi text box khi chạy HdAd
Wed Dec 16, 2015 3:22 pm
[VB] Tìm cửa sổ và Button bằng FindWindow & FindWindowsEx HdAd
Wed Dec 16, 2015 3:16 pm
[VB] Xóa text mặc định của text box khi click HdAd
Wed Dec 16, 2015 3:12 pm


You are not connected. Please login or register

Dùng Timer để send text (VB)

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Dùng Timer để send text (VB) on Thu Nov 26, 2015 11:02 am

HdAd

avatar
Admin
Code 1: CaulacboVB
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
Sending each line to Notepad is a bit more involved. Although Notepad in theory does support StandardInput there are issues getting it to work, so SendKeys can be used instead:
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

View user profile http://hoidap.probb.org

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum