Results 1 to 21 of 21

Thread: [RESOLVED] How control web component in VB6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Resolved [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

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: How control web component in VB6

    Quote 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..

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  4. #4
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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

  6. #6
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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:
    1. 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

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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

  8. #8
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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:
    1. WebBrowser1.Navigate2 "www.ezremit.com.kw"
    2.  
    3. Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
    4.     DoEvents
    5. Loop
    6.  
    7. WebBrowser1.Document.getElementById("agentcode").focus
    Finally... what's your name, actually? Nasreen, Kari, Fathima? I'm confused...
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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

  10. #10
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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:
    1. Option Explicit
    2.  
    3. Dim WithEvents objDocument As HTMLDocument
    4.  
    5. Private Sub Form_Load()
    6. WebBrowser1.Navigate2 "www.ezremit.com.kw"
    7.  
    8. Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
    9.     DoEvents
    10. Loop
    11.  
    12. Set objDocument = WebBrowser1.Document
    13. WebBrowser1.Document.getElementById("agentcode").focus
    14. End Sub
    15.  
    16. Private Sub Form_Unload(Cancel As Integer)
    17. Set objDocument = Nothing
    18. End Sub
    19.  
    20. Private Function objDocument_onclick() As Boolean
    21. 'Check if the active element is indeed the submit button
    22. If objDocument.activeElement.tagName = "INPUT" Then
    23.     If objDocument.activeElement.getAttribute("value") = "Submit" Then
    24.         MsgBox "Submit button clicked." & vbCrLf & _
    25.                "Agentcode: " & objDocument.getElementById("agentcode").Value & vbCrLf & _
    26.                "User ID: " & objDocument.getElementById("Userid").Value & vbCrLf & _
    27.                "Password: " & objDocument.getElementById("passwd").Value & vbCrLf & _
    28.                "Security ID: " & objDocument.getElementById("pin").Value
    29.     End If
    30. End If
    31.  
    32. 'Proceed with the submitting of the form
    33. objDocument_onclick = True
    34. End Function
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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

  12. #12
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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:
    1. 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:
    1. If objDocument.activeElement.tagName = "A" Then
    2.    If objDocument.activeElement.href = "linkThatMayNotBeFollowed.htm" Then
    3.       objDocument_onclick = False
    4.       MsgBox "This link may not be followed."
    5.    End If
    6. 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

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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

  14. #14
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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

  16. #16
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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:
    1. 'Added Reference to HTML Object Library
    2. Dim WithEvents wFORM As HTMLFormElement
    3.  
    4.  
    5. Private Sub Form_Load()
    6.     WebBrowser1.Navigate "www.google.com"
    7. End Sub
    8.  
    9. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    10. If (pDisp Is WebBrowser1.Application) Then
    11.     Set wFORM = WebBrowser1.Document.Forms(0)
    12. End If
    13. End Sub
    14.  
    15.  
    16. Private Function wFORM_onsubmit() As Boolean
    17.     MsgBox WebBrowser1.Document.getElementById("q").Value
    18. 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"

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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:
    1. Dim BankIndex as Integer
    2. Dim BankName as String
    3. BankIndex  =  5
    4. 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

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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:
    1. Dim WithEvents objDocument As HTMLDocument
    2.  
    3. Private Sub browser_DownloadComplete()
    4. Set objDocument = browser.Document
    5. 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:
    1. Dim WithEvents objFrame As HTMLDocument
    2.  
    3. Private Sub browser_DownloadComplete()
    4. Set objFrame = browser.Document.frames(0).Document.Frame
    5. 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:
    1. 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.

  20. #20
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    355

    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....

  21. #21
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    355

    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
  •  



Click Here to Expand Forum to Full Width