• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11703
  • Last Modified:

Error 80020101 while calling javascript function from Visual Basic

Hi Gurus,
I am facing problem while calling a javascript function from Visual basic. Basically my requirement is like this.

First I have to invoke a web page from visual basic and once it is called, I have to invoke javascript function in it. While debugging the code, I could see that the web page gets loaded successfully but the code gives error 80020101 when it executes the call to javascript function. Below is the code that I have used.

Dim oIE As Object
'Create the IE application object.
oIE = CreateObject("internetexplorer.application")
'Load the URL.
oIE.Navigate("http://xyz.net:8065/bc/bsp/crm_ic/default.htm?sap-client=220&sap-sessioncmd=open")
'Wait for the web page to load completely.
Do While (oIE.ReadyState <> 4)
Loop
'MsgBox(oIE.Document.frames.length)
Call oIE.Document.parentWindow.execScript("window.top.setProduct('1105206503')", "JavaScript")

I could successfully simulate the process by doing following steps -
1. Paste the URL in web brower and let the page load successfully.
2. Now paste the function in web browser like javascript:window.top.setProduct('1105206503')
By doing this, it calls the function successfully.

But when I am trying to execute this through VB code I get error 80020101.
I tried statements like -
Call oIE.Document.frames.execScript("window.top.setProduct('1105206503')", "JavaScript")
or
Call oIE.Document.frames(0).execScript("window.top.setProduct('1105206503')", "JavaScript")

but no use.

The statement MsgBox(oIE.Document.frames.length) returns 0 suggesting that there is only one frame on the page.

Help please.

Thanks,
Rahul.
0
raurangabadkar
Asked:
raurangabadkar
1 Solution
 
raurangabadkarAuthor Commented:
Hi Master,

Thanks for the link. I checked it and tried few possibilities mentioned in it.

Today I started testing my code a fresh and I realized that may be I was not waiting enough for the page to get loaded successfully.

I added a wait in my code and now it has started working fine.

Points awarded.

Thanks,
Rahul.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now