RichTextBox Reader with a Timer
I have a Button that shows an OpenFileDialog
, so I can pick a .txt
file and show it in RichTextBox1
.
I want that when I press Go
, the text file is read line by line with 5 sec delay and show each line read in Label4
.
I have 5 lines in test.txt
file. Now I choose this file from my software that I'm working on and when I choose this file its place the result of my test.txt
file into the RichTextBox
.
I want that when I click Go
, it reads line 1 for 5 sec and when read it, show it in Label4
. Then, after 5 seconds, it starts reading line 2 and show it in Label4
and so on until all lines are read.
Here is my code:
Imports System.Runtime.InteropServices
Public Class Form1
<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)>
Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Public Structure Struct_INTERNET_PROXY_INFO
Public dwAccessType As Integer
Public proxy As IntPtr
Public proxyBypass As IntPtr
End Structure
Private Sub UseProxy(ByVal strProxy As String)
Const INTERNET_OPTION_PROXY As Integer = 38
Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
Dim struct_IPI As Struct_INTERNET_PROXY_INFO
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")
Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))
Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Label4.Text = (RichTextBox1.Text)
UseProxy(Label4.Text)
WebBrowser1.Navigate(TextBox3.Text)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If (OpenFileDialog1.ShowDialog = DialogResult.OK) Then
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
End If
End Sub
End Class
vb.net
add a comment |
I have a Button that shows an OpenFileDialog
, so I can pick a .txt
file and show it in RichTextBox1
.
I want that when I press Go
, the text file is read line by line with 5 sec delay and show each line read in Label4
.
I have 5 lines in test.txt
file. Now I choose this file from my software that I'm working on and when I choose this file its place the result of my test.txt
file into the RichTextBox
.
I want that when I click Go
, it reads line 1 for 5 sec and when read it, show it in Label4
. Then, after 5 seconds, it starts reading line 2 and show it in Label4
and so on until all lines are read.
Here is my code:
Imports System.Runtime.InteropServices
Public Class Form1
<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)>
Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Public Structure Struct_INTERNET_PROXY_INFO
Public dwAccessType As Integer
Public proxy As IntPtr
Public proxyBypass As IntPtr
End Structure
Private Sub UseProxy(ByVal strProxy As String)
Const INTERNET_OPTION_PROXY As Integer = 38
Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
Dim struct_IPI As Struct_INTERNET_PROXY_INFO
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")
Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))
Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Label4.Text = (RichTextBox1.Text)
UseProxy(Label4.Text)
WebBrowser1.Navigate(TextBox3.Text)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If (OpenFileDialog1.ShowDialog = DialogResult.OK) Then
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
End If
End Sub
End Class
vb.net
2
Why are you showing us all this proxy code if the question is about looping through the RichTextBox Lines property with a timer? Hint: use a timer.
– LarsTech
Nov 15 '18 at 18:32
2
The problem is that you don't have any code to do any of what you said you wanted except to load the contents of a text file into a RichTextBox. Please edit your question to show the code that attempts to display a line every 5 seconds and remove the code that has nothing to do with the question.
– Blackwood
Nov 15 '18 at 18:50
add a comment |
I have a Button that shows an OpenFileDialog
, so I can pick a .txt
file and show it in RichTextBox1
.
I want that when I press Go
, the text file is read line by line with 5 sec delay and show each line read in Label4
.
I have 5 lines in test.txt
file. Now I choose this file from my software that I'm working on and when I choose this file its place the result of my test.txt
file into the RichTextBox
.
I want that when I click Go
, it reads line 1 for 5 sec and when read it, show it in Label4
. Then, after 5 seconds, it starts reading line 2 and show it in Label4
and so on until all lines are read.
Here is my code:
Imports System.Runtime.InteropServices
Public Class Form1
<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)>
Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Public Structure Struct_INTERNET_PROXY_INFO
Public dwAccessType As Integer
Public proxy As IntPtr
Public proxyBypass As IntPtr
End Structure
Private Sub UseProxy(ByVal strProxy As String)
Const INTERNET_OPTION_PROXY As Integer = 38
Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
Dim struct_IPI As Struct_INTERNET_PROXY_INFO
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")
Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))
Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Label4.Text = (RichTextBox1.Text)
UseProxy(Label4.Text)
WebBrowser1.Navigate(TextBox3.Text)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If (OpenFileDialog1.ShowDialog = DialogResult.OK) Then
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
End If
End Sub
End Class
vb.net
I have a Button that shows an OpenFileDialog
, so I can pick a .txt
file and show it in RichTextBox1
.
I want that when I press Go
, the text file is read line by line with 5 sec delay and show each line read in Label4
.
I have 5 lines in test.txt
file. Now I choose this file from my software that I'm working on and when I choose this file its place the result of my test.txt
file into the RichTextBox
.
I want that when I click Go
, it reads line 1 for 5 sec and when read it, show it in Label4
. Then, after 5 seconds, it starts reading line 2 and show it in Label4
and so on until all lines are read.
Here is my code:
Imports System.Runtime.InteropServices
Public Class Form1
<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)>
Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Public Structure Struct_INTERNET_PROXY_INFO
Public dwAccessType As Integer
Public proxy As IntPtr
Public proxyBypass As IntPtr
End Structure
Private Sub UseProxy(ByVal strProxy As String)
Const INTERNET_OPTION_PROXY As Integer = 38
Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
Dim struct_IPI As Struct_INTERNET_PROXY_INFO
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")
Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))
Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Label4.Text = (RichTextBox1.Text)
UseProxy(Label4.Text)
WebBrowser1.Navigate(TextBox3.Text)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If (OpenFileDialog1.ShowDialog = DialogResult.OK) Then
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
End If
End Sub
End Class
vb.net
vb.net
edited Nov 16 '18 at 10:24
Jimi
9,17741935
9,17741935
asked Nov 15 '18 at 18:20
Captain . AndreasCaptain . Andreas
33
33
2
Why are you showing us all this proxy code if the question is about looping through the RichTextBox Lines property with a timer? Hint: use a timer.
– LarsTech
Nov 15 '18 at 18:32
2
The problem is that you don't have any code to do any of what you said you wanted except to load the contents of a text file into a RichTextBox. Please edit your question to show the code that attempts to display a line every 5 seconds and remove the code that has nothing to do with the question.
– Blackwood
Nov 15 '18 at 18:50
add a comment |
2
Why are you showing us all this proxy code if the question is about looping through the RichTextBox Lines property with a timer? Hint: use a timer.
– LarsTech
Nov 15 '18 at 18:32
2
The problem is that you don't have any code to do any of what you said you wanted except to load the contents of a text file into a RichTextBox. Please edit your question to show the code that attempts to display a line every 5 seconds and remove the code that has nothing to do with the question.
– Blackwood
Nov 15 '18 at 18:50
2
2
Why are you showing us all this proxy code if the question is about looping through the RichTextBox Lines property with a timer? Hint: use a timer.
– LarsTech
Nov 15 '18 at 18:32
Why are you showing us all this proxy code if the question is about looping through the RichTextBox Lines property with a timer? Hint: use a timer.
– LarsTech
Nov 15 '18 at 18:32
2
2
The problem is that you don't have any code to do any of what you said you wanted except to load the contents of a text file into a RichTextBox. Please edit your question to show the code that attempts to display a line every 5 seconds and remove the code that has nothing to do with the question.
– Blackwood
Nov 15 '18 at 18:50
The problem is that you don't have any code to do any of what you said you wanted except to load the contents of a text file into a RichTextBox. Please edit your question to show the code that attempts to display a line every 5 seconds and remove the code that has nothing to do with the question.
– Blackwood
Nov 15 '18 at 18:50
add a comment |
1 Answer
1
active
oldest
votes
Add a Timer to your form in the designer, set the interval then handle the Timer.Tick event.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Timer1.Interval = 5000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Static i As Integer
If i < RichTextBox1.Lines.Count Then
Label1.Text = RichTextBox1.Lines(i)
i += 1
Else
Label1.Text = ""
Timer1.Stop()
End If
End Sub
That is working perfectly, but now i have a new issue, before i add this code you gave it to me, IP adress on Label4 getting use for proxy UseProxy(Label4.Text) But now its not using it as proxy
– Captain . Andreas
Nov 16 '18 at 8:57
Please ask a new question with the updated code.
– Mary
Nov 16 '18 at 16:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325669%2frichtextbox-reader-with-a-timer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add a Timer to your form in the designer, set the interval then handle the Timer.Tick event.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Timer1.Interval = 5000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Static i As Integer
If i < RichTextBox1.Lines.Count Then
Label1.Text = RichTextBox1.Lines(i)
i += 1
Else
Label1.Text = ""
Timer1.Stop()
End If
End Sub
That is working perfectly, but now i have a new issue, before i add this code you gave it to me, IP adress on Label4 getting use for proxy UseProxy(Label4.Text) But now its not using it as proxy
– Captain . Andreas
Nov 16 '18 at 8:57
Please ask a new question with the updated code.
– Mary
Nov 16 '18 at 16:31
add a comment |
Add a Timer to your form in the designer, set the interval then handle the Timer.Tick event.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Timer1.Interval = 5000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Static i As Integer
If i < RichTextBox1.Lines.Count Then
Label1.Text = RichTextBox1.Lines(i)
i += 1
Else
Label1.Text = ""
Timer1.Stop()
End If
End Sub
That is working perfectly, but now i have a new issue, before i add this code you gave it to me, IP adress on Label4 getting use for proxy UseProxy(Label4.Text) But now its not using it as proxy
– Captain . Andreas
Nov 16 '18 at 8:57
Please ask a new question with the updated code.
– Mary
Nov 16 '18 at 16:31
add a comment |
Add a Timer to your form in the designer, set the interval then handle the Timer.Tick event.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Timer1.Interval = 5000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Static i As Integer
If i < RichTextBox1.Lines.Count Then
Label1.Text = RichTextBox1.Lines(i)
i += 1
Else
Label1.Text = ""
Timer1.Stop()
End If
End Sub
Add a Timer to your form in the designer, set the interval then handle the Timer.Tick event.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Timer1.Interval = 5000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Static i As Integer
If i < RichTextBox1.Lines.Count Then
Label1.Text = RichTextBox1.Lines(i)
i += 1
Else
Label1.Text = ""
Timer1.Stop()
End If
End Sub
answered Nov 16 '18 at 4:28
MaryMary
3,6412820
3,6412820
That is working perfectly, but now i have a new issue, before i add this code you gave it to me, IP adress on Label4 getting use for proxy UseProxy(Label4.Text) But now its not using it as proxy
– Captain . Andreas
Nov 16 '18 at 8:57
Please ask a new question with the updated code.
– Mary
Nov 16 '18 at 16:31
add a comment |
That is working perfectly, but now i have a new issue, before i add this code you gave it to me, IP adress on Label4 getting use for proxy UseProxy(Label4.Text) But now its not using it as proxy
– Captain . Andreas
Nov 16 '18 at 8:57
Please ask a new question with the updated code.
– Mary
Nov 16 '18 at 16:31
That is working perfectly, but now i have a new issue, before i add this code you gave it to me, IP adress on Label4 getting use for proxy UseProxy(Label4.Text) But now its not using it as proxy
– Captain . Andreas
Nov 16 '18 at 8:57
That is working perfectly, but now i have a new issue, before i add this code you gave it to me, IP adress on Label4 getting use for proxy UseProxy(Label4.Text) But now its not using it as proxy
– Captain . Andreas
Nov 16 '18 at 8:57
Please ask a new question with the updated code.
– Mary
Nov 16 '18 at 16:31
Please ask a new question with the updated code.
– Mary
Nov 16 '18 at 16:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325669%2frichtextbox-reader-with-a-timer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Why are you showing us all this proxy code if the question is about looping through the RichTextBox Lines property with a timer? Hint: use a timer.
– LarsTech
Nov 15 '18 at 18:32
2
The problem is that you don't have any code to do any of what you said you wanted except to load the contents of a text file into a RichTextBox. Please edit your question to show the code that attempts to display a line every 5 seconds and remove the code that has nothing to do with the question.
– Blackwood
Nov 15 '18 at 18:50