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.
Related
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
I've created a form in VB that requests some entries and through those entries a body for an email is created. Now I have to make a button that opens the default email client of the computer and populates the Body with the text that is generated through the form (I don't want it to send the email since the user is supposed to add the From and the Subject). I've managed to make it happen through this simple line :
Dim Text As String = Textbox1.Text
Process.Start("mailto:email#email.com?subject=Hello&body=" & Text)
However, when the email client opens the format of the body is messed up. There are supposed to be paragraphs and spaces but there aren't any. Can you help me fix this ?
In order for MailTo to work properly, you need to URL Encode your message. The following should work:
Dim Text As String = Textbox1.Text
Process.Start("mailto:email#email.com?subject=Hello&body=" & System.Web.HttpUtility.UrlEncode(Text))
I am trying to make a form on VB.NET that when a certain webpage is loaded into the web browser (in this case its a .txt file with a string of numbers). It will look for those numbers and if it finds them it will close that form and open another. I have tried to do it many times and my latest attempts came out with this code. Any help would be appreciated.
Dim passcontents As String
passcontents = WebBrowser.DocumentText = "test.com/test.txt"
If WebBrowser.DocumentText = "test.com/test.txt" And passcontents Then
ActualGen.Show()
Me.Close()
Else
End If
There are a couple of basic problems with the code you've posted.
1) Are you trying to test passcontents as a boolean or a string? You've defined it as a String, but then you are trying to assign the equality of two other strings to it, as you would a Boolean.
Try setting Option Strict On at the top of your code - it gives a few more helpful pointers to check in this case.
2) The If... Then condition is checking the same data as passcontents (may) already be providing. Are you just trying to check that the correct page is loaded, or do you want to check for certain page contents as well?
You appear to be getting mixed up between the browser's document URL and the loaded document contents.
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
I'm developing a windows forms application using VB.NET. I'm currently working on DataReport (by Microsoft, not Crystal). Everything works fine when using DataSet as DataSource. But I have a question on how am I going to put data to my DataReport from a user input? Preferably when the user is on the act of printing(clicking the print button in the ReportViewer), a Form will pop-up and ask him for input. That input I'm talking about is random names of people, and we don't have to track their names so there's no reason to put it on the database.
Here's my simple setup:
MainForm.vb (Form)
MyReportViewer (ReportViewer)
MyReport.rdlc (DataReport)
InputForm (Form)
MyInputBox (TextBox)
If it is impossible to do it on the act of printing. Maybe on the MainForm_Load event or before the generation of report can do.
I've searched the net for an hour but I'm out of luck.
I've found the answer, it's called ReportParameters.
Here's how to set it:
'Get input from user...
Dim OneParameter As String = InputBox("Enter something to display on report!", "Report Parameter")
'Prepare report parameters... The `SetParameters` requires array of `ReportParameter`...
Dim ReportParameters As New List(Of ReportParameter)
'Add the user input to `ReportParameter` array...
ReportParameters.Add(New ReportParameter("OneParameter", OneParameter, True))
'Set the `ReportParameters` of the `ReportViewer`...
FormWithReportViewer.TheReportViewer.LocalReport.SetParameters(ReportParameters)
FormWithReportViewer.Show()
FormWithReportViewer.Focus()
On the DataReport(.rdlc), we have to add a ReportParameters (Menu>Report>Report Parameters). The same name (OneParameter) should be used to avoid error. We can now use the parameter in our textbox, just put =Parameters!OneParameter.Value and we're done!
Note: We have to set the report parameters before rendering the report. If we cannot avoid that, refresh the report after adding parameters so it will be updated:
FormWithReportViewer.TheReportViewer.RefreshReport