Solved

Inet control problem

Posted on 1998-11-12
8
2,371 Views
Last Modified: 2013-12-25
I am using the inet control under VB6 with the following code:
Private Sub cmdGetFile_Click()
Dim strURL As String
' Take input for address to connect to
strURL = txtURL.Text
' Use inet control to logon to server
    With inetFTP
        .URL = strURL
        .UserName = "anonymous"
        .Password = "jasons@"
' Get file from server
        .Execute , "GET test.txt c:\windows\desktop\README"
    End With
        inetFTP.Execute , "GET test.txt c:\windows\desktop\READMEB"
    End If
End Sub
Now What happens is that an error message appears whenever the second GET method is executed. This is not replicated under the debug session. The error that apears is that the previous command is still executing. Now I understand that this is an async. control and that it just executes without waiting for the previous to stop runnning. I have even tried putting in a Do While Loop like so:
Do While control.StillExecuting = True
Loop
Thus it should sit around until it receives the correct termination of the previous get.

Is this a bug or is it something I am doing wrong?

There's an extra 500 points if this one is answered correctly today!!!!
0
Comment
Question by:unicorntech
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Accepted Solution

by:
idcanada earned 1000 total points
ID: 1488238
Private Const ftpDIR As Integer = 0

                    Private Const ftpPUT As Integer = 1

                    Private Const ftpGET As Integer = 2

                    Private Const ftpDEL As Integer = 3

                    Private iLastFTP As Integer



                    Private Sub cmdConnect_Click()

                        On Error GoTo ConnectError

                        Inet1.URL = txtURL

                        Inet1.UserName = txtUserName

                        Inet1.Password = txtPassword

                        Inet1.Protocol = icFTP

                        iLastFTP = ftpDIR



                        Inet1.Execute Inet1.URL, "DIR"

                    End Sub



                    Private Sub Inet1_StateChanged(ByVal _

                        State As Integer)

                        Select Case State

                            Case icNone

                             sbFTP.Panels("status").Text = ""

                            Case icResolvingHost

                             sbFTP.Panels("status").Text

                               = "Resolving Host"

                            Case icHostResolved

                             sbFTP.Panels("status").Text _

                               = "Host Resolved"

                            Case icConnecting

                             sbFTP.Panels("status").Text _

                               = "Connecting..."

                            Case icConnected

                             sbFTP.Panels("status").Text _

                               = "Connected!"

                            Case icRequesting

                             sbFTP.Panels("status").Text _

                               = "Requesting..."

                            Case icRequestSent

                             sbFTP.Panels("status").Text _

                               = "Request Sent"

                            Case icReceivingResponse

                             sbFTP.Panels("status").Text _

                               = "Receiving Response..."

                            Case icResponseReceived

                             sbFTP.Panels("status").Text _

                               = "Response Received!"

                            Case icDisconnecting

                             sbFTP.Panels("status").Text _

                               = "Disconnecting..."



                            Case icDisconnected

                             sbFTP.Panels("status").Text _

                               = "Disconnected"

                            Case icError

                             sbFTP.Panels("status").Text _

                               = "Error! " & Trim(CStr( _

                               Inet1.ResponseCode)) & _

                               ": " & Inet1.ResponseInfo

                            Case icResponseCompleted

                             sbFTP.Panels("status").Text _

                               = "Response Completed!"

                                ReactToResponse iLastFTP

                        End Select

                    End Sub



                    Public Function _

                        ReactToResponse(ByVal _

                        iLastCommand As Integer) As Long

                        Select Case iLastCommand

                            Case ftpDIR

                                ShowRemoteFileList

                            Case ftpPUT

                                MsgBox "File Sent from " & CurDir()

                            Case ftpGET

                                MsgBox "File Received "& "in " & CurDir()

                            Case ftpDEL

                        End Select

                    End Function



                    Public Function ShowRemoteFileList() As Long

                        Dim sFileList As String

                        Dim sTemp As String

                        Dim p As Integer

                        sTemp = Inet1.GetChunk(1024)

                        Do While Len(sTemp) > 0

                            DoEvents

                            sFileList = sFileList & sTemp

                            sTemp = Inet1.GetChunk(1024)

                        Loop

                        lstRemoteFiles.Clear

                        Do While sFileList > ""

                            DoEvents

                            p = InStr(sFileList, vbCrLf)

                            If p > 0 Then

                                lstRemoteFiles.AddItem

                                    Left(sFileList, p - 1)

                                If Len(sFileList) > (p + 2) Then

                                    sFileList = Mid(sFileList, p + 2)

                                Else

                                    sFileList = ""

                                End If

                            Else

                                lstRemoteFiles.AddItem sFileList

                                sFileList = ""

                            End If

                        Loop

                    End Function



                    Public Function GetFiles(sFileList As String) As Long

                        Dim sFile As String

                        Dim sTemp As String

                        Dim p As Integer

                        iLastFTP = ftpGET

                        sTemp = sFileList

                        Do While sTemp > ""

                            DoEvents

                            p = InStr(sTemp, "|")

                            If p Then

                                sFile = Left(sTemp, p - 1)

                                sTemp = Mid(sTemp, p + 1)

                            Else

                                sFile = sTemp

                                sTemp = ""

                            End If

                            Inet1.Execute Inet1.URL, "GET " & sFile & _

                                " " & sFile

                        'wait until this execution is done

                        `before going to next file

                            Do

                                DoEvents

                            Loop Until Not _

                                Inet1.StillExecuting

                        Loop

                        iLastFTP = ftpDIR

                        Inet1.Execute Inet1.URL, "DIR"

                    End Function



                    Public Function PutFiles(sFileList As String) As Long

                        Dim sFile As String

                        Dim sTemp As String

                        Dim p As Integer

                        iLastFTP = ftpPUT

                        sTemp = sFileList

                        Do While sTemp > ""

                            DoEvents

                            p = InStr(sTemp, "|")

                            If p Then

                                sFile = Left(sTemp, p - 1)

                                sTemp = Mid(sTemp, p + 1)

                            Else

                                sFile = sTemp

                                sTemp = ""

                            End If

                            Inet1.Execute Inet1.URL, "PUT" & sFile & _

                                " " & sFile

                        'wait until this execution is done

                        `before going to next file

                            Do

                                DoEvents

                            Loop Until Not Inet1.StillExecuting

                        Loop

                        iLastFTP = ftpDIR

                        Inet1.Execute Inet1.URL, "DIR"

                    End Function



                    Private Sub dirLocal_Change()

                        filLocal.Path = dirLocal.Path

                    End Sub



                    Private Sub drvLocal_Change()

                        dirLocal.Path = drvLocal.Drive

                    End Sub



                    Private Sub filLocal_DragDrop(Source _

                            As Control, X As Single, Y As Single)

                        'receiving files from FTP site.

                        Dim I As Integer

                        Dim sFileList As String

                        If TypeOf Source Is ListBox Then

                            For i = 0 _

                                To Source.ListCount - 1

                                If Source.Selected(i) Then

                                    sFileList = _

                                        sFileList & _

                                        Source.List(i) & "|"

                                End If

                            Next

                        End If

                        If Len(sFileList) > 0 Then

                            'strip off the last pipe

                            sFileList = Left(sFileList, _

                                Len(sFileList) - 1)

                            GetFiles sFileList

                        End If

                    End Sub



                    Private Sub _

                        filLocal_MouseDown(Button As _

                        Integer, Shift As Integer, X As _

                        Single, Y As Single)

                        filLocal.Drag vbBeginDrag

                    End Sub



                    Private Sub filLocal_MouseUp(Button _

                        As Integer, Shift As Integer, _

                        X As Single, Y As Single)

                        filLocal.Drag vbEndDrag

                    End Sub



                    Private Sub _

                        lstRemoteFiles_DragDrop(Source _

                        As Control, X As Single, Y As Single)

                        Dim I As Integer

                        Dim sFileList As String

                        If TypeOf Source Is FileListBox Then

                            For i = 0 To Source.ListCount - 1

                                If Source.Selected(i) Then

                                    sFileList = sFileList & _

                                      Source.List(i) & "|"

                                End If

                            Next

                        End If

                        If Len(sFileList) > 0 Then

                            'strip off the last pipe

                            sFileList = Left(sFileList, _

                                Len(sFileList) - 1)

                            PutFiles sFileList

                        End If

                    End Sub



                    Private Sub _

                        lstRemoteFiles_KeyDown(KeyCode _

                        As Integer, Shift As Integer)

                        If KeyCode = vbKeyDelete Then

                            Inet1.Execute Inet1.URL, "DEL " & _

                                lstRemoteFiles.List( _

                                lstRemoteFiles.ListIndex)

                            Do

                                DoEvents

                            Loop While Inet1.StillExecuting

                        End If

                        iLastFTP = ftpDIR

                        Inet1.Execute Inet1.URL, "DIR"

                    End Sub



                    Private Sub _

                        lstRemoteFiles_MouseDown(Button _

                        As Integer, Shift As Integer, )

                        X As Single, Y As Single)

                        lstRemoteFiles.Drag vbBeginDrag

                    End Sub



                    Private Sub lstRemoteFiles_MouseUp(Button As _

                        Integer, Shift As Integer, _

                        X As Single, Y As Single)

                        lstRemoteFiles.Drag vbEndDrag

                    End Sub
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1488239
I can't believe that I missed this one.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1488240
Problem is you need DoEvents in your spin loop. The Inet control is provided by the OS and if you don't have a DoEvents inside your:

