Solved

Inet Transfer Conrol

Posted on 2000-02-16
11
633 Views
Last Modified: 2010-08-05
Hi, Freaks!

I have the following code:


Private Sub Command1_Click()
    Me.Result = ""
    Dim InetUrl As String
    Inet1.URL = "https://sfs.mchw.siemens.de/bo/abstimmung/fx_lpr_ord_ccy_det.cfm?date=01/31/2000"
    Inet1.AccessType = icUseDefault
    Inet1.Protocol = icHTTPS
    'InetReturn = Inet1.OpenURL(InetUrl, icString)
    Inet1.UserName = "Train"
    Inet1.Password = "3453"
    Inet1.Execute
   
    Me.Result = inetreturn
End Sub

      Private Sub Inet1_StateChanged(ByVal State As Integer)
       Dim vtData As Variant ' Data variable.

       Select Case State
       ' ... Other cases not shown.
       Case icError ' 11
           ' In case of error, return ResponseCode and

      ' ResponseInfo.
           vtData = Inet1.ResponseCode & ":" & _
           Inet1.ResponseInfo

       Case icResponseCompleted  ' 12
           Dim strData As String: strData = ""
           Dim bDone As Boolean: bDone = False

           ' Get first chunk.
           vtData = Inet1.GetChunk(1024, icString)
           DoEvents

           Do While Not bDone

               strData = strData & vtData
               ' Get next chunk.
               vtData = Inet1.GetChunk(1024, icString)
               DoEvents

               If Len(vtData) = 0 Then
                   bDone = True
               End If
           Loop

          Me.Result.Caption = strData
       End Select
      End Sub

The code works fine but returns me the complete html-code of the desired adress. But I just want the stuff I see on the screen of this page.

I former times I used this code:

    Inet.AccessType = icUseDefault
    InetReturn = Inet.OpenURL("https://sfs.mchw.siemens.de/bo/abstimmung/fx_lpr_ord_ccy_det.cfm?date=01/31/2000", icString)
    MsgBox InetReturn

It worked fine and provided the desired data in the string InetReturn.

Does anyone know how to fix my problem?

Any help is needed

Andy
0
Comment
Question by:cas1
  • 6
  • 5
11 Comments
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
If I understand your problem correctly, you need to parse out all of the HTML Keywords... Everything between the symbols < > are HTML Keywords...

You can use the following StripHTML function to do that:

Cheers!


THE CODE:

Function StripHTML(Source As String) As String
    Dim iVal As Long
    Dim Buf As String
    Dim lBuf As String
    Dim rBbuf As String
    iVal = InStr(1, Source, "<")
    If iVal = 0 Then
        StripHTML = Source
        Exit Function
    End If
    lBuf = Left$(Source, iVal - 1)
    iVal = InStr(iVal, Source, ">")
    rbuf = Mid$(Source, iVal + 1)
    Buf = lBuf + " " + rbuf
   
    Do
        iVal = InStr(1, Buf, "<")
        If iVal = 0 Then
            StripHTML = Buf
            Exit Do
        End If
        lBuf = Left$(Buf, iVal - 1)
        iVal = InStr(iVal, Buf, ">")
        rbuf = Mid$(Buf, iVal + 1)
        Buf = lBuf + " " + rbuf
    Loop
End Function
0
 
LVL 4

Author Comment

by:cas1
Comment Utility
Sorry, but that code doesn't seem to work. Aditionally I think that this is a solution, I would only agree if there is really no other way of doing it. Why is it possible with the other code, only to retrieve the screen contents?
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
Using the Inet control, parsing out the tags IS the only way to do it.  The Inet control returns a STRING containing the HTML document.  You have to parse that string.

Using the code I gave you, this is how you would add it to your program in the Inet1_StateChanged subroutine:


      Private Sub Inet1_StateChanged(ByVal State As Integer)
       Dim vtData As Variant ' Data variable.

       Select Case State
       ' ... Other cases not shown.
       Case icError ' 11
           ' In case of error, return ResponseCode and

      ' ResponseInfo.
           vtData = Inet1.ResponseCode & ":" & _
           Inet1.ResponseInfo

       Case icResponseCompleted  ' 12
           Dim strData As String: strData = ""
           Dim bDone As Boolean: bDone = False

           ' Get first chunk.
           vtData = Inet1.GetChunk(1024, icString)
           DoEvents

           Do While Not bDone

               strData = strData & vtData
               ' Get next chunk.
               vtData = Inet1.GetChunk(1024, icString)
               DoEvents

               If Len(vtData) = 0 Then
                   bDone = True
               End If
           Loop

          Me.Result.Caption = StripHTML(strData)
       End Select
      End Sub




Cheers!
0
 
LVL 4

Author Comment

by:cas1
Comment Utility
Yes, I know, mcrider, but the html-code of the page I want to access has over 410000 (!!!) Characters. So it takes up half an hour to parse out the tags this way. And as I already wrote: This code returns ONLY the screen contents, NOT the whole html-code:

   Inet.AccessType = icUseDefault
    InetReturn = Inet.OpenURL("https://sfs.mchw.siemens.de/bo/abstimmung/fx_lpr_ord_ccy_det.cfm?date=01/31/2000", icString)
    MsgBox InetReturn

But I can't use it because I don't know how to provide the username and password. (The return is always: access denied)

So I wonder if there is really no way to get only the data I need !?!
0
 
LVL 4

Author Comment

by:cas1
Comment Utility
Or do you know another way of solving my problem, probably using the winsock control?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 14

Expert Comment

by:mcrider
Comment Utility
Try this:

1) Create a new project.

2) Add the reference for "Microsoft HTML Object" to the project.  You can do this by clicking "Project->References..." and then selecting "Microsoft HTML Object" from the list.

3) Add a webbrowser control called "WebBrowser1" to "Form1". The WebBrowser control can be added by Right-Clicking on the toolbar and selecting "Components..." then selecting "Microsoft Internet Controls" from the list.

4) Add the following code to a MODULE:

    Function GetHTMLText(WebBrowserControl As Object) As String
        Dim HTMLdoc As HTMLDocument
        Dim HTMLobj As IHTMLElementCollection
        Dim Element As IHTMLElement
        Dim sElement As Variant
        Dim iVal As Long
        Dim lBuf As String
         
        'WAIT IN CASE BROWSER IS STILL LOADING
        Do
            If WebBrowserControl.ReadyState = 4 Then Exit Do
            DoEvents
        Loop
         
        'GET THE DOCUMENT
        Set HTMLdoc = WebBrowserControl.Document
        Set HTMLobj = HTMLdoc.All.tags("BODY")
        If HTMLdoc.frames.length > 0 Then
            For iVal = 0 To HTMLdoc.frames.length - 1
                For Each Element In HTMLdoc.frames(iVal).Document.All
                    If Element.tagName = "BODY" Then
                        lBuf = lBuf + vbCrLf + Element.innerHTML
                    End If
                Next
            Next iVal
        Else
            For Each Element In HTMLdoc.All
                If Element.tagName = "BODY" Then
                    lBuf = lBuf + vbCrLf + Element.innerHTML
                End If
            Next
        End If
        GetHTMLText = lBuf
    End Function




Then you can do this in a command button:

   Dim MyBuffer As String
   WebBrowser1.Navigate "https://sfs.mchw.siemens.de/bo/abstimmung/fx_lpr_ord_ccy_det.cfm?date=01/31/2000"
   MyBuffer = GetHTMLText(WebBrowser1)


By the way, If you don't want to see the page displayed in the WebBrowser control, *DONT* set the visible property of the WebBrowser control to false, otherwise, this code will not work... Just move the control outside the visible window... For example:

   WebBrowser1.Left = (WebBrowser1.Width * -1) - 20


Hope this helps!

             
Cheers!
0
 
LVL 4

Author Comment

by:cas1
Comment Utility
Sorry, maybe you think I'm a little bit stupid, but how can I now get the data I see in the Webbrowser Control in i.e. variable ?

Like this:  strContent = me.webbrowser1.value

But there is no value property
!?!

Can you help?
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
That's what the GetHTMLText function does...

   strContent = GetHTMLText(WebBrowser1)

The WebBrowser control has a "Document" property, but it doesn't return a string, it returns an Object.  The GetHTMLText function manipulates that object to return the text...


Cheers!

0
 
LVL 4

Author Comment

by:cas1
Comment Utility
You are right, but this function returns the whole html-content again, and using your function StripHTML would take much too long again. So this does not really solve problem. The html-content I already got with the Inet-control. Maybe you have another idea? In the meantime I play a little bit around with the Inet-Control. Perhaps however there is a solution with the Inet control. I would prefer this because I alreay have this control in use (and so a reference to it)

Bye

Andy
0
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
Comment Utility
Good-luck... I dont believe there is another solution using the inet control.
0
 
LVL 4

Author Comment

by:cas1
Comment Utility
Sorry for the delay but I think you deserved the points. Thanx for you time


Andy
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now