Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • Last Modified:

Inet Transfer Conrol

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
cas1
Asked:
cas1
  • 6
  • 5
1 Solution
 
mcriderCommented:
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
 
cas1Author Commented:
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
 
mcriderCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cas1Author Commented:
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
 
cas1Author Commented:
Or do you know another way of solving my problem, probably using the winsock control?
0
 
mcriderCommented:
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
 
cas1Author Commented:
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
 
mcriderCommented:
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
 
cas1Author Commented:
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
 
mcriderCommented:
Good-luck... I dont believe there is another solution using the inet control.
0
 
cas1Author Commented:
Sorry for the delay but I think you deserved the points. Thanx for you time


Andy
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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