Do While control.StillExecuting = True
    DoEvents
Loop

The OS never gets a chance to execute.

I had this identical problem in a web poster I wrote. Source code and install is online at:

www.hostpc.net/madmark

Check it before you award the points!

M

0
 
LVL 4

Expert Comment

by:idcanada
ID: 1488241
mark2150,

I am just a little disapointed by your comment as it suggests that my answer
is not right.
Your suggestion for the DoEvents is legit,
however already implanted in the above answer.

    ' wait until this execution is done
    ' before going to next file

     Do
     DoEvents
     Loop Until Not _
     Inet1.StillExecuting

The point system on EE is as significant as you allow it.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 12

Expert Comment

by:mark2150
ID: 1488242
One "DoEvents" is a *LOT* less code than the above. It was not meant as a critique. But when I can replace two pages of code with one or two lines, that, to me, is an improvement. Certainly if your solution works you can have the points. The code you posted was overwhelming and I was unable to rapidly focus on the fix.

M

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1488243
DoEvents in a loop is bad. Never use doevents in a loop!!!!!!!!!!
Use timers instead!!
0
 

Expert Comment

by:pofpof98
ID: 1488244
Hi
Just passing by, so just my experience about the ****ing Inet control (may be developed by a couple of trainees ...)

The StillExcuting method is 100% bugged => the Inet control (already 50% bugged) is now 0000000000% useful ! Those who pretend the contrary never use it.

