Solved

Inet Transfer Conrol

Posted on 2000-02-16
11
647 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
ID: 2530622
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
ID: 2530686
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
ID: 2530708
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 4

Author Comment

by:cas1
ID: 2530726
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
ID: 2530740
Or do you know another way of solving my problem, probably using the winsock control?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2530802
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
ID: 2531347
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
ID: 2532783
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
ID: 2533919
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
ID: 2534009
Good-luck... I dont believe there is another solution using the inet control.
0
 
LVL 4

Author Comment

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


Andy
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

831 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