Exception.InnerException in vb.net - vb.net

This is my first time making a program using visual basic language. I thought my project is running smooth because every time I debug using visual studio the program is ok so I didn't mind checking the .exe file of the program but today I've found this error in the .exe file of the program
An error occured creating the form. See Exception.InnerException for details. The Error is: Could not load file or assembly 'AxInterop.WMPLib.Version=1.0.0.0 Culture=neutral. PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified
I don't understand why the program is running good in visual studio. but has errors in .exe
Here is the code of the form that has error
Public Class formVideo
Private Sub TestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2,
(Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2)
Call Disable(Me)
End Sub
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
Private Const SC_CLOSE As Integer = &HF060
Private Const MF_BYCOMMAND As Integer = &H0
Private Const MF_GRAYED As Integer = &H1
Private Const MF_ENABLED As Integer = &H0
Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)
' The return value specifies the previous state of the menu item (it is either
' MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates that the menu item does not exist.
Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)
Case MF_ENABLED
Case MF_GRAYED
Case &HFFFFFFFF
Throw New Exception("The Close menu item does not exist.")
Case Else
End Select
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Call Disable(Me)
End Sub
Private Sub btnMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMenu.Click
Me.Close()
formMenu.Show()
End Sub
Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
mpVideo.Ctlcontrols.play()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
mpVideo.Ctlcontrols.pause()
End Sub
Private Sub btnCPU_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCPU.Click
mpVideo.URL = "Resources\See How the CPU Works In One Lesson.avi"
End Sub
Private Sub btnMobo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMobo.Click
mpVideo.URL = "Resources\Understanding your motherboard.avi"
End Sub
Private Sub btnHDD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHDD.Click
mpVideo.URL = "Resources\What is a Hard Drive_ (HDD vs SSD_) - Computer Basics.avi"
End Sub
Private Sub btnRam_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRam.Click
mpVideo.URL = "Resources\What is RAM_ - Computer Basics.avi"
End Sub
Private Sub btnPSU_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPSU.Click
mpVideo.URL = "Resources\Testing the PC's PSU.avi"
End Sub
Private Sub btnVGA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVGA.Click
mpVideo.URL = "Resources\What is a GPU_ - Computer Basics.avi"
End Sub
Private Sub btnCooling_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCooling.Click
mpVideo.URL = "Resources\A Beginner's Guide to Water Cooling Your Computer.avi"
End Sub
Private Sub btnExtensions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExtensions.Click
mpVideo.URL = "Resources\Peripheral - Wiki Article.avi"
End Sub
Private Sub mpVideo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mpVideo.Enter
mpVideo.stretchToFit = True
End Sub
Private Sub btnFF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFF.Click
mpVideo.Ctlcontrols.fastForward()
End Sub
Private Sub btnRewind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRewind.Click
mpVideo.Ctlcontrols.fastReverse()
End Sub
End Class

Ok. Make sure that axinterop.dll is present on the directory that the solution file refers to, before compiling. Depending on which OS you have, will depend on how Visual Studio works. The Exception only triggers on a runtime error occurrence. And also, the compiled .exe file, has to be with the .pdb file and the .config file. Otherwise, it would not work. If all else fails, then reboot your device, and if it still fails after that, then it might be a complete internal runtime error.

Make sure that the axinterop dll is present in the application folder. To me it sounds like you only copied the executable from you bin folder.

Related

How Do I Click This Button? In Visual Basic 2010 WebBrowser control

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

How to save data to a text file?

