[RESOLVED] replacing static url variables 'within a sub' with Textbox input
Alright in my last post, dunfiddlin helped me figure out how to pause this Sub (which is ran in/by a background worker)
In this post I'm trying to figure out how to replace URL variables..with 'textboxs' i can edit via my form.
Alright so here is my code...and I want to replace some of the url variables with TextBox's incase I want to collect names just in a certain contest thread. I did figure out how to place a Textbox for the # of seconds pausing though LoL :duck::duck: :goose:
Code:
Private Sub ParseUsers()
Dim pageSrc As String = GetStuff("http://www.my-forum.com/my-search/index.htm?get_forum_id_sub=11&thread_id=22&b=1")
Dim maxPages As Integer = GetMaxPages(pageSrc)
ProgressBar1.Maximum = maxPages
Profilelist.AddRange(ExtractUsers(pageSrc))
For i As Integer = 2 To maxPages
pageSrc = GetStuff("http://www.my-forum.com/my-search/index.htm?get_forum_id_sub=11&thread_id=22&b=" & i.ToString)
Profilelist.AddRange(ExtractUsers(pageSrc))
ProgressBar1.Value = i
Dim t As UInt64 = Now.Ticks
Do Until Now.Ticks - t >= TextBox3.Text * 10 ^ 7 'where TextBox3.Text is required delay in seconds
Loop
Next
IO.File.WriteAllLines("USERS.txt", Profilelist.ToArray)
End Sub
I don't know how to do this spacing/context wise...but here's what I'm wanting to replace
Code:
?get_forum_id_sub=11& (replace just the #11 with TextBox1.Text)
&thread_id=22& (replace just the #22 with TextBox2.Text)
Re: beginners help: replacing static url variables 'within a sub' with Textbox input
Pass TextBox1.Text and TextBox2.Text as parameters
Code:
Private Sub ParseUsers(ByVal id1 As String, ByVal id2 As String)
Dim pageSrc As String = GetStuff("http://www.my-forum.com/my-search/index.htm?get_forum_id_sub=" & id1 & "&thread_id=" & id2 & "&b=1")
Dim maxPages As Integer = GetMaxPages(pageSrc)
ProgressBar1.Maximum = maxPages
Profilelist.AddRange(ExtractUsers(pageSrc))
For i As Integer = 2 To maxPages
pageSrc = GetStuff("http://www.my-forum.com/my-search/index.htm?get_forum_id_sub=" & id1 & "&thread_id=" & id2 & "&b=" & i.ToString)
Profilelist.AddRange(ExtractUsers(pageSrc))
ProgressBar1.Value = i
Dim t As UInt64 = Now.Ticks
Do Until Now.Ticks - t >= TextBox3.Text * 10 ^ 7 'where TextBox3.Text is required delay in seconds
Loop
Next
IO.File.WriteAllLines("USERS.txt", Profilelist.ToArray)
End Sub
Re: beginners help: replacing static url variables 'within a sub' with Textbox input
Do you mean....like this?
Code:
Private Sub ParseUsers(ByVal TextBox1.Text As String, Byval TextBox2.Text As String)
Dim pageSrc As String = GetStuff("http://www.my-forum.com/my-search/index.htm?get_forum_id_sub=" & TextBox1.text & "&thread_id=" & TextBox2.text & "&b=1")
Dim maxPages As Integer = GetMaxPages(pageSrc)
ProgressBar1.Maximum = maxPages
Profilelist.AddRange(ExtractUsers(pageSrc))
For i As Integer = 2 To maxPages
pageSrc = GetStuff("http://www.my-forum.com/my-search/index.htm?get_forum_id_sub=" & TextBox1.text & "&thread_id=" & TextBox2.text & "&b=" & i.ToString)
Profilelist.AddRange(ExtractUsers(pageSrc))
ProgressBar1.Value = i
Dim t As UInt64 = Now.Ticks
Do Until Now.Ticks - t >= TextBox3.Text * 10 ^ 7 'where TextBox3.Text is required delay in seconds
Loop
Next
IO.File.WriteAllLines("USERS.txt", Profilelist.ToArray)
End Sub
Or do you mean I should re-name Textbox1 to id1 under the 'properties' window in vs2010.
Or do you mean like to 'declare' id1 as TextBox1.text under Public Class Form1
Sorry I'm not quite sure what 'as parameters' means yet. I'm still a total newbie :(
Re: beginners help: replacing static url variables 'within a sub' with Textbox input
Leave the sub as it is
Code:
Private Sub ParseUsers(ByVal id1 As String, ByVal id2 As String)
Dim pageSrc As String = GetStuff("http://www.my-forum.com/my-search/index.htm?get_forum_id_sub=" & id1 & "&thread_id=" & id2 & "&b=1")
Dim maxPages As Integer = GetMaxPages(pageSrc)
ProgressBar1.Maximum = maxPages
Profilelist.AddRange(ExtractUsers(pageSrc))
For i As Integer = 2 To maxPages
pageSrc = GetStuff("http://www.my-forum.com/my-search/index.htm?get_forum_id_sub=" & id1 & "&thread_id=" & id2 & "&b=" & i.ToString)
Profilelist.AddRange(ExtractUsers(pageSrc))
ProgressBar1.Value = i
Dim t As UInt64 = Now.Ticks
Do Until Now.Ticks - t >= TextBox3.Text * 10 ^ 7 'where TextBox3.Text is required delay in seconds
Loop
Next
IO.File.WriteAllLines("USERS.txt", Profilelist.ToArray)
End Sub
Then pass TextBox1.Text and TextBox2.Text when you call it, like this
Code:
ParseUsers(TextBox1.Text, TextBox2.Text)
Re: beginners help: replacing static url variables 'within a sub' with Textbox input
Re: beginners help: replacing static url variables 'within a sub' with Textbox input
Ok so leave it exactly as you wrote it...with id1 & id2
Then in this code....
Code:
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
ParseMembers()
End Sub
Your saying to simply change it to....
Code:
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
ParseUsers(TextBox1.Text, TextBox2.Text)
End Sub
And it will then be working & passing the #'s i manually put into my textboxs?
How does it know that TextBox1.Text is now id1? I'm just confused I guess. But I will definitely try this out & thank you so much!!
Re: beginners help: replacing static url variables 'within a sub' with Textbox input
It knows because you are telling it so
Code:
Private Sub ParseUsers(ByVal id1 As String, ByVal id2 As String)
It expects 2 string paramaters in your case this would be the text property of the textboxes you want to use. It could be a literal as well or any other string variable in any case they will be known to the sub as id1 and id2 no matter what the source because that is in the definition of the sub.
Re: beginners help: replacing static url variables 'within a sub' with Textbox input
Quote:
Originally Posted by
DataMiser
It knows because you are telling it so
Code:
Private Sub ParseUsers(ByVal id1 As String, ByVal id2 As String)
It expects 2 string paramaters in your case this would be the text property of the textboxes you want to use. It could be a literal as well or any other string variable in any case they will be known to the sub as id1 and id2 no matter what the source because that is in the definition of the sub.
Of course it works aweeeesome!
Thank you guys all so much!!!!