I have created an app using Microsoft VB6, using error handlers in every sub and function (no errors generated). I created an executable, which runs fine on the machine that has VB6 installed on it, but the app does not run on my other box. I get "Run-time error '5': Invalid procedure call or argument".

Am I missing any dll files, or maybe something needs to be included during the creation of the executable?

I am running XP Pro w/ Service Pack 2 on both machines.

Thanks

Recommended Answers

All 6 Replies

Hi,

When you moved it to other PC how did you do it ? Did you just move .exe ?

If so you need to build application and then move all files it generates and run the setup.exe to install.

Hope this helps

Denis

Runtime error 5 doesn't mean to any syntax or compile errors within your app. It causes due to some logical errors within your program. It happens whenever you try to move focus to any control in runtime which is currently disabled. Like you have two textboxes in a form, among them one's enable property is set to false and you are trying to move focus to this textbox. In this context you cannot move focus to this control and vb6 will fetch this runtime error. It also happens if you try to move the focus to such a control other than the control whose tabindex property has been set to 0 in form_load event.

To overcome this problem just check within your coding whether you are trying to move focus to any disabled control or to such a control whose tabindex property is not set to 0.

On the other hand, if you want to run your app in some other computer always create the setup package using vb6's package & deployment wizard. You can also try to run your app without creating any install package by just copying the .exe file and all associated files to respective folders on the target machine. In this case you must have vb6 runtime files installed in the user's computer. But it is always recommended that you create a setup.exe package using package and deployment wizard.

Regards,
Shouvik

I retried it using the Package and Deployment wizard, still get the same error. This time, the error keeps coming up and I have to kill it in the Task Manager.

I am not doing anything with Focus or tabindex properties in my code.

Option Explicit ' forces declaration of variables
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public orig_path As String
Public username As String


Private Sub Desktop_Cmd_Click()
On Error GoTo err_form_load
orig_path = "C:\Documents and Settings\" & username & "\Desktop"
Dir1.Path = orig_path
Exit Sub
err_form_load: '*********** error handler ****************
MsgBox Err.Number & Err.Description
Resume
End Sub


Private Sub Dir1_Change()
On Error GoTo err_form_load
orig_path = Dir1.Path
Exit Sub
err_form_load: '*********** error handler ****************
MsgBox Err.Number & Err.Description
Resume
End Sub


Private Sub Drive1_Change()
On Error GoTo err_form_load
Dir1.Path = Drive1.Drive
Exit Sub
err_form_load: '*********** error handler ****************
MsgBox Err.Number & Err.Description
Resume
End Sub


Private Sub Exit_Cmd_Click()
On Error GoTo err_form_load
Unload Me
Exit Sub
err_form_load: '*********** error handler ****************
MsgBox Err.Number & Err.Description
Resume
End Sub


Private Sub Form_Load()
On Error GoTo err_form_load
Dim init_str As String
Dim r As Long
orig_path = Dir1.Path
init_str = Space$(10)
r = GetUserName(init_str, 10)
username = Left(init_str, InStr(1, init_str, Chr(0)) - 1)
Exit Sub
err_form_load: '*********** error handler ****************
MsgBox Err.Number & Err.Description
Resume
End Sub


Private Sub MyDocs_Cmd_Click()
On Error GoTo err_form_load
orig_path = "C:\Documents and Settings\" & username & "\My Documents"
Dir1.Path = orig_path
Exit Sub
err_form_load: '*********** error handler ****************
MsgBox Err.Number & Err.Description
Resume
End Sub


Private Sub Save_Cmd_Click()
On Error GoTo err_form_load
Dim folder_path As String
Dim olk_path As String
Dim fso As New FileSystemObject
Dim oParent As Folder
Dim oFolder As Folder
Dim oFile As File
Dim i As Integer
Dim new_file As String
Dim file_name As String
Dim x As Integer
Dim y As String
olk_path = ""
Set oParent = fso.GetFolder(orig_path)
CommonDialog1.Filter = "Text Files (*.txt) |*.TXT|All Files (*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowSave
new_file = CommonDialog1.FileName
Open new_file For Output As #1
Print #1, oParent.Name
For Each oFile In oParent.Files
Print #1, " " & oFile.Name
Next
If Sub_Option.Value = True Then
CountFiles (orig_path)
End If
Close #1
MsgBox "Done!", , "Complete"
Exit Sub
err_form_load: '*********** error handler ****************
MsgBox Err.Number & Err.Description
Resume
End Sub


Function CountFiles(orig_path)
On Error GoTo err_form_load
Dim fso As New FileSystemObject
Dim oParent As Folder
Dim oFolder As Folder
Dim oFile As File
Set oParent = fso.GetFolder(orig_path)
For Each oFolder In oParent.SubFolders
Print #1, ""
Print #1, "\" & oFolder.Name
For Each oFile In oFolder.Files
Print #1, " " & oFile.Name
Next
Next
For Each oFolder In oParent.SubFolders
CountFiles (oFolder.Path)
Next
Exit Function
err_form_load: '*********** error handler ****************
MsgBox Err.Number & Err.Description
Resume
End Function


Option Explicit ' forces declaration of variables
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public orig_path As String
Public username As String


Private Sub Desktop_Cmd_Click()
On Error GoTo err_form_load
orig_path = "C:\Documents and Settings\" & username & "\Desktop"
Dir1.Path = orig_path
Exit Sub
err_form_load: '*********** error handler ****************
MsgBox Err.Number & Err.Description
Resume
End Sub

You don't say which of these routines it is erroring from. It would help if the MsgBox error message included subroutine name as well as error message.

However if we take subroutine above then I am not surprised it goes round and round without stopping for following reason.


orig_path = "C:\Documents and Settings\" & username & "\Desktop"

It looks to me as if you are trying to point path to the users Destop folder. However username does not appear to be defined.

Therefore the program errors.

Then prints out the error message.

Your program then says Resume which I believe will take it to
orig_path = "C:\Documents and Settings\" & username & "\Desktop"

Which then errors..........

Hope this helps you sort it.

Denis

I found the problem!

Once I disabled the Resume statements, I got the errors to appear. My problem was restricting the length that the login id could be. On my work laptop (the one I write code on), I log in with a 7-character username, and on my home pc, I log in with my full name (over 10 characters).

init_str = Space$(10)
r = GetUserName(init_str, 10)

Once I changed these numbers from 10 to 30, it works just fine

Thanks to both of you for the help.

I found the problem!

Brilliant - glad you are sorted.

If it is any help for the future, I tend to leave error trapping out completely, unless it is totally necessary.

Most of my programs don't use error trapping because there is no need. As you have seen here the error trapping was masking your problem. I think it also slows down the running because it is another activity that has got to happen.

Best wishes

Denis

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.