Run-Time error 5

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2007
Posts: 7
Reputation: lz300 is an unknown quantity at this point 
Solved Threads: 0
lz300 lz300 is offline Offline
Newbie Poster

Run-Time error 5

 
0
  #1
Jun 30th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 319
Reputation: DenisOxon is an unknown quantity at this point 
Solved Threads: 15
DenisOxon's Avatar
DenisOxon DenisOxon is offline Offline
Posting Whiz

Re: Run-Time error 5

 
0
  #2
Jun 30th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Run-Time error 5

 
0
  #3
Jun 30th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 7
Reputation: lz300 is an unknown quantity at this point 
Solved Threads: 0
lz300 lz300 is offline Offline
Newbie Poster

Re: Run-Time error 5

 
0
  #4
Jun 30th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 319
Reputation: DenisOxon is an unknown quantity at this point 
Solved Threads: 15
DenisOxon's Avatar
DenisOxon DenisOxon is offline Offline
Posting Whiz

Re: Run-Time error 5

 
0
  #5
Jun 30th, 2007
Originally Posted by lz300 View Post

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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 7
Reputation: lz300 is an unknown quantity at this point 
Solved Threads: 0
lz300 lz300 is offline Offline
Newbie Poster

Re: Run-Time error 5

 
0
  #6
Jul 1st, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 319
Reputation: DenisOxon is an unknown quantity at this point 
Solved Threads: 15
DenisOxon's Avatar
DenisOxon DenisOxon is offline Offline
Posting Whiz

Re: Run-Time error 5

 
0
  #7
Jul 1st, 2007
Originally Posted by lz300 View Post
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC