I'm converting an application from VB6 to VB.NET and all gets converted fine apart from a section where I want to automate an image being clicked on.
The application uses the webbrowser control to signon to a web site, navigate to a certain page, click some radio and checkbox controls then click on a image input control to finish. This just crashes with 'Object variable or With block variable not set' in VB.NET
The VB6 code once you are on the right page is like this;
Dim frm As HTMLFormElement
Dim doc As HTMLDocument
Dim tlist As Object
Set doc = WebBrowser1.Document
Set frm = doc.Forms(0)
' Select XML format
Set tlist = frm.namedItem("downloadType")
tlist.Item(1).Checked = True
Set tlist = frm.namedItem("downloadIds")
' Call a subroutine to tick all the relevant checkboxes
tick_new tlist, WebBrowser1.Document.body.innerText
' Click on the download button
WebBrowser1.Document.All("downloadChecked").Click
And that works.
The HTML is like this;
<form name="grbReportDownloadForm" method="post" action="/online/newbacs/ocs/download/sort.do" class="grb" id="list">
<fieldset class="tertiary_background">
....
<input type="image" name="downloadAll" src="/gr_online/images/download_all.gif" />
<input type="image" name="downloadChecked" src="/gr_online/images/download.gif" />
</div>
</td>
</tr>
</table>
</fieldset>
</form>
The VB.NET code is like this;
Dim frm As MSHTML.HTMLFormElement
Dim doc As MSHTML.HTMLDocument
Dim tlist As Object
doc = WebBrowser1.Document.DomDocument
frm = doc.Forms.item(0)
' Select XML format
tlist = frm.namedItem("downloadType")
'UPGRADE_WARNING: Couldn't resolve default property of object tlist.Item. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
tlist.Item(1).Checked = True
tlist = frm.namedItem("downloadIds")
'UPGRADE_WARNING: Couldn't resolve default property of object WebBrowser1.Document.body. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
tick_new(tlist, WebBrowser1.Document.DomDocument.body.innerText)
' Click on the download button
'UPGRADE_WARNING: Couldn't resolve default property of object WebBrowser1.Document.All. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
WebBrowser1.Document.DomDocument.All("downloadChecked").Click()
So anyone know what's wrong or just how you click on an image input control?
Thanks in advance.
The application uses the webbrowser control to signon to a web site, navigate to a certain page, click some radio and checkbox controls then click on a image input control to finish. This just crashes with 'Object variable or With block variable not set' in VB.NET
The VB6 code once you are on the right page is like this;
Dim frm As HTMLFormElement
Dim doc As HTMLDocument
Dim tlist As Object
Set doc = WebBrowser1.Document
Set frm = doc.Forms(0)
' Select XML format
Set tlist = frm.namedItem("downloadType")
tlist.Item(1).Checked = True
Set tlist = frm.namedItem("downloadIds")
' Call a subroutine to tick all the relevant checkboxes
tick_new tlist, WebBrowser1.Document.body.innerText
' Click on the download button
WebBrowser1.Document.All("downloadChecked").Click
And that works.
The HTML is like this;
<form name="grbReportDownloadForm" method="post" action="/online/newbacs/ocs/download/sort.do" class="grb" id="list">
<fieldset class="tertiary_background">
....
<input type="image" name="downloadAll" src="/gr_online/images/download_all.gif" />
<input type="image" name="downloadChecked" src="/gr_online/images/download.gif" />
</div>
</td>
</tr>
</table>
</fieldset>
</form>
The VB.NET code is like this;
Dim frm As MSHTML.HTMLFormElement
Dim doc As MSHTML.HTMLDocument
Dim tlist As Object
doc = WebBrowser1.Document.DomDocument
frm = doc.Forms.item(0)
' Select XML format
tlist = frm.namedItem("downloadType")
'UPGRADE_WARNING: Couldn't resolve default property of object tlist.Item. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
tlist.Item(1).Checked = True
tlist = frm.namedItem("downloadIds")
'UPGRADE_WARNING: Couldn't resolve default property of object WebBrowser1.Document.body. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
tick_new(tlist, WebBrowser1.Document.DomDocument.body.innerText)
' Click on the download button
'UPGRADE_WARNING: Couldn't resolve default property of object WebBrowser1.Document.All. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
WebBrowser1.Document.DomDocument.All("downloadChecked").Click()
So anyone know what's wrong or just how you click on an image input control?
Thanks in advance.