There is a post in the M$ KB about this problem.
I don't remember exactly where but they say =true must be replaced by =-1 or =1 or something like that.
This answer is bullsheet too.

The DoEvents method will sometimes resolve the problem, sometimes not (looks like M$ product stability?)

Switch to winsock control (or better winsock DLL).
This is what I have done and I don't regret it.
I know it's a longer development but the stability is a luxury and by the way you will have spent the same time resolving your problem.

Go winsock.com & Carl & Gary

Keep the faith !
0
 

Expert Comment

by:pofpof98
ID: 1488245
Hi
Just passing by, so just my experience about the ****ing Inet control (may be developed by a couple of trainees ...)

The StillExcuting method is 100% bugged => the Inet control (already 50% bugged) is now 0000000000% useful ! Those who pretend the contrary never use it.

There is a post in the M$ KB about this problem.
I don't remember exactly where but they say =true must be replaced by =-1 or =1 or something like that.
This answer is bullsheet too.

The DoEvents method will sometimes resolve the problem, sometimes not (looks like M$ product stability?)

Switch to winsock control (or better winsock DLL).
This is what I have done and I don't regret it.
I know it's a longer development but the stability is a luxury and by the way you will have spent the same time resolving your problem.

Go winsock.com & Carl & Gary

Keep the faith !
0

Featured Post

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

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

707 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

11 Experts available now in Live!

Get 1:1 Help Now