Multiple Lines Webrequest From RichTextBox - vb.net

Ok so i'm trying to make multiple webrequests, but in a different way.
i'm trying to let my users add the websites on each line of a richtextbox and when they click a button it will run this:
Dim request As WebRequest = WebRequest.Create("Website")
But not for the hole richtextbox, but for every line, so say the richtextbox has all these lines:
google.com
facebook.com
youtube.com
and once they click the button, those sites will be put into the space where it says Website.
If anyone can help me with this, thank you!
Also sorry if this is messy, I don't think there's any other way to present this information!

This could get you started. Textboxes have a Lines property that contains a collection of strings from each line of the textbox (See this MSDN page for reference)
Dim arrUrls() As String = RichTextBox1.Lines
For i As Integer = 0 To UBound(arrUrls)
If Not arrUrls(i).Length=0 Then Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(arrUrls(i))
Next

Related

check if richtextbox contains textbox

I want to create a very simple login form is VB
All of the usernames are in a textfile on my webserver.
So first the program downloads that textfile with:
Dim wc As New WebClient()
Dim datawc.DownloadString("url.txt")
After that my program put the the text in a richbox with
RichTextBox1.Text = data
Then the programs checks if the text that is entered in the textbox is also in the richtextbox.
Now the problem is that if i fill in the textbox 1122, and in the richtextbox is 1133 that the program returns a correct response.
Sorry for my bad english
I just fixed it myself by using this condition
If data.Contains(TextBox1.Text) Then

Can't turn combobox value into a string - Visual Basic

I am trying to use a combobox as an input for resolving an IP address, but I have an issue. When a user selected their desired IP from the list, and click 'test', it doesn't seem to recognise the input of the combobox. If I replace the combobox with a text box, it works fine - for some reason, it won't accept the combobox input, even thought the result of both that and the textbox are exactly the same, they are both simple strings.
Dim ip As String = combobox1.Text
_sock = New TcpClient(ip, port)
If I change 'combobox1.Text' to textbox1.Text, and then enter the IP manually into textbox1, it doesn't work! I also tried 'combobox1.Text.ToString', and that didn't work. This is extremely frustrating, so a quick answer would be appreciated, thanks.
'Returns the Text that has been selected:
Dim ip As String = combobox1.SelectedItem
'Returns the Index of the selected Item (ascending from 0):
Dim ip As String = combobox1.SelectedIndex
Ok, I figured it out - the values in the data source for the combobox were taken from a text file, where each part of the string was taken from a different line. Therefore, instead of being 192.186.1.75 (for example), it was infact VbCrLf + 192.186.1.75, which is what caused the error. I guess my next question is, does anyone know how to stop that?
Edit - Nevermind, it's fixed now!
Thank you all for your help :)

Showing MsgBox() with nowait (no user input) is not the real issue

I had searched a lot how to display a Msgbox that will not wait the user input (pressing ok or cancel).
I found 3 solutiuons to this.
1- Display the MsgBox() in another thread or using BackgroundWorker()
2- Create a form that display the message, then closed the form by a timer and use it instead of Msgbox()
3- Using the API MessageBoxA()
Let say I have a loop from 1 to 100, and I want display a message for the i(counter)
When I test above 3 ways, I found that this is not the right way of doing it, I don't need a msgbox() to close by it self after showing the message, because that will display 100 dialog.
What I realy want is to display ONLY 1 MsgBox() and change the text accordingly.
I managed to do this using a a Form() as class and I did it using Application.DoEvents
I know it can be done using BackgroundWorker or Threading since alot of people advice against using Application.Doevents
Here is my code
Dim oWW As New WaitWindow With {.TopLevel = True,.TopMost = True,.StartPosition = FormStartPosition.CenterScreen}
oWW.Show(Me)
For i = 1 to 100
Threading.Thread.Sleep(500) ' Just to slowdown execution
oWW.SetMessage("Counter = " + i.ToString)
Next
oWW.Dispose()
Public Class WaitWindow
Sub SetMessage(ByVal Message As string)
lbl_message.Text = Message
Application.DoEvents
End Sub
End Class
WaitWindow is not more than a Form base class with a label (lbl_message)
That code works fine (display WaitWindowForm on center of currently displayed form only once, then I change the text)
I have 3 questions :
1- How to display the WaitWindowForm in the top right corner of my working form?
2- Is it possible to display the normal MsgBox() or MessageBox.Show() only once, then capture the text displayed and change it?
3- Which one is suitable for my issue (BackGroundWorker or Threading) and what the code in WaitWindow class I post will be if I decided to use Backgroundworker or Threading instead of Application.DoEvents (Changing the label text not showing new form with new text) ?
3 questions in one post.. humm.. who cares, I am not the one who will answer lol :)
Thanks in advance.
I think the issue that you're really encountering is that you're trying to use a message box for something it's not suited for. If you want to have text that constantly changes just add a text box in the upper right corner of your application and adjust it every time a new message needs to be shown.
You can also look up dialogu windows (search ".showdialog() vb.net" in google) might help as well.

HTTP get request in Visual Basic

I am totally new to VB as I have just started to learn it.
I have already created a user form with an input text box and a button. I want to be able to scan a barcode and implement it into this link: http://openean.kaufkauf.net/?ean=\[ean\]&cmd=query&queryid=200000000 replacing [ean] with the numbers from the barcode.
Afterwards make a HTTP GET request and having the result pop up in a message box. I do not know how to take the value of the text box, paste it into the link and make the request.
Assuming your text box is named TextBox1, try:
Dim request As String = String.Format("http://openean.kaufkauf.net/?ean={0}&cmd=query&queryid=200000000", TextBox1.Text)
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString(request)
MessageBox.Show(result)
Note that the above code will wait for the result from the server before allowing the user to interact with the application again, but it's enough to get you started.

Vb.net click link by looking for String!

I am working on a vb.net program, I want to click a hyperlink on a page, the source look like this:
messages for Today, 2010-10-19
I want to check it everyday too!
I tried to click it with the following methods(Both couldn't click the link!):
Dim theElementCollection As HtmlElementCollection
Dim ctrlIdentity As String
theElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
For Each curElement As HtmlElement In theElementCollection
ctrlIdentity = curElement.GetAttribute("innerText").ToString
If ctrlIdentity = Today.Date.ToString(Today.Date.ToString("dd")) Then
curElement.InvokeMember("click")
End If
Next
and I tried this code too:
If Me.WebBrowser1.Document.Links(i).InnerHtml.Contains(Today.Date.ToString("dd")) Then
Me.WebBrowser1.Document.Links(i).InvokeMember("Click")
End If
Next
Any help would be appreciated! Thanks!
I've found that the best way to click links in a WebBrowser is using javascript. Try something like this:
WebBrowser1.Navigate("javascript:function%20x(){document.getElementById('foo').click()}x()")
You'll need to rewrite your above code in javascript but that's a piece of cake. You can test your javascript by copy-pasting it directly into the browser's location bar. This is also a reliable way to fill out forms.
Caveats:
Notice how the work that I want to do is wrapped in a function. This is needed if you want the javascript to do multiple statements. Wrap in a function and then invoke the function.
You can't navigate to a URL more than around 500 characters. (The limit isn't exactly 512 but it's close.) There's no warning, either, so keep it in mind.
Make sure you wait until the page is loaded. The ReadyState = Complete and IsBusy = False.
Clicking like this doesn't always generate the usual events that you get when you click a link.
"%20" is hex for space. I don't recall if this was strictly necessary in my code. Try it both ways.