RGuillermo
asked on
.net app works in some computers and does not in some others
Hi Experts,
I have a very small app developed in visual studio 2012 with visual basic, it is a specific very small automatizacion of a website. Compiled with .net 4.5
The fact is it works fine in some computers and in some others it says:
"unhandled exception has ocurred un your application. If you click continue the application ill ignore this error and attempt to continue. If you click quit the application will close inmediately... object referenece not set to an instance of an object."
Below you will find the code
Please your support on this.
Best regards,
R
Imports System
Imports System.IO
Imports System.Collections
Imports System.Threading
Public Class broserwindow
Public MyFileName As String
Public MyNewLine As String
Dim w_pat_cod As String, w_azv_cod As String, w_ptl_usr As String, w_ptl_pwd As String, ss_tmp_fdr As String
Dim sw_gee_res_gev As Boolean = False, sw_delay As Boolean = False
'Dim stepcounter As Integer, t4_cnt As Integer
Dim xstepcounter As Integer = 0
Dim t4_cnt As Integer = 0
Private Sub browser_load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Location = New Point(800, 200)
READ_DATA_01()
wb.Navigate("www.website.com")
End Sub
Private Sub Timer0_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer0.Tick
Timer0.Enabled = False
after_load()
End Sub
Private Sub after_load()
Dim n As Integer
'MsgBox("Afterload")
'Me.Location = New Point(1000, 400)
n = 0
If w_azv_cod = "" Or Val(w_azv_cod) <= 0 Then
Timer1.Enabled = False
MsgBox(" No patient AZV Code. " + StrDup(2, vbCrLf) + _
" Please update database", vbOKOnly, " Data Control")
Do While True
If Me.wb.ReadyState <> WebBrowserReadyState.Compl ete Then
End
Else
n = n + 1
End If
If n = 2000 Then
End
End If
Loop
Else
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Me.Begin.PerformClick()
End Sub
Private Sub READ_DATA_01()
MyFileName = "c:\tmp\ss_tmp_fdr.txt"
FileOpen(1, MyFileName, OpenMode.Input)
ss_tmp_fdr = Trim(RTrim(LineInput(1)))
FileClose(1)
MyFileName = ss_tmp_fdr + "azv_cod_txt.txt"
FileOpen(1, MyFileName, OpenMode.Input)
w_pat_cod = Trim(RTrim(LineInput(1)))
w_azv_cod = Trim(RTrim(LineInput(1)))
w_ptl_usr = Trim(RTrim(LineInput(1)))
w_ptl_pwd = Trim(RTrim(LineInput(1)))
FileClose(1)
'If My.Computer.FileSystem.Fil eExists(My FileName) Then
' My.Computer.FileSystem.Del eteFile(My FileName)
'End If
End Sub
Private Sub SetTextboxText(ByVal fld As String, ByVal Text As String)
On Error GoTo a0001
DirectCast(GetCurrentWebFo rm.item(fl d), mshtml.HTMLInputElement).v alue = Text
GoTo a0002
a0001:
MsgBox("INTERNET SLOW")
a0002:
On Error GoTo 0
End Sub
Private Sub ClickSubmitButton()
'DirectCast(GetCurrentWebF orm.item(" cmdSubmitM e", 0), mshtml.HTMLButtonElement). click()
'Return 'so we don't call the below method
On Error GoTo b001
GetCurrentWebForm.submit()
GoTo b002
b001:
MsgBox("internet slow 2")
b002:
End Sub
Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
'Dim X7 As String
Try
'X7 = CStr(DirectCast(wb.Documen t, mshtml.HTMLDocument))
Return DirectCast(wb.Document, mshtml.HTMLDocument)
Catch ex As Exception
Return Nothing
End Try
End Function
Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
Try
If GetCurrentWebDoc.forms.len gth > 0 Then
Return DirectCast(GetCurrentWebDo c.forms.it em(0), mshtml.HTMLFormElement)
Else
Return Nothing
End If
Catch ex As Exception
Return Nothing
End Try
End Function
Private Function GetLinks() As String
Dim Temp As String = String.Empty, w_href As String = String.Empty
Dim i As Integer = 1
For Each MyLink As mshtml.HTMLAnchorElement In GetCurrentWebDoc.links
Temp &= i.ToString & ")" & Environment.NewLine
'MessageBox.Show(Temp)
Temp &= "Text: " & MyLink.innerText & Environment.NewLine & " URL: " & MyLink.href & Environment.NewLine & Environment.NewLine
w_href = MyLink.href
i += 1
If i = 4 Then
Exit For
End If
Next
Return w_href
End Function
Private Sub GetTextboxText()
MessageBox.Show("Value Is: " & DirectCast(GetCurrentWebFo rm.item("t xtBox"), mshtml.HTMLInputElement).v alue)
End Sub
'FILLS THE HTML TEXT AREA WITH TEXT FROM OUR WINFORM
Private Sub SetTextareaText(ByVal Text As String)
DirectCast(GetCurrentWebFo rm.item("t xtArea"), mshtml.HTMLTextAreaElement ).value = Text
End Sub
'GETS THE TEXT FROM THE HTML TEXT AREA AND DISPLAYS IT IN A MESSAGEBOX
Private Sub GetTextareaText()
MessageBox.Show("Value Is: " & DirectCast(GetCurrentWebFo rm.item("t xtArea"), mshtml.HTMLTextAreaElement ).value)
End Sub
'SET THE RADIO BUTTONS CHECKED. NOTICE THEY ARE BOTH CALLED THE SAME THING, BUT THE INDEX IS DIFFERENT.
' Private Sub SetRadioYesChecked()
' If rdoRadioYes.Checked Then
' DirectCast(GetCurrentWebFo rm.item("r doSelectio n", 0), mshtml.HTMLOptionButtonEle ment).chec ked = True
' Else
' DirectCast(GetCurrentWebFo rm.item("r doSelectio n", 1), mshtml.HTMLOptionButtonEle ment).chec ked = True
' End If
' End Sub
'CLICKS THE REGULAR HTML BUTTON (WHICH CALLS A JAVASCRIPT IN THE HTML PAGE TO SHOW THAT IT WORKED)
Private Sub ClickNormalButton()
DirectCast(GetCurrentWebFo rm.item("c mdClickMe" , 0), mshtml.HTMLButtonElement). click()
End Sub
'GRABS THE DIV TAG AND CHANGES ITS COLOR (AND TEXT) TO SHOW HOW TO MANIPULATE NON FORM ELEMENTS
Private Sub ChangeDIVColor()
Dim MyDiv As mshtml.HTMLDivElement = DirectCast(GetCurrentWebDo c.all.item ("divTesti ng"), mshtml.HTMLDivElement)
If MyDiv.style.backgroundColo r.ToString = "silver" Then
MyDiv.style.backgroundColo r = "yellow"
MyDiv.innerText = "I AM YELLOW"
Else
MyDiv.style.backgroundColo r = "silver"
MyDiv.innerText = "I AM SILVER"
End If
End Sub
'SHOW THE SOURCE HTML OF THE PAGE BEING VIEWED
'I PUT THIS IN ANOTHER FORM BECAUSE SHOWING THE SOURCE IN A MESSAGEBOX CAN BE ANNOYING
'Private Sub ShowPageSource()
' Dim F As New frmSource
' F.txtSource.Text = GetCurrentWebDoc.documentE lement.Get HashCode.T oString() '.outerHTML
' F.ShowDialog(Me)
' F.Dispose()
' F = Nothing
'End Sub
'EXECUTES THE JAVASCRIPT FUNCTION NAMED HelloWorld() IN THE HTML DOCUMENT
Private Sub ExecuteJavascript()
GetCurrentWebDoc.parentWin dow.execSc ript("vkch ecksSearch Result()", "javascript")
End Sub
'PRINTS THE CURRENT WEBPAGE. PRINTS UP THE SELECT PRINTER DIALOG JUST LIKE IE
Private Sub PrintPage()
Try
GetCurrentWebDoc.execComma nd("Print" , True)
Catch ex As Exception
End Try
End Sub
'THIS WILL LOOK THE IMAGES ON THE WEBPAGE, AND DISPLAY THEIR SRC VALUES
Private Sub GetImageInfo()
'GET OUR 2 IMAGES
Dim MyImages(21) As mshtml.HTMLImg
Dim temp As String = "Image Sources: " & Environment.NewLine & Environment.NewLine
Dim x As Integer
x = GetCurrentWebDoc.images.le ngth - 1
For i As Integer = 0 To x
MyImages(i) = DirectCast(GetCurrentWebDo c.images.i tem(, i), mshtml.HTMLImg)
temp &= MyImages(i).src & Environment.NewLine
Next
MessageBox.Show(temp)
End Sub
'THIS WILL GET THE COMBOBOX FROM THE HTML FORM, AND IT WILL
'DISPLAY THE SELECTED INDEX AND VALUE
Private Sub GetComboValue()
Dim MyHTMLCombo As mshtml.HTMLSelectElement = DirectCast(GetCurrentWebFo rm.item("c mboItems") , mshtml.HTMLSelectElement)
MessageBox.Show("Current Selected Index: " & MyHTMLCombo.selectedIndex & Environment.NewLine & _
"Current Selected Value: " & MyHTMLCombo.value & Environment.NewLine)
End Sub
Private Sub ClickCheckBox()
Dim MyInputElement As mshtml.HTMLInputElement = DirectCast(GetCurrentWebFo rm.item("c hkBox", 0), mshtml.HTMLInputElement)
MyInputElement.checked = Not MyInputElement.checked
End Sub
' Private Sub rdoPageTypeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Private Sub wb_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub cmd_id_ele_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_id_ele.Click
' Dim mapElements As HtmlElementCollection = GetCurrentWebForm.getEleme ntsByTagNa me("map")
' Dim inputElements As HtmlElementCollection = wb.cGetElementsByTagName(" input")
Dim mapElements As mshtml.IHTMLElementCollect ion = CType(GetCurrentWebForm.ge tElementsB yTagName(" BUTTON"), mshtml.IHTMLElementCollect ion)
Dim x As Integer
x = 0
For Each aa As mshtml.IHTMLElement In mapElements
x +=
MsgBox(Str(x) + "OuterHtml :" & aa.outerHTML & vbCrLf & vbCrLf & vbCrLf & "InnerHtml :" & aa.innerHTML & vbCrLf)
'MsgBox("InnerHtml :" & aa.innerHTML & vbCrLf)
'MsgBox(Str(x) & " -- " & aa.innerHTML)
'If element.tagName.getAttribu te("Mappin gType").To Lower.Equa ls("submit ") AndAlso _
' element.getAttribute(v("VA LUE").ToLo wer.Equals ("login") Then
'element.InvokeMember("cli ck")
'element.InvokeMember("sub mit")
'End If
Next
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GetCurrentWebForm()
GetImageInfo()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.wb.ReadyState = WebBrowserReadyState.Compl ete Then
GetCurrentWebDoc.parentWin dow.execSc ript("vkch ecksSearch Result()", "javascript")
Else
MsgBox(" web page 4: Downloading...")
End If
End Sub
'Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Dim F As New frmSource
' GetCurrentWebForm()
' F.txtSource.Text = GetCurrentWebDoc.documentE lement.out erHTML
' F.ShowDialog(Me)
'F.Dispose()
' F = Nothing
'End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sluiten.Click
Dim Temp As String = String.Empty
Dim i As Integer = 1
If Me.wb.ReadyState = WebBrowserReadyState.Compl ete Then
For Each MyLink As mshtml.HTMLDivElement In GetCurrentWebDoc.getElemen tsByTagNam e("button" )
Temp = MyLink.outerHTML & Chr(13)
DirectCast(MyLink, mshtml.HTMLButtonElement). click()
i += 1
Next
Else
MsgBox("web page 6: downloading...")
End If
xstepcounter = 2
End Sub
' Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
'End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Portaal.Click
wb.Navigate("www.website.com")
xstepcounter = 0
End Sub
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles use_pwd.Click
If Me.wb.ReadyState = WebBrowserReadyState.Compl ete Then
SetTextboxText("loginnaam" , w_ptl_usr)
'Me.wb.Refresh()
SetTextboxText("Password", w_ptl_pwd)
espera_a_la_web(3000)
ClickSubmitButton()
GetCurrentWebForm()
Else
MsgBox(" page1 still downloading...")
End If
xstepcounter = 1
End Sub
Private Sub cmdGetLinks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles vg_chk.Click
Dim Temp As String = String.Empty
'Dim i As Integer = 1
If Me.wb.ReadyState = WebBrowserReadyState.Compl ete Then
'MsgBox("vg - 1")
'For Each MyLink As mshtml.HTMLDivElement In GetCurrentWebDoc.getElemen tsByTagNam e("a")
For Each MyLink As mshtml.HTMLAnchorElement In GetCurrentWebDoc.getElemen tsByTagNam e("a")
'MsgBox("vg - 2")
Temp = UCase(MyLink.outerHTML & Chr(13))
If Temp.IndexOf("VG-CHECKS") >= 0 Then
'MsgBox(Temp)
DirectCast(MyLink, mshtml.HTMLAnchorElement). click()
Exit For
'i += 1
End If
Next
Else
MsgBox("web page 6: downloading...")
End If
xstepcounter = 2
'Dim w_href As String = String.Empty
'If Me.wb.ReadyState = WebBrowserReadyState.Compl ete Then
'w_href = GetLinks()
'MessageBox.Show(w_href)
'wb.Navigate(w_href)
'GetCurrentWebForm()
'Else
'MsgBox(" Web page 2: Still downloading...")
'End If
'stepcounter = 2
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles azv_cod.Click
READ_DATA_01()
'MessageBox.Show(w_azv_cod )
'espera_a_la_web(30000)
If Me.wb.ReadyState = WebBrowserReadyState.Compl ete Then
SetTextboxText("RelatieNum mer", w_azv_cod)
REM ******** critical line
GetCurrentWebDoc.parentWin dow.execSc ript("vkch ecksSearch Result()", "javascript")
'espera_a_la_web(7000)
Else
MsgBox(" Web page 3: Still Downloading...")
End If
If True Then
End If
xstepcounter = 3
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Open.Click
Timer1.Enabled = False
If Me.wb.ReadyState = WebBrowserReadyState.Compl ete Then
'Timer1.Enabled = False
'Timer3.Enabled = True
'MsgBox(" Processing...", vbOKOnly, " Process control...")
exists_code.PerformClick()
If sw_gee_res_gev Then
MsgBox(" Code not registered at AZV web Portaal. ", vbOKOnly, " Data Control....")
sw_gee_res_gev = False
xstepcounter = 5
Me.Timer1.Enabled = False
Me.Timer2.Enabled = False
Else
GetCurrentWebDoc.parentWin dow.execSc ript("load VkchecksDi alog(" + w_azv_cod + ")", "javascript")
xstepcounter = 4
Me.Timer1.Enabled = False
Me.Timer2.Enabled = True
End If
Else
MsgBox(" Web page 5: Downloading...")
End If
End Sub
Private Sub Button7_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wis.Click
If Me.wb.ReadyState = WebBrowserReadyState.Compl ete Then
GetCurrentWebDoc.parentWin dow.execSc ript("clea rForm()", "javascript")
Else
MsgBox(" Web page 7: downloading...")
End If
xstepcounter = 2
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bClose.Click
Close()
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
GetCurrentWebDoc()
Me.wb.Focus()
SendKeys.Send("{HOME}")
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Begin.Click
'Dim childform1 As New Form1
'childform1.Show()
Timer1.Enabled = False
While True
If xstepcounter = 0 Then
''Timer1.Enabled = False
If Me.wb.ReadyState <> WebBrowserReadyState.Compl ete Then
Form1.Show()
Timer1.Enabled = True
Exit While
Else
'espera_a_la_web(40000)
use_pwd().PerformClick()
End If
Timer1.Enabled = True
Exit While
End If
If xstepcounter = 1 Then
''Timer1.Enabled = False
If Me.wb.ReadyState <> WebBrowserReadyState.Compl ete Then
t4_cnt = 1000
'sw_delay = True
Timer4.Interval() = 2000
Timer5.Enabled = True
Form1.Timer1.Interval() = Timer4.Interval()
Timer4.Enabled = True
Form1.Show()
Timer1.Enabled = True
Exit While
Else
Timer1.Enabled = False
'MsgBox("1111111")
vg_chk().PerformClick()
espera_a_la_web(4000)
'MsgBox("aa")
End If
Timer1.Enabled = True
Exit While
End If
If xstepcounter = 2 Then
''Timer1.Enabled = False
If Me.wb.ReadyState <> WebBrowserReadyState.Compl ete Then
t4_cnt = 2000
sw_delay = True
Timer1.Enabled = False
Timer4.Interval() = 2000
Timer5.Enabled = True
Form1.Timer1.Interval() = Timer4.Interval()
Timer4.Enabled = True
Form1.Show()
Timer1.Enabled = True
Exit While
Else
azv_cod().PerformClick()
'espera_a_la_web (4000)
End If
Timer1.Enabled = False
End If
If xstepcounter = 3 Then
''Timer1.Enabled = False
If Me.wb.ReadyState <> WebBrowserReadyState.Compl ete Then
'MsgBox("a")
espera_a_la_web(4000)
t4_cnt = 3000
sw_delay = True
Timer1.Enabled = False
Timer4.Interval() = 2000
Timer5.Enabled = True
Form1.Timer1.Interval() = Timer4.Interval()
Timer4.Enabled = True
Form1.Show()
Timer1.Enabled = True
Exit While
Else
'MsgBox("3333333")
Open().PerformClick()
'MsgBox("end 3333333")
End If
If xstepcounter = 5 Then
Timer1.Enabled = False
Else
Timer1.Enabled = True
End If
Timer1.Enabled = True
End If
Exit While
End While
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
GetCurrentWebDoc()
Me.wb.Focus()
SendKeys.Send("{END}")
End Sub
Private Sub search_again_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear_search.Click
sluiten.PerformClick()
wis.PerformClick()
End Sub
Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Timer2.Enabled = False
azv_cod().PerformClick()
Begin.PerformClick()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
clear_search.PerformClick( )
Me.Timer2.Enabled = False
End Sub
Private Sub Button5_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Timer2.Enabled = False
End Sub
Private Sub s_hide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles s_hide.Click
Dim file As System.IO.StreamWriter, v1 As String = ss_tmp_fdr & "azv_req_flag_01.txt"
file = My.Computer.FileSystem.Ope nTextFileW riter(v1, True)
file.WriteLine("AZV Request Module active.")
file.Close()
Me.Visible = False
Me.Timer7.Enabled = True
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
SendKeys.Send("{enter}")
'Timer1.Enabled = True
Timer3.Enabled = False
Timer2.Enabled = True
End Sub
Private Sub exists_code_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exists_code.Click
Dim Temp As String = String.Empty
Dim i As Integer = 1
Timer1.Enabled = False
Temp = ""
delay(3)
If Me.wb.ReadyState = WebBrowserReadyState.Compl ete Then
For Each MyLink As mshtml.HTMLLabelElement In GetCurrentWebDoc.getElemen tsByTagNam e("label")
Temp = MyLink.outerHTML & Chr(13)
'MsgBox(Temp)
If UCase(Temp).IndexOf("GEEN RESULTATEN GEVONDEN") >= 0 Then
sw_gee_res_gev = True
End If
i += 1
Next
Else
MsgBox("exist_code failed...")
End If
xstepcounter = 5
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
'Timer1.Enabled = True
Timer4.Enabled = False
Timer5.Enabled = False
End Sub
Private Sub wb_Enter_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wb.Enter
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
t4_cnt += 1
Label1.Text = CStr(t4_cnt)
End Sub
Private Sub espera_a_la_web(ByVal p_milisec As Integer)
Dim nn As Integer
nn = 0
Do While True
If Me.wb.ReadyState <> WebBrowserReadyState.Compl ete Then
MsgBox("nothing")
Else
nn += 1
Label1.Text = CStr(nn) + " / " + CStr(p_milisec)
End If
If nn >= p_milisec Then
Exit Do
End If
Loop
End Sub
Sub delay(ByVal dblSecs As Double)
Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
Dim dblWaitTil As Date
Now.AddSeconds(OneSec)
dblWaitTil = Now.AddSeconds(OneSec).Add Seconds(db lSecs)
Do Until Now > dblWaitTil
Application.DoEvents()
Loop
End Sub
Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
'If System.IO.File.Exists() Then
'End If
End Sub
Private Sub broserwindow_FormClosing(s ender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
Dim v1 As String = ss_tmp_fdr & "azv_req_flag_01.txt"
If My.Computer.FileSystem.Fil eExists(v1 ) Then
My.Computer.FileSystem.Del eteFile(v1 )
End If
End Sub
Private Sub Timer7_Tick(sender As Object, e As EventArgs) Handles Timer7.Tick
Dim v1 As String = ss_tmp_fdr + "azv_cod_txt.txt"
If My.Computer.FileSystem.Fil eExists(v1 ) Then
'Button1_Click()
End If
End Sub
End Class
I have a very small app developed in visual studio 2012 with visual basic, it is a specific very small automatizacion of a website. Compiled with .net 4.5
The fact is it works fine in some computers and in some others it says:
"unhandled exception has ocurred un your application. If you click continue the application ill ignore this error and attempt to continue. If you click quit the application will close inmediately... object referenece not set to an instance of an object."
Below you will find the code
Please your support on this.
Best regards,
R
Imports System
Imports System.IO
Imports System.Collections
Imports System.Threading
Public Class broserwindow
Public MyFileName As String
Public MyNewLine As String
Dim w_pat_cod As String, w_azv_cod As String, w_ptl_usr As String, w_ptl_pwd As String, ss_tmp_fdr As String
Dim sw_gee_res_gev As Boolean = False, sw_delay As Boolean = False
'Dim stepcounter As Integer, t4_cnt As Integer
Dim xstepcounter As Integer = 0
Dim t4_cnt As Integer = 0
Private Sub browser_load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Location = New Point(800, 200)
READ_DATA_01()
wb.Navigate("www.website.com")
End Sub
Private Sub Timer0_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer0.Tick
Timer0.Enabled = False
after_load()
End Sub
Private Sub after_load()
Dim n As Integer
'MsgBox("Afterload")
'Me.Location = New Point(1000, 400)
n = 0
If w_azv_cod = "" Or Val(w_azv_cod) <= 0 Then
Timer1.Enabled = False
MsgBox(" No patient AZV Code. " + StrDup(2, vbCrLf) + _
" Please update database", vbOKOnly, " Data Control")
Do While True
If Me.wb.ReadyState <> WebBrowserReadyState.Compl
End
Else
n = n + 1
End If
If n = 2000 Then
End
End If
Loop
Else
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Me.Begin.PerformClick()
End Sub
Private Sub READ_DATA_01()
MyFileName = "c:\tmp\ss_tmp_fdr.txt"
FileOpen(1, MyFileName, OpenMode.Input)
ss_tmp_fdr = Trim(RTrim(LineInput(1)))
FileClose(1)
MyFileName = ss_tmp_fdr + "azv_cod_txt.txt"
FileOpen(1, MyFileName, OpenMode.Input)
w_pat_cod = Trim(RTrim(LineInput(1)))
w_azv_cod = Trim(RTrim(LineInput(1)))
w_ptl_usr = Trim(RTrim(LineInput(1)))
w_ptl_pwd = Trim(RTrim(LineInput(1)))
FileClose(1)
'If My.Computer.FileSystem.Fil
' My.Computer.FileSystem.Del
'End If
End Sub
Private Sub SetTextboxText(ByVal fld As String, ByVal Text As String)
On Error GoTo a0001
DirectCast(GetCurrentWebFo
GoTo a0002
a0001:
MsgBox("INTERNET SLOW")
a0002:
On Error GoTo 0
End Sub
Private Sub ClickSubmitButton()
'DirectCast(GetCurrentWebF
'Return 'so we don't call the below method
On Error GoTo b001
GetCurrentWebForm.submit()
GoTo b002
b001:
MsgBox("internet slow 2")
b002:
End Sub
Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
'Dim X7 As String
Try
'X7 = CStr(DirectCast(wb.Documen
Return DirectCast(wb.Document, mshtml.HTMLDocument)
Catch ex As Exception
Return Nothing
End Try
End Function
Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
Try
If GetCurrentWebDoc.forms.len
Return DirectCast(GetCurrentWebDo
Else
Return Nothing
End If
Catch ex As Exception
Return Nothing
End Try
End Function
Private Function GetLinks() As String
Dim Temp As String = String.Empty, w_href As String = String.Empty
Dim i As Integer = 1
For Each MyLink As mshtml.HTMLAnchorElement In GetCurrentWebDoc.links
Temp &= i.ToString & ")" & Environment.NewLine
'MessageBox.Show(Temp)
Temp &= "Text: " & MyLink.innerText & Environment.NewLine & " URL: " & MyLink.href & Environment.NewLine & Environment.NewLine
w_href = MyLink.href
i += 1
If i = 4 Then
Exit For
End If
Next
Return w_href
End Function
Private Sub GetTextboxText()
MessageBox.Show("Value Is: " & DirectCast(GetCurrentWebFo
End Sub
'FILLS THE HTML TEXT AREA WITH TEXT FROM OUR WINFORM
Private Sub SetTextareaText(ByVal Text As String)
DirectCast(GetCurrentWebFo
End Sub
'GETS THE TEXT FROM THE HTML TEXT AREA AND DISPLAYS IT IN A MESSAGEBOX
Private Sub GetTextareaText()
MessageBox.Show("Value Is: " & DirectCast(GetCurrentWebFo
End Sub
'SET THE RADIO BUTTONS CHECKED. NOTICE THEY ARE BOTH CALLED THE SAME THING, BUT THE INDEX IS DIFFERENT.
' Private Sub SetRadioYesChecked()
' If rdoRadioYes.Checked Then
' DirectCast(GetCurrentWebFo
' Else
' DirectCast(GetCurrentWebFo
' End If
' End Sub
'CLICKS THE REGULAR HTML BUTTON (WHICH CALLS A JAVASCRIPT IN THE HTML PAGE TO SHOW THAT IT WORKED)
Private Sub ClickNormalButton()
DirectCast(GetCurrentWebFo
End Sub
'GRABS THE DIV TAG AND CHANGES ITS COLOR (AND TEXT) TO SHOW HOW TO MANIPULATE NON FORM ELEMENTS
Private Sub ChangeDIVColor()
Dim MyDiv As mshtml.HTMLDivElement = DirectCast(GetCurrentWebDo
If MyDiv.style.backgroundColo
MyDiv.style.backgroundColo
MyDiv.innerText = "I AM YELLOW"
Else
MyDiv.style.backgroundColo
MyDiv.innerText = "I AM SILVER"
End If
End Sub
'SHOW THE SOURCE HTML OF THE PAGE BEING VIEWED
'I PUT THIS IN ANOTHER FORM BECAUSE SHOWING THE SOURCE IN A MESSAGEBOX CAN BE ANNOYING
'Private Sub ShowPageSource()
' Dim F As New frmSource
' F.txtSource.Text = GetCurrentWebDoc.documentE
' F.ShowDialog(Me)
' F.Dispose()
' F = Nothing
'End Sub
'EXECUTES THE JAVASCRIPT FUNCTION NAMED HelloWorld() IN THE HTML DOCUMENT
Private Sub ExecuteJavascript()
GetCurrentWebDoc.parentWin
End Sub
'PRINTS THE CURRENT WEBPAGE. PRINTS UP THE SELECT PRINTER DIALOG JUST LIKE IE
Private Sub PrintPage()
Try
GetCurrentWebDoc.execComma
Catch ex As Exception
End Try
End Sub
'THIS WILL LOOK THE IMAGES ON THE WEBPAGE, AND DISPLAY THEIR SRC VALUES
Private Sub GetImageInfo()
'GET OUR 2 IMAGES
Dim MyImages(21) As mshtml.HTMLImg
Dim temp As String = "Image Sources: " & Environment.NewLine & Environment.NewLine
Dim x As Integer
x = GetCurrentWebDoc.images.le
For i As Integer = 0 To x
MyImages(i) = DirectCast(GetCurrentWebDo
temp &= MyImages(i).src & Environment.NewLine
Next
MessageBox.Show(temp)
End Sub
'THIS WILL GET THE COMBOBOX FROM THE HTML FORM, AND IT WILL
'DISPLAY THE SELECTED INDEX AND VALUE
Private Sub GetComboValue()
Dim MyHTMLCombo As mshtml.HTMLSelectElement = DirectCast(GetCurrentWebFo
MessageBox.Show("Current Selected Index: " & MyHTMLCombo.selectedIndex & Environment.NewLine & _
"Current Selected Value: " & MyHTMLCombo.value & Environment.NewLine)
End Sub
Private Sub ClickCheckBox()
Dim MyInputElement As mshtml.HTMLInputElement = DirectCast(GetCurrentWebFo
MyInputElement.checked = Not MyInputElement.checked
End Sub
' Private Sub rdoPageTypeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Private Sub wb_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub cmd_id_ele_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_id_ele.Click
' Dim mapElements As HtmlElementCollection = GetCurrentWebForm.getEleme
' Dim inputElements As HtmlElementCollection = wb.cGetElementsByTagName("
Dim mapElements As mshtml.IHTMLElementCollect
Dim x As Integer
x = 0
For Each aa As mshtml.IHTMLElement In mapElements
x +=
MsgBox(Str(x) + "OuterHtml :" & aa.outerHTML & vbCrLf & vbCrLf & vbCrLf & "InnerHtml :" & aa.innerHTML & vbCrLf)
'MsgBox("InnerHtml :" & aa.innerHTML & vbCrLf)
'MsgBox(Str(x) & " -- " & aa.innerHTML)
'If element.tagName.getAttribu
' element.getAttribute(v("VA
'element.InvokeMember("cli
'element.InvokeMember("sub
'End If
Next
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GetCurrentWebForm()
GetImageInfo()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.wb.ReadyState = WebBrowserReadyState.Compl
GetCurrentWebDoc.parentWin
Else
MsgBox(" web page 4: Downloading...")
End If
End Sub
'Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Dim F As New frmSource
' GetCurrentWebForm()
' F.txtSource.Text = GetCurrentWebDoc.documentE
' F.ShowDialog(Me)
'F.Dispose()
' F = Nothing
'End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sluiten.Click
Dim Temp As String = String.Empty
Dim i As Integer = 1
If Me.wb.ReadyState = WebBrowserReadyState.Compl
For Each MyLink As mshtml.HTMLDivElement In GetCurrentWebDoc.getElemen
Temp = MyLink.outerHTML & Chr(13)
DirectCast(MyLink, mshtml.HTMLButtonElement).
i += 1
Next
Else
MsgBox("web page 6: downloading...")
End If
xstepcounter = 2
End Sub
' Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
'End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Portaal.Click
wb.Navigate("www.website.com")
xstepcounter = 0
End Sub
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles use_pwd.Click
If Me.wb.ReadyState = WebBrowserReadyState.Compl
SetTextboxText("loginnaam"
'Me.wb.Refresh()
SetTextboxText("Password",
espera_a_la_web(3000)
ClickSubmitButton()
GetCurrentWebForm()
Else
MsgBox(" page1 still downloading...")
End If
xstepcounter = 1
End Sub
Private Sub cmdGetLinks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles vg_chk.Click
Dim Temp As String = String.Empty
'Dim i As Integer = 1
If Me.wb.ReadyState = WebBrowserReadyState.Compl
'MsgBox("vg - 1")
'For Each MyLink As mshtml.HTMLDivElement In GetCurrentWebDoc.getElemen
For Each MyLink As mshtml.HTMLAnchorElement In GetCurrentWebDoc.getElemen
'MsgBox("vg - 2")
Temp = UCase(MyLink.outerHTML & Chr(13))
If Temp.IndexOf("VG-CHECKS") >= 0 Then
'MsgBox(Temp)
DirectCast(MyLink, mshtml.HTMLAnchorElement).
Exit For
'i += 1
End If
Next
Else
MsgBox("web page 6: downloading...")
End If
xstepcounter = 2
'Dim w_href As String = String.Empty
'If Me.wb.ReadyState = WebBrowserReadyState.Compl
'w_href = GetLinks()
'MessageBox.Show(w_href)
'wb.Navigate(w_href)
'GetCurrentWebForm()
'Else
'MsgBox(" Web page 2: Still downloading...")
'End If
'stepcounter = 2
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles azv_cod.Click
READ_DATA_01()
'MessageBox.Show(w_azv_cod
'espera_a_la_web(30000)
If Me.wb.ReadyState = WebBrowserReadyState.Compl
SetTextboxText("RelatieNum
REM ******** critical line
GetCurrentWebDoc.parentWin
'espera_a_la_web(7000)
Else
MsgBox(" Web page 3: Still Downloading...")
End If
If True Then
End If
xstepcounter = 3
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Open.Click
Timer1.Enabled = False
If Me.wb.ReadyState = WebBrowserReadyState.Compl
'Timer1.Enabled = False
'Timer3.Enabled = True
'MsgBox(" Processing...", vbOKOnly, " Process control...")
exists_code.PerformClick()
If sw_gee_res_gev Then
MsgBox(" Code not registered at AZV web Portaal. ", vbOKOnly, " Data Control....")
sw_gee_res_gev = False
xstepcounter = 5
Me.Timer1.Enabled = False
Me.Timer2.Enabled = False
Else
GetCurrentWebDoc.parentWin
xstepcounter = 4
Me.Timer1.Enabled = False
Me.Timer2.Enabled = True
End If
Else
MsgBox(" Web page 5: Downloading...")
End If
End Sub
Private Sub Button7_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wis.Click
If Me.wb.ReadyState = WebBrowserReadyState.Compl
GetCurrentWebDoc.parentWin
Else
MsgBox(" Web page 7: downloading...")
End If
xstepcounter = 2
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bClose.Click
Close()
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
GetCurrentWebDoc()
Me.wb.Focus()
SendKeys.Send("{HOME}")
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Begin.Click
'Dim childform1 As New Form1
'childform1.Show()
Timer1.Enabled = False
While True
If xstepcounter = 0 Then
''Timer1.Enabled = False
If Me.wb.ReadyState <> WebBrowserReadyState.Compl
Form1.Show()
Timer1.Enabled = True
Exit While
Else
'espera_a_la_web(40000)
use_pwd().PerformClick()
End If
Timer1.Enabled = True
Exit While
End If
If xstepcounter = 1 Then
''Timer1.Enabled = False
If Me.wb.ReadyState <> WebBrowserReadyState.Compl
t4_cnt = 1000
'sw_delay = True
Timer4.Interval() = 2000
Timer5.Enabled = True
Form1.Timer1.Interval() = Timer4.Interval()
Timer4.Enabled = True
Form1.Show()
Timer1.Enabled = True
Exit While
Else
Timer1.Enabled = False
'MsgBox("1111111")
vg_chk().PerformClick()
espera_a_la_web(4000)
'MsgBox("aa")
End If
Timer1.Enabled = True
Exit While
End If
If xstepcounter = 2 Then
''Timer1.Enabled = False
If Me.wb.ReadyState <> WebBrowserReadyState.Compl
t4_cnt = 2000
sw_delay = True
Timer1.Enabled = False
Timer4.Interval() = 2000
Timer5.Enabled = True
Form1.Timer1.Interval() = Timer4.Interval()
Timer4.Enabled = True
Form1.Show()
Timer1.Enabled = True
Exit While
Else
azv_cod().PerformClick()
'espera_a_la_web (4000)
End If
Timer1.Enabled = False
End If
If xstepcounter = 3 Then
''Timer1.Enabled = False
If Me.wb.ReadyState <> WebBrowserReadyState.Compl
'MsgBox("a")
espera_a_la_web(4000)
t4_cnt = 3000
sw_delay = True
Timer1.Enabled = False
Timer4.Interval() = 2000
Timer5.Enabled = True
Form1.Timer1.Interval() = Timer4.Interval()
Timer4.Enabled = True
Form1.Show()
Timer1.Enabled = True
Exit While
Else
'MsgBox("3333333")
Open().PerformClick()
'MsgBox("end 3333333")
End If
If xstepcounter = 5 Then
Timer1.Enabled = False
Else
Timer1.Enabled = True
End If
Timer1.Enabled = True
End If
Exit While
End While
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
GetCurrentWebDoc()
Me.wb.Focus()
SendKeys.Send("{END}")
End Sub
Private Sub search_again_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear_search.Click
sluiten.PerformClick()
wis.PerformClick()
End Sub
Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Timer2.Enabled = False
azv_cod().PerformClick()
Begin.PerformClick()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
clear_search.PerformClick(
Me.Timer2.Enabled = False
End Sub
Private Sub Button5_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Timer2.Enabled = False
End Sub
Private Sub s_hide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles s_hide.Click
Dim file As System.IO.StreamWriter, v1 As String = ss_tmp_fdr & "azv_req_flag_01.txt"
file = My.Computer.FileSystem.Ope
file.WriteLine("AZV Request Module active.")
file.Close()
Me.Visible = False
Me.Timer7.Enabled = True
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
SendKeys.Send("{enter}")
'Timer1.Enabled = True
Timer3.Enabled = False
Timer2.Enabled = True
End Sub
Private Sub exists_code_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exists_code.Click
Dim Temp As String = String.Empty
Dim i As Integer = 1
Timer1.Enabled = False
Temp = ""
delay(3)
If Me.wb.ReadyState = WebBrowserReadyState.Compl
For Each MyLink As mshtml.HTMLLabelElement In GetCurrentWebDoc.getElemen
Temp = MyLink.outerHTML & Chr(13)
'MsgBox(Temp)
If UCase(Temp).IndexOf("GEEN RESULTATEN GEVONDEN") >= 0 Then
sw_gee_res_gev = True
End If
i += 1
Next
Else
MsgBox("exist_code failed...")
End If
xstepcounter = 5
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
'Timer1.Enabled = True
Timer4.Enabled = False
Timer5.Enabled = False
End Sub
Private Sub wb_Enter_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wb.Enter
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
t4_cnt += 1
Label1.Text = CStr(t4_cnt)
End Sub
Private Sub espera_a_la_web(ByVal p_milisec As Integer)
Dim nn As Integer
nn = 0
Do While True
If Me.wb.ReadyState <> WebBrowserReadyState.Compl
MsgBox("nothing")
Else
nn += 1
Label1.Text = CStr(nn) + " / " + CStr(p_milisec)
End If
If nn >= p_milisec Then
Exit Do
End If
Loop
End Sub
Sub delay(ByVal dblSecs As Double)
Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
Dim dblWaitTil As Date
Now.AddSeconds(OneSec)
dblWaitTil = Now.AddSeconds(OneSec).Add
Do Until Now > dblWaitTil
Application.DoEvents()
Loop
End Sub
Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
'If System.IO.File.Exists() Then
'End If
End Sub
Private Sub broserwindow_FormClosing(s
Dim v1 As String = ss_tmp_fdr & "azv_req_flag_01.txt"
If My.Computer.FileSystem.Fil
My.Computer.FileSystem.Del
End If
End Sub
Private Sub Timer7_Tick(sender As Object, e As EventArgs) Handles Timer7.Tick
Dim v1 As String = ss_tmp_fdr + "azv_cod_txt.txt"
If My.Computer.FileSystem.Fil
'Button1_Click()
End If
End Sub
End Class
Hello, Can you check event viewer logs, such type of errors got logged in event viewer, so can get idea from there.
The reason for failure might be some systems not support .net 4.5 for any reason or having connectivity problem to get correct components for your application.
The reason for failure might be some systems not support .net 4.5 for any reason or having connectivity problem to get correct components for your application.
Don't know what computers you're trying to run it on but you can't even install .NET 4.5 on Windows XP so it won't run your program.
ASKER
Smighty,
the code is now attached in a word doc.
Yes both machines have .net 4.5
regarding what sets them apart... its a variety of pcs where the small app works... win win xp, win 7 , win 8 .... with each system sotimes works and sometime specially if the internet is slow it does not....
pathces and OS cant really verify in so many machines but they have to be more or less uptode.
Vjsoft:
I checked the even viewer and nothing special so far
Yes sometimes the internet gets slower.
DaveBaldwin,
They are like 50 pcs some with xp some with win 7 and some others with win 8
very few with win xp, so I am thinking compiling for .net 3.5
will that work in all OSs?
thanks to all
vb-app.docx
the code is now attached in a word doc.
Yes both machines have .net 4.5
regarding what sets them apart... its a variety of pcs where the small app works... win win xp, win 7 , win 8 .... with each system sotimes works and sometime specially if the internet is slow it does not....
pathces and OS cant really verify in so many machines but they have to be more or less uptode.
Vjsoft:
I checked the even viewer and nothing special so far
Yes sometimes the internet gets slower.
DaveBaldwin,
They are like 50 pcs some with xp some with win 7 and some others with win 8
very few with win xp, so I am thinking compiling for .net 3.5
will that work in all OSs?
thanks to all
vb-app.docx
.NET 3.5 works on Windows XP.
yes, if you are aiming for compatibility with Windows XP you'd have to go for .net 3.5
Windows 7 and are able to support .net 4.0 and 4.5
Windows 7 and are able to support .net 4.0 and 4.5
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please do no change the code, firs try of any Windows 7 or higher system. You can also try Windows Server 2008 R2 also.
can you put the Code in a Document and Attach it, its quite hard to follow track on such long questions ;)
to your problem: Have you checked whether both Computers do have .net 4.5 installed on them?
What does the machines set apart? OS, SP-Level, Patches, anything would be appreciated :)