I have built my own browser 9see attached code) however I would like to modify the code so that textbox1 reads a txt file at start and uses the contents of that text file to navigate to a URL of equal value to the text with in that text file. All this should happen at the launch of the web browser form.
Example of the text file contents would be http://www.testsite.com
Code as follows:
#Region "Webbrowser navigation"
Private Sub Go()
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Go()
End Sub
Private Sub TextBox1_keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Go()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.GoBack()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.GoForward()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Stop()
End Sub
#End Region
how can I best do this?
In the event handler for the form's Load event, do something like this:
TextBox1.Text = File.ReadAllText("StartUrl.txt")
Go()
However, unless you have some good reason to use a text file, I would suggest something more flexible and standard such as XML. If you don't mind using the standard app.config file, just add one of those to your project and you can use the ConfigurationManager class to read the setting.
Related
I am trying to click this button in WebBrowser Control
Im trying to make a web automation to purchase from gamestop im using visual basic 2010 express heres what my code looks like
Public Class Form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Document.GetElementById("mainContentPlaceHolder_dynamicContent_ctl00_RepeaterResultFoundTemplate_ResultFoundPlaceHolder_1_ctl00_1_ctl00_1_StandardPlaceHolderTop_3_ctl00_3_rptResults_3_res_0_btnAddToCart_0").InvokeMember("Click")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.Navigate("http://www.gamestop.com/browse?nav=16k-3-wwii,28zu0")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Document.GetElementById("cartcheckoutbtn").InvokeMember("Click")
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.Document.GetElementById("buyasguest").InvokeMember("Click")
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
WebBrowser1.Document.GetElementById("ShipTo_FirstName").SetAttribute("value", "Rob")
WebBrowser1.Document.GetElementById("ShipTo_LastName").SetAttribute("value", "Horton")
WebBrowser1.Document.GetElementById("ShipTo_City").SetAttribute("value", "San Diego")
WebBrowser1.Document.GetElementById("USStates").InvokeMember("Select")
WebBrowser1.Document.GetElementById("ShipTo_Line1").SetAttribute("value", "9295 PebbleStone Ln")
WebBrowser1.Document.GetElementById("ShipTo_PostalCode").SetAttribute("value", "92128")
WebBrowser1.Document.GetElementById("ShipTo_PhoneNumber").SetAttribute("value", "6194682282")
For Each ee As HtmlElement In WebBrowser1.Document.All
If ee.InnerText Is Nothing Then Continue For
If ee.InnerText = "California" Then ee.SetAttribute("Selected", True)
Next
WebBrowser1.Document.GetElementById("ShipTo_EmailAddress").SetAttribute("value", TextBox1.Text)
For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If element.GetAttribute("class") = "btn_positive ats-checkoutbtn" Then
element.InvokeMember("click")
End If
Next
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Im trying to click on this button and i inspect elemented it and this is what showed up **
(CONTINUE CHECKOUT ▶)
**
How Do I make it click this i tried Id but it has no id
btw im new to this just trying to make a auto web automation software to purchase games The code thats there when i inspect element it is on the top top top
You are actually trying to click a link and not an input button.
The link has an onclick attribute that contains javascript and returns false.
So you can either find that link or you can just execute the Javascript that the link executes submitshipto()
WebBrowser1.InvokeScript("submitshipto()")
Or:
For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
If element.GetAttribute("class") = "btn_positive ats-checkoutbtn" Then
element.InvokeMember("click")
End If
Next
Say I have two Excel files and a VBA code file:
File1.xlsx
File2.xlsx
Macro.vb
Using Visual Basic I am attempting to create a Windows form program that will allow me to Browse for File1, File2 and the Macro file.
Once the files are selected, the macro needs to use data from both File1 and File2 and update File1.
Here is a pic of the form, and the lines of code for it.
Public Class frmStuff
Private Sub btnBrowse1_Click(sender As System.Object, e As System.EventArgs) Handles btnBrowse1.Click
End Sub
Private Sub btnBrowse2_Click(sender As System.Object, e As System.EventArgs) Handles btnBrowse2.Click
End Sub
Private Sub btnBrowse3_Click(sender As System.Object, e As System.EventArgs) Handles btnBrowse3.Click
End Sub
Private Sub txtFile1_Text(sender As System.Object, e As System.EventArgs) Handles txtFile1.Text
End Sub
Private Sub txtFile2_Text(sender As System.Object, e As System.EventArgs) Handles txtFile2.Text
End Sub
Private Sub txtMacro_Text(sender As System.Object, e As System.EventArgs) Handles txtMacro.Text
End Sub
Private Sub btnRun_Click(sender As System.Object, e As System.EventArgs) Handles btnRun.Click
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
End Sub
End Class
Do the Excel files need to be open for the macro to run?
If they do could I also please have help on opening the Excel files.
Sorry, was being a little impulsive. I have since worked on this and have got it working to a certain point.
The issues that I am now having and will post if I can not resolve myself.
Cheers anyway
I edited my question and heres the whole code i used
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'GradesDBDataSet.tblGrades' table. You can move, or remove it, as needed.
Me.TblGradesTableAdapter.Fill(Me.GradesDBDataSet.tblGrades)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TblGradesBindingSource.MoveNext()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
TblGradesBindingSource.RemoveCurrent()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TblGradesBindingSource.MovePrevious()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TblGradesBindingSource.MoveLast()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TblGradesBindingSource.MoveFirst()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TblGradesBindingSource.AddNew()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
On Error GoTo saveErr
TblGradesBindingSource.EndEdit()
TblGradesTableAdapter.Update(GradesDBDataSet.tblGrades)
MsgBox("Record Save ", MsgBoxStyle.Information)
saveErr:
Exit Sub
End Sub
End Class
Hello Everyone... i have a problem using this code. . to save data to ms access from vb.net
i just follow a tutorial in youtube. it works BUT when i close the program then minutes later I run it again, data doesnt saved. . . Why? .
And can you suggest whats is the best way to Add, DELETE SAVE using vb.net? thanks eveyone ^_^
The most likely answer is that you are using a local data file that is overwritten each time you build.
Read this to learn how local data files are managed:
http://msdn2.microsoft.com/en-us/library/ms246989(VS.80).aspx
The solution in that case is to select the data file in the Solution Explorer, open the Properties window and set the Copy to output directory property to Copy if newer. The source file will only be copied to the output folder if you have changed that source file. That means that you can keep your test data between sessions.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser.Show()
WebBrowser.WebBrowser1.Navigate("www.carsonmap.com/hidalgo/login.cfm")
WebBrowser.WebBrowser1.Document.GetElementById("UserName").SetAttribute("value", "lrgvdc")
WebBrowser.WebBrowser1.Document.GetElementById("PW").SetAttribute("value", WebBrowser.TextBox2.Text)
End Sub
I need help with this code I keep getting an error saying Null Reference.
I got the idea from this Youtube Video check out to see what I am trying to accomplish.
https://www.youtube.com/watch?v=9EJXzWasTq4&list=PL42055376AE25291E&index=41
They used two buttons to enter to the website I am trying to enter to a website By using one button any ideas why doesnt it work.
When you use WebBrowser1.Navigate - it just begins to load document, the document is not available right away.
You need to use WebBrowser.DocumentCompleted Event to place your code that works on document's elements. E.g. something like
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser.Show()
WebBrowser.WebBrowser1.Navigate("www.carsonmap.com/hidalgo/login.cfm")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
WebBrowser.WebBrowser1.Document.GetElementById("UserName").SetAttribute("value", "lrgvdc")
WebBrowser.WebBrowser1.Document.GetElementById("PW").SetAttribute("value", WebBrowser.TextBox2.Text)
End Sub
I created a button and I need it to restart the form
I have no idea how to work on the visual basic what should i write
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
Do you mean Application.Restart() ?
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Application.Restart()
End Sub
Although in Visual Basic this does the same as in C#, it restarts the application not just clears the form.
In order to reload the form you simply need to do this in the form's Load event.
Me.Close()
Me.Show()
Try This..
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Application.Restart()
End Sub