Results 1 to 9 of 9

Thread: Error 424 Object required ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Error 424 Object required ?

    Hello,
    dont know what's wrong with this code, I get always error 424 when I compile exe, but when I start it from vbproject, it run's without any problem?

    Here is code:

    Code:
    Private hOpen As Long
    Private hConnection As Long
    Private hFile As Long
    Private dwType As Long
    Private dwSeman As Long
    Private Sub Command1_Click()
        
        'Variables
        sServer = txtServer.Text
        sUser = txtUser.Text
        sPassword = txtPassword.Text
        sDir = txtDir.Text
        sLocal = App.Path & "\" & TxtFile.Text
        sRemote = TxtFileR.Text
        
        'Save values to remember
        SaveSetting "PutGet FTP", "Values", "Server", txtServer.Text
        SaveSetting "PutGet FTP", "Values", "User", txtUser.Text
        SaveSetting "PutGet FTP", "Values", "Password", txtPassword.Text
        SaveSetting "PutGet FTP", "Values", "Directory", txtDir.Text
        
    'Open INTERNET
        hOpen = InternetOpen("PutGet FTP", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
        If hOpen = 0 Then 'ZERO means Internet Coudn't Open
            MsgBox "Error: " & Err.LastDllError, 32, "Internet Conection Error"
            Status.Caption = "Disconnected..."
            Exit Sub
        End If
        Status.Caption = "Internet Open..."
        
        dwType = FTP_TRANSFER_TYPE_BINARY 'SET TO BINARY
        dwSeman = 0 'Set Conection Active
        hConnection = 0 'Reset Conection
        
    'Connect to server
        hConnection = InternetConnect(hOpen, sServer, INTERNET_INVALID_PORT_NUMBER, sUser, sPassword, INTERNET_SERVICE_FTP, dwSeman, 0)
        If hConnection = 0 Then 'ZERO means can't connect to Server
            MsgBox "Error: " & Err.LastDllError, 32, "Server Conection Error"
            Status.Caption = "Disconnected..."
            Exit Sub
        End If
        Status.Caption = "Connected to Server..."
    
    'Specify Initial Directory
        OpenDir = FtpSetCurrentDirectory(hConnection, sDir)
        If OpenDir = False Then 'False means specified directory is wrong
            MsgBox "Error: " & Err.LastDllError, 32, "Initial Directory Error"
            Status.Caption = "Disconnected..."
            If hConnection <> 0 Then 'Disconnect if is still conected
                Cerrar = InternetCloseHandle(hConnection)
            End If
            Exit Sub
        End If
        Status.Caption = "Directory Ready..."
    
    'Put File
        Subir = FTPPutFile(hConnection, sLocal, sRemote, dwType, 0)
        If Subir = False Then 'False means couldn't send the file
            MsgBox "Error: " & Err.LastDllError, 32, "File Transfer Error"
            Status.Caption = "Disconnected..."
            If hConnection <> 0 Then 'Disconnect if is still conected
                Cerrar = InternetCloseHandle(hConnection)
            End If
            Exit Sub
        End If
        Status.Caption = "Sending File..."
        
    'Close conection
        If hConnection <> 0 Then
            Cerrar = InternetCloseHandle(hConnection)
            Status.Caption = "Disconnected..."
        End If
        
    End Sub
    
    Private Sub Command2_Click()
        'Variables
        sServer = txtServer.Text
        sUser = txtUser.Text
        sPassword = txtPassword.Text
        sDir = txtDir.Text
        sLocal = App.Path & "\" & TxtFile.Text
        sRemote = TxtFileR.Text
        
        'Save values to remember
        SaveSetting "PutGet FTP", "Values", "Server", txtServer.Text
        SaveSetting "PutGet FTP", "Values", "User", txtUser.Text
        SaveSetting "PutGet FTP", "Values", "Password", txtPassword.Text
        SaveSetting "PutGet FTP", "Values", "Directory", txtDir.Text
        
    'Open INTERNET
        hOpen = InternetOpen("CYSM FTP", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
        If hOpen = 0 Then 'ZERO means Internet Coudn't Open
            MsgBox "Error: " & Err.LastDllError, 32, "Internet Conection Error"
            Status.Caption = "Disconnected..."
            Exit Sub
        End If
        Status.Caption = "Internet Open..."
        
        dwType = FTP_TRANSFER_TYPE_BINARY 'SET TO BINARY
        dwSeman = 0 'Set Conection Active
        hConnection = 0 'Reset Conection
    
    'Connect to server
        hConnection = InternetConnect(hOpen, sServer, INTERNET_INVALID_PORT_NUMBER, sUser, sPassword, INTERNET_SERVICE_FTP, dwSeman, 0)
        If hConnection = 0 Then 'ZERO means can't connect to Server
            MsgBox "Error: " & Err.LastDllError, 32, "Server Conection Error"
            Status.Caption = "Disconnected..."
            Exit Sub
        End If
        Status.Caption = "Connected to Server..."
    
    'Specify Initial Directory
        OpenDir = FtpSetCurrentDirectory(hConnection, sDir)
        If OpenDir = False Then 'False means specified directory is wrong
            MsgBox "Error: " & Err.LastDllError, 32, "Error de Directorio Inicial"
            Status.Caption = "Disconnected..."
            If hConnection <> 0 Then 'Disconnect if is still conected
                Cerrar = InternetCloseHandle(hConnection)
            End If
            Exit Sub
        End If
        Status.Caption = "Directory Ready..."
    
    'Get File
        Bajar = FTPGetFile(hConnection, sRemote, sLocal, False, FILE_ATTRIBUTE_NORMAL, dwType Or INTERNET_FLAG_RELOAD, 0)
        If Bajar = False Then 'False means couldn't get the file
            MsgBox "Error: " & Err.LastDllError, 32, "File Transfer Error"
            Status.Caption = "Disconnected..."
            If hConnection <> 0 Then 'Disconnect if is still conected
                Cerrar = InternetCloseHandle(hConnection)
            End If
            Exit Sub
        End If
        Status.Caption = "Downloading File..."
        
    'Close conection
        If hConnection <> 0 Then
            Cerrar = InternetCloseHandle(hConnection)
            Status.Caption = "Disconnected..."
        End If
        
    
    End Sub
    
    Private Sub Command3_Click()
    End
    End Sub
    
    Private Sub Form_Load()
    'Values to remember
    
        txtServer.Text = GetSetting("PutGet FTP", "Values", "Server")
        txtUser.Text = GetSetting("PutGet FTP", "Values", "User")
        txtPassword.Text = GetSetting("PutGet FTP", "Values", "Password")
        txtDir.Text = GetSetting("PutGet FTP", "Values", "Directory")
        TxtFile.Text = "Text.txt"
        TxtFileR.Text = "Text.txt"
        
    End Sub
    here is module:

    Code:
    Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
    Public Const FTP_TRANSFER_TYPE_BINARY = &H2
    Public Const FTP_TRANSFER_TYPE_ASCII = &H1
    Public Const INTERNET_INVALID_PORT_NUMBER = 0
    Public Const INTERNET_SERVICE_FTP = 1
    Public Const INTERNET_FLAG_RELOAD = &H80000000
    Public Const FILE_ATTRIBUTE_NORMAL = &H80
    
    Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
    Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
    Public Declare Function FTPPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
    Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Long
    Public Declare Function FTPGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean

    Afther compile code, not working ( error 424 ) ?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Error 424 Object required ?

    Does this the error occur on your computer, or just on others?

    If it is just on others, see the article Why doesn't my program work on another computer? from our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)

    If it occurs on yours too, when does it occur (which routine)?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Error 424 Object required ?

    Quote Originally Posted by si_the_geek
    Does this the error occur on your computer, or just on others?

    If it is just on others, see the article Why doesn't my program work on another computer? from our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)

    If it occurs on yours too, when does it occur (which routine)?
    On mine, I havent test it on other since it wont work on mine!
    Only in my project source folder works without problem or when I use it in vbproject!
    If I copy exe to other dir, I get error 424!

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Error 424 Object required ?

    Which part of the program does the error occur in (eg: Command1_Click) ?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Error 424 Object required ?

    Quote Originally Posted by si_the_geek
    Which part of the program does the error occur in (eg: Command1_Click) ?
    Put Get, so both
    command1 - command2
    But when test it from vbproject, no errors, all works fine ?

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Error 424 Object required ?

    The only thing that jumps out at me (which is in both subs) is this line:
    Code:
        sLocal = App.Path & "\" & TxtFile.Text
    This assumes that the contents of TxtFile.Text is the name of a file, which is in the same folder as your program (and that the folder is not the root of the drive).

    For both you should check if the folder is the root of the drive (if so, don't use the "\"), and for Put you should check that the file actually exists.

    It doesn't seem like it should cause the error you are getting, but I don't use FTP code.


    If that doesn't solve it, you'll need to track it down a bit more.. for example, what is the value of Status.Caption when the error occurs? (as there are several lines between each time you change it, you could add a few more values for it in each section to narrow down the issue further)

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Error 424 Object required ?

    post the form
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Error 424 Object required ?

    Quote Originally Posted by westconn1
    post the form
    evrything posted already in 1st post

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Error 424 Object required ?

    i mean attach the form (form1.frm), not the code
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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