-
Apr 13th, 2005, 09:41 AM
#1
Thread Starter
Lively Member
[RESOLVED] How control web component in VB6
Hi Dears,
I am working in a money exchange. I developed a money transfer program for the company.
Now my company has started an online money transfer service up on an agreement with EzRemit service which offers this service.
EzRemit service is done through their e-commercial web site www.ezremit.net, in ASP Classic
So in my project I coluld to call this web site using webbrowser control of VB6. Now I want to manipulate programitcally the data we put in the fields of the web site. That is the same data we want to also store in our server while it goes into remote server of the site.
Here an another company who also deals with the EzRemit service has a program with this facility. The site is opened in a VB6 program and this program manipulate and store the data entered in the fields of the web site.
Thus my manager requested me to develop same facility in our program also. And I have no way to contatct with the programmer who did for other company.
So I request you also to help me regarding this by providing idea or code to do the same. I think it is done in VB6 by the help of ASP.
Any way I hope your help urgently
With regards,
Klari
-
Apr 13th, 2005, 10:41 AM
#2
Frenzied Member
Re: How control web component in VB6
Originally Posted by nasreen
Hi Dears,
I am working in a money exchange. I developed a money transfer program for the company.
Now my company has started an online money transfer service up on an agreement with EzRemit service which offers this service.
EzRemit service is done through their e-commercial web site www.ezremit.net, in ASP Classic
So in my project I coluld to call this web site using webbrowser control of VB6. Now I want to manipulate programitcally the data we put in the fields of the web site. That is the same data we want to also store in our server while it goes into remote server of the site.
Here an another company who also deals with the EzRemit service has a program with this facility. The site is opened in a VB6 program and this program manipulate and store the data entered in the fields of the web site.
Thus my manager requested me to develop same facility in our program also. And I have no way to contatct with the programmer who did for other company.
So I request you also to help me regarding this by providing idea or code to do the same. I think it is done in VB6 by the help of ASP.
Any way I hope your help urgently
With regards,
Klari
So you need to manipulate data in textboxes of a web page?
I have done this some time back... let me know.. if you want this..
-
Apr 13th, 2005, 11:08 AM
#3
Re: How control web component in VB6
If you want to post data to a HTML form you should look into the ServerXMLHTTP object of the MSXML component.
-
Apr 13th, 2005, 03:31 PM
#4
Fanatic Member
Re: How control web component in VB6
If you have some more details on the page you're wanting to fill in, I'll see what I can do for you. Also, read the second article in my signature, it covers manipulation of webpages.
Author for Visual Basic Web Magazine
-
Apr 14th, 2005, 05:31 AM
#5
Thread Starter
Lively Member
Re: How control web component in VB6
Hi
Dear Sir
Read your reply to my post in vbfourms,
Thanks a lot of for your directions. Really it was great help for me.
Any way my problem is not solved yet.
Here I have mail you to michielmeulendijk@hotmail.com two screen shots of my project in Jpg format. I think you may considert it and help me.
My project is for an Exchange company doing online money transactions.
As you can see in my first screenshot the first page of the web is opend in a from in my project using web control. In this page we put the custmer informations. Now what I really want is when I click the proceed button of the web page I want to save the data typed in the fields of web page in my local database also.
I want the same facility in my second page also. This page used to put beneficiary informations. So I want to save the data in my system also at the time it is saved in remoter server.
Pls keep in mind that I have no any privilage to edit the website. It is not mine and it is of a forieng company.
How can I slove my problem.
Hoping your directions, codes, a smiple project of any pages like yahoo mails login page.
With regards,
nasreen
thanks once again
-
Apr 14th, 2005, 05:30 PM
#6
Fanatic Member
Re: How control web component in VB6
It's very well possible to save the data from the webpage before it's being submitted. As I suggested in my previous post, you should use the Document Object Model; it provides you with a hierarchical interface to control the webpage. Let me explain.
I found the website at http://www.ezremit.com.kw/ and since I don't have any customer ID I can't log in. If you look at the HTML source of the page you'll see that all textboxes are input elements (<input type=text...). The page has been well programmed, all elements have names and unique ID's (id="agentcode" for example). To get the text of the first textbox (Agent Code), you can use this code:
VB Code:
MsgBox WebBrowser1.Document.getElementById("agentcode").value
I strongly suggest you read the second article in my signature (Using the DHTML Document Object Model). It clearly explains the concept of the DOM, you'll understand it much better.
Also, if you want me to help you more, you'll have to send me login information so I can get past the first page. Then I can take a more detailed look at the HTML of the other pages.
Author for Visual Basic Web Magazine
-
Apr 15th, 2005, 02:25 PM
#7
Thread Starter
Lively Member
Re: How control web component in VB6
Hi TheVader,
Special thanks to you for your valuable directions.
Now I got the idea to retieve data from web components. Especially your code sample is very useful.
Here I also expect to describe me how can I catch this data before it is submitting.
I used the event "BeforeNavigate2" of the WebBrowser but this have many other problems. Especially when click the back button of the navigator.
So is there any idea to trace with submit button click action. For example I want to retrieve the data when the Login button is clicked in www.ezremit.com.kw
Regarding this I have another problem also, that I want to set focus to a field.
I tried with this code
WebBrowser1.Document.getElementById("agentcode").focus
and
WebBrowser1.Document.getElementById("agentcode").focus()
The first one dosn't work and second one shows syntax error.
So how can I do it. How can I set focus into agentcode field.
I read your DHTML DOM documentation. This article opened a wide possiblities before me. But I didn't get a satsified solution for the above mentioned problem.
Expecting your detailed reply
Regarding to the login details really I am also ignorent about it. I am only a programmer for this company. Whenever I need to login, the manager do it and type the password and so.
With regards,
klari
-
Apr 15th, 2005, 03:01 PM
#8
Fanatic Member
Re: How control web component in VB6
The BeforeNavigate2 event should be good enough to detect the submitting of the form. Alternatively, it can be solved by using the HTML events such as onClick. If you tell me what the problem with BeforeNavigate2 is, I can help you better.
The focus code as you describe it should work. I think you are calling it at the wrong moment, directly after the Navigate method. That's a common mistake; you should wait for the page to be loaded before trying to work with its HTML. Try something like this:
VB Code:
WebBrowser1.Navigate2 "www.ezremit.com.kw"
Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
WebBrowser1.Document.getElementById("agentcode").focus
Finally... what's your name, actually? Nasreen, Kari, Fathima? I'm confused...
Author for Visual Basic Web Magazine
-
Apr 17th, 2005, 03:49 AM
#9
Thread Starter
Lively Member
Re: How control web component in VB6
Hi TheVader,
Happy to your prompt response.
Now my problems regarding this is almost solved . Thanks to you, a lot of.
As I told you in prvious post I face some problem with BeforeNavigate2 event to trace the sumbit action.
Because in our main page there are many links to different services. If the user click any of this link the data in the filed will be collected also. I want to be collected only when the sumbit button is clicked. This problem can be solved with a boolean variable as I think. But it is too risk.
Thus if I get an idea to trace the click even of the submit button it will be very easy and smooth to me.
So if you please to describe me an idea for this problem it is a great help for me.
And my Name is Fathima Nasreen, Klari is my village. I am known in the name of Klari.
With regards,
Klari
-
Apr 17th, 2005, 05:28 AM
#10
Fanatic Member
Re: How control web component in VB6
Hi Klari,
Nice to be able to help. To capture the clicking of the submit button, we have to use the actual document events (such as onClick, onDblClick etc.) instead of those of the Web Browser Control. Add this reference to your project: Microsoft HTML Object Library. Then use this code:
VB Code:
Option Explicit
Dim WithEvents objDocument As HTMLDocument
Private Sub Form_Load()
WebBrowser1.Navigate2 "www.ezremit.com.kw"
Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
Set objDocument = WebBrowser1.Document
WebBrowser1.Document.getElementById("agentcode").focus
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objDocument = Nothing
End Sub
Private Function objDocument_onclick() As Boolean
'Check if the active element is indeed the submit button
If objDocument.activeElement.tagName = "INPUT" Then
If objDocument.activeElement.getAttribute("value") = "Submit" Then
MsgBox "Submit button clicked." & vbCrLf & _
"Agentcode: " & objDocument.getElementById("agentcode").Value & vbCrLf & _
"User ID: " & objDocument.getElementById("Userid").Value & vbCrLf & _
"Password: " & objDocument.getElementById("passwd").Value & vbCrLf & _
"Security ID: " & objDocument.getElementById("pin").Value
End If
End If
'Proceed with the submitting of the form
objDocument_onclick = True
End Function
Author for Visual Basic Web Magazine
-
Apr 18th, 2005, 05:01 AM
#11
Thread Starter
Lively Member
Re: How control web component in VB6
Hi TheVader,
Thanks once again for your kindness.
Your code is working smoothly and as I want to be really.
If you don't mind let me ask another doubts regarding this, so I can do my project in a good performance.
My doubts is Can we trace and cotrol the click action of any hyper link. ie. in our web page there are many links as menu to different services. Here I want to prevent the user clicking some of these links while he do some perticular tasks, such as new transaction and so.
Now I put a frame control to hide these links. I think there may be another good idea programitically to give message somthink like "this action not allowed"
And also expect an idea to trace the Backward and Forward actions of the browser.
Hoping your cooperation towards,
With regars,
klari
-
Apr 18th, 2005, 06:06 PM
#12
Fanatic Member
Re: How control web component in VB6
Hi Klari,
Yes you can programmatically click hyperlinks. Just use the Click method on a link object, like this:
VB Code:
WebBrowser1.Document.getElementById("myLink").Click
To act when a link has been clicked thay may not be followed, perform another check just like the submit button. Call this in the objDocument_onclick event.
VB Code:
If objDocument.activeElement.tagName = "A" Then
If objDocument.activeElement.href = "linkThatMayNotBeFollowed.htm" Then
objDocument_onclick = False
MsgBox "This link may not be followed."
End If
End If
A valuable resource for documentation on the DOM is the MSDN section for Web Development, which can be found here.
What exactly do you mean by 'tracing the forward and back actions'? With the CommandStateChanged event you can detect when the back/forward buttons should be enabled or disabled. The first article in my signature provides sample code for that.
Author for Visual Basic Web Magazine
-
Nov 27th, 2005, 11:51 AM
#13
Thread Starter
Lively Member
Re: How control web component in VB6
Hi TheVader,
Good day,
Hope you fine.
Once again here I beg your help regarding my project which is enriched with your strong support.
My project in VB 6.0 for a money transfer company uisng different Online money services is almost finished the work. And in this time I rememebr you help, support and guidence in my project especially in DHTML Document Object Model.
Regarding to the same problem let me put my new problem I face in my project.
The work for www.ezremit.com.kw is almost completed and now I am writing code for another speed service ARY Speed Remittance.
Since this site is developed in ASP .Net I cannot take control on the objects of this site.
Whenever I follow the same procedure you tought me for ezremit.com.kw VB says error and says
'Object variable or With Block variable not set' . I don't know what is the mistake. Here you can visit the site by this address
http://demo.speedremit.ae/
User name : uaedemo
PassWrd : demo
I used the following code to login automatically
dim UserID as string
dim PsWd as string
UserID = "uaedemo"
PsWd = "demo"
Private Sub CmdLogIn_Click()
browser.Document.getElementById("txtLoginName").Value = UserID
browser.Document.getElementById("txtPassword").Value = PsWd
End Sub
This time the error number 91 arises with message 'Object variable or With Block variable not set'
I think the problem may be for the site is developed by ASP .Net
Now I expect your sincere help regarding this porblem.
Expecting your best cooperation
Nasreen
-
Nov 27th, 2005, 08:47 PM
#14
Fanatic Member
Re: How control web component in VB6
Hi Kati,
I'm glad to tell you I've found the error in your code. Actually your code was correct, but you called it from the wrong document. Let me explain; the whole page consists of a frameset (you can see this by going to View > Source in Internet Explorer). This frameset exists in the source document (the one that is accessed by browser.Document).
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
</script>
<html>
<head>
<TITLE>Welcome to ARY Speed Remit :: We understand your needs</TITLE>
</head>
<frameset rows="0,*" border="0">
<frame name="header" src="about:blank" scrolling="no" noresize>
<frame name="main" src="Login.aspx">
<noframes>
<p id="p1">
This HTML frameset displays multiple Web pages. To view this frameset, use a
Web browser that supports HTML 4.0 and later.
</p>
</noframes>
</frameset>
</html>
From the source you can tell there are two frames, "header" and "main'. It seems the second frame is the one that holds the page we're looking for. So we have to access the document of that particular frame. It can be done like this:
browser.Document.frames.Item(1).Document.getElementById("txtLoginName").Value = UserID
browser.Document.frames.Item(1).Document.getElementById("txtPassword").Value = PsWd
So the problem is not caused by the ASP used. In fact, server-side scripting with ASP or PHP can never cause these problems, because the code that is finally received by the browser is always plain HTML.
Best regards,
Michiel
Author for Visual Basic Web Magazine
-
Nov 29th, 2005, 08:55 AM
#15
Thread Starter
Lively Member
Re: How control web component in VB6
Dear Sir,
Thanks so much
Thanks again for your genuine guidence. Now the code is working properly,
Wishing all the bests and expecting the best support and cooperations
Nasreen
-
Nov 29th, 2005, 09:09 AM
#16
Re: How control web component in VB6
Just a FYI tip: (Vader will like this too )
dont WithEvents the Document.. hit the Form itself it makes it easier to grab the onsubmit
same of "watching" for the submit on google
VB Code:
'Added Reference to HTML Object Library
Dim WithEvents wFORM As HTMLFormElement
Private Sub Form_Load()
WebBrowser1.Navigate "www.google.com"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WebBrowser1.Application) Then
Set wFORM = WebBrowser1.Document.Forms(0)
End If
End Sub
Private Function wFORM_onsubmit() As Boolean
MsgBox WebBrowser1.Document.getElementById("q").Value
End Function
there are lots of "events" in a form.. and the onsubmit will allow you to nab all the fields before it does anything else
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Dec 10th, 2006, 04:20 AM
#17
Thread Starter
Lively Member
Re: How control web component in VB6
Hi Mr. TheVader
Hope u fine.
After an intervel I am still in need of your help and guidance in my career that always give me hope in your kindness. Surely you opened a wide range of hopes in my carreer world.
Now I am facing a new problem in my new project.
In this project, the web page has read only field when I double click that filed a popup explorer window come.
The script is written in JavaScript , here is the HTML tag details of that web site
<TD><INPUT id=agentCd
ondblclick="callLov('addRemitInfo_files/lovAgentCd.htm','300','316')"
readOnly maxLength=10 name=agentCd></TD>
Now I want to cancel this action programitically in my project.
I wrote this code
Private Function objDocument_ondblclick() As Boolean
On Error GoTo Last
objDocument_ondblclick = False
Exit Function
Last:
End Function
But this code is not working and the popup window still come.
So, if possible pls suggest a solution to stop this action or to close the popup window programitically from my project.
I send a mail to you with attachment of that web site I saved.
Waiting for your best support
Nasreen
-
Feb 7th, 2007, 04:13 AM
#18
Thread Starter
Lively Member
Re: How control web component in VB6
Hi all,
Is there any idea to click the select component of an HTML page programitically
Here is the HTMT code
HTML Code:
<td width="83%" align=left nowrap><font face="Times New Roman, Times, serif">
<select name=cboPrimary size=1 onChange="RemoveOptionAndSubmit(cboSecondary)" style="width=350px;">
<option value="003" >ALLIED BANKING CORPORATION - $ BTB (USD )</option>
<option value="004" >ALLIED BANKING CORPORATION - PESO BTB (PHP )</option>
<option value="008" >ALLIED BANKING CORPORATION - PESO DTOD (PHP )</option>
<option value="052" >BANK OF THE PHILIPPINE ISLAND (USD )</option>
<option value="049" >BANK OF THE PHILLIPINE ISLAND (PHP )</option>
<option value="179" >EQUITABLE BANK / PCI (PHP )</option>
<option value="175" >METRO BANK (PHP )</option>
<option value="176" >METRO BANK - $ (USD )</option>
<option value="177" >PHILIPPINE NATIONAL BANK (PHP )</option>
<option value="178" >PHILIPPINE NATIONAL BANK - $ (USD )</option>
</select>
</font>
</td>
When one of bank is selected, the branches of that bank will be lsited.
Now I want to do this process programtically.
Here I used this code:
VB Code:
Dim BankIndex as Integer
Dim BankName as String
BankIndex = 5
browser.Document.getElementById("cboPrimary").selectedIndex = BankIndex
This code select the expected bank BANK OF THE PHILIPPINE ISLAND (USD )
But the page not lists the branch of this bank. It still remain wihout any action.
Is there any suggession to solve this problem
With regards,
Nasreen
-
Mar 4th, 2007, 03:34 AM
#19
Thread Starter
Lively Member
Re: How control web component in VB6
Hi Thevader and All,
How we can programitically click a button or link of a web page viewed in FRAMED web page.
I use for a web page without frame the following code :
VB Code:
Dim WithEvents objDocument As HTMLDocument
Private Sub browser_DownloadComplete()
Set objDocument = browser.Document
End Sub
This code work fine and without error.
But I want to do the same function in a web page with three frames, to control the mouse click programitically.
I used the the following code
VB Code:
Dim WithEvents objFrame As HTMLDocument
Private Sub browser_DownloadComplete()
Set objFrame = browser.Document.frames(0).Document.Frame
End Sub
But when execute the line (Set objFrame = browser.Document.frames(0).Document.Frame)
I got a runtime error saying Exception occurred.
I also changed that line as :
VB Code:
Set objFrame = browser.Document.frames.Item(2).Document
This time the error was : Object or class does not support the set of events
Any idea to solve this problem or any idea to control the mouse click in a framed web page
With regards,
Nasreen
Last edited by nasreen; Mar 4th, 2007 at 08:37 AM.
-
Jun 21st, 2009, 12:04 AM
#20
Hyperactive Member
Re: [RESOLVED] How control web component in VB6
I know that this code has been around for a while but i find that it is the only thing that can somewhat take me towards what I need. If I could get some help I would really appreciate it...
I am simply trying to read the page that can have x forms with x elements with x attributes and output that information into a textbox
I know how to find elements with specific tag name but I don't know how to read out element names and ids regardless of tag name.
I have used this code and it worked for "input" tagname
Code:
Dim inv As Integer
Dim ind As Integer
Dim c As Integer
Dim FormName As Object
Dim element As Object
Dim tagName As String
Text1 = ""
inv = 0
For Each FormName In MyBrowser.Document.getElementsByTagName("form")
Text1 = Text1 & "Form Name: " & FormName.Name & vbCrLf & "Form ID: " & FormName.Id & vbCrLf & "Form Index: " & inv & vbCrLf
inv = inv + 1
Next FormName
For ind = 0 To inv - 1
Text1 = Text1 & vbCrLf & "- - - - - - -" & vbCrLf
Text1 = Text1 & "Form index: " & ind & vbCrLf & vbCrLf
Text1 = Text1 & "*********************************" & vbCrLf
c = 0
For Each element In MyBrowser.Document.Forms(ind).getElementsByTagName("input")
If element.Name = vbNullString Then
Text1 = Text1 & c & ":" & vbTab & "ID: " & element.Id & vbTab & " Type: " & element.Type & vbCrLf
Else
Text1 = Text1 & c & ":" & vbTab & "Name: " & element.Name & vbTab & " Type: " & element.Type & vbCrLf
End If
c = c + 1
Next element
Text1 = Text1 & "- - - - - - -"
Next
How would I do this with all elements,, not just one tangname....
-
Jun 21st, 2009, 12:09 AM
#21
Hyperactive Member
Re: [RESOLVED] How control web component in VB6
I used this to get form elements data when I click on them
Code:
If objDocument.activeElement.tagName = "INPUT" Then
Text1.Text = "Name: " & vbTab & MyBrowser.Document.activeElement.Name & vbCrLf & _
"Id: " & vbTab & MyBrowser.Document.activeElement.Id & vbCrLf & _
"Type: " & vbTab & MyBrowser.Document.activeElement.Type
ElseIf objDocument.activeElement.tagName = "A" Then
Text1.Text = "link clicked."
ElseIf objDocument.activeElement.tagName = "textarea" Then
Text1.Text = "textarea."
End If
'Proceed with the submitting of the form
objDocument_onclick = True
How would I adapt this to loop through all forms and elements and just list them for me? I extracted that from your code above, and it helped me a bit,,,, I am sorry if I am asking dumb questions, I am not experienced with this stuff very much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|