Basically, I have this program, where you click a link and it opens it. But it doesn't save all the links I put in. There is a name list and link list. You can add links and names with the buttons, and then open link with 'watch'. I was primarily going to use this for youtubers and streamers. Here is the code.
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim NamePath As String = ("C:\Favoriter\NameList.txt\")
Dim nsr As StreamReader
nsr = New StreamReader(NamePath)
Do Until nsr.EndOfStream
lstName.Items.Add(nsr.ReadLine)
Loop
nsr.Close()
Dim URLPath As String = ("C:\Favoriter\URLList.txt\")
Dim usr As StreamReader
usr = New StreamReader(URLPath)
Do Until usr.EndOfStream
lstURL.Items.Add(usr.ReadLine)
Loop
usr.Close()
End Sub
Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim NamePath As String = ("C:\Favoriter\NameList.txt\")
Dim nsw As StreamWriter
nsw = File.CreateText(NamePath)
Dim NameItems As String
Do Until lstName.Items.Count.Equals(0)
NameItems = lstName.Items.Item(0)
lstName.Items.RemoveAt(0)
nsw.WriteLine(NameItems)
Loop
nsw.Flush()
nsw.Close()
Dim URLPath As String = ("C:\Favoriter\URLList.txt\")
Dim usw As StreamWriter
usw = File.CreateText(URLPath)
Dim URLItems As String
Do Until lstURL.Items.Count.Equals(0)
URLItems = lstURL.Items.Item(0)
lstURL.Items.RemoveAt(0)
usw.WriteLine(URLItems)
Loop
usw.Flush()
usw.Close()
End Sub
Private Sub lblTitle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTitle.Click
End Sub
Private Sub lstName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstName.SelectedIndexChanged
End Sub
Private Sub lstURL_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstURL.SelectedIndexChanged
End Sub
Private Sub txtName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
End Sub
Private Sub txtURL_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtURL.TextChanged
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
lstName.Items.Add(txtName.Text)
lstURL.Items.Add(txtURL.Text)
End Sub
Private Sub btnWatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWatch.Click
If lstURL.SelectedItem = True Then
Process.Start(lstURL.SelectedItem)
End If
End Sub
Private Sub lblName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblName.Click
End Sub
Private Sub lblURL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblURL.Click
End Sub
End Class
As first look i see you are using File.CreateText(Path), this function will overwrite the old file what ever it has data , so everytime after you write your data you delete them by overwriting, you can use
if File.Exists(Path) then
File.Open(Path)
else
File.CreateText(Path)
End If
like this you will not overwrite each time you write the text .

Insert,update delete in vb.net

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.

VB.net Form unexpectingly terminating

Hi I have the following form but cant figureout why its upbrubtly terminiating when difrent buttons are clicked?
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Dim TEST1 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
If TEST1 = 0 Then
Me.WebBrowser1.Navigate("http://www.hotmail.com")
End If
End Sub
Private Sub button1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub
Private Sub button2_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseLeave
Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.WebBrowser1.Navigate("file://C:\test\test")
Button1.Enabled = False
Button2.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.WebBrowser1.Navigate("file://C:\test")
Button2.Enabled = False
Button1.Enabled = True
End Sub
Private Sub button2_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
Dim TEST2 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
If TEST2 = 0 Then
Me.WebBrowser1.Navigate("http://www.hotmail.com")
End If
End Sub
The terms face book and hotmail are just random to keep company site private :)
I suspect the Mouse_Enter event and the Mouse_Leave events are not giving time to the webbrowser to fully load the document and maybe it is internally crashing.
Try checking if the webbrowser has finished working before navigating again and tell us:
Use
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete
Me.WebBrowser1.Navigate("http://www.google.com")
End if

Showing a message to the user if website does not open

I'm trying to show a message to the user if the requested website does not open (or the internet is not working). The message I want to show is
"Site is not working. Please contact the administrator."
How can I do this? Here's what I have
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("google.com")
Dim connectn As Boolean
If connectn = False Then
MsgBox("site not working please contact the developer")
End If
End Sub
Private Sub Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Back.Click
WebBrowser1.GoBack()
End Sub
Private Sub Forward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Forward.Click
WebBrowser1.GoForward()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.Stop()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.GoHome()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
WebBrowser1.Refresh()
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
End Sub
Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
End Sub
Private Sub WebBrowser1_DocumentCompleted_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
End Sub
End Class
It's best not to use the DocumentCompleted event handler as it will fire when a frame is complete, not necessarily the entire webpage. Instead use the following:
With WebBrowser1
.Navigate("google.com")
Do Until Not (.IsBusy)
Application.DoEvents()
Loop
Do Until .ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
Loop
End With
Other than that, if it is for a specific site you can find what the correct URL is and simply compare the "endstate" URL when the Webbrowser has completely loaded. If you want it to be generalized for any website you can find most information from this link about page event handling for navigation errors.