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 ) ? :(
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)?
Re: Error 424 Object required ?
Quote:
Originally Posted by si_the_geek
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!
Re: Error 424 Object required ?
Which part of the program does the error occur in (eg: Command1_Click) ?
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 ?
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)
Re: Error 424 Object required ?
Re: Error 424 Object required ?
Quote:
Originally Posted by westconn1
post the form
evrything posted already in 1st post
Re: Error 424 Object required ?
i mean attach the form (form1.frm), not the code