Runtime error 0 when populating a combo box in vb6

Strange machine-specific error ...

I have an application where a combo box text value is set to the document path (ie ..

cmbAIDFile.Text = clsTonyToolkit.GetSetting("ExportAIDFile",gtypmetadata.gcnnCentral) & ""

      

Forget all the GetSetting routines and so on, it just returns a string of text and works great.

This works correctly on all but one machine. This particular Vista machine throws a runtime error 0 and logs the user out of the program regardless of the ErrorHandling in the procedure. Other Vista machines are working fine.

Any answers to this confusing issue would be greatly appreciated.


Thank you for your help.

The machine is running Vista Business 64 bit.

The user has the ability to obtain administrator rights through the User Account Control, which is enabled.

Following your prompts, I tried to run the application as administrator and get all sorts of weird responses (missing files, unregistered, etc.). Uninstall the app and try reinstalling. I think that shadow copies of a folder can confuse things as well.

+1


source to share


4 answers


You may have found the wrong place for the error. When you change a property of an Text

object ComboBox

, the event ComboBox

Change

fires if the new text is different from the previous text. Events LostFocus

and / or Validate

may fire as well, depending on what your code is doing and how your form is configured.

If Change

an error occurs in the event handler (or in the event handlers, LostFocus

or Validate

if you do something with them), the error handling code in the code that changes the combo box is never called (this is due to how error handling and events work in VB6 ).

Generally, you should always put an error handler in every single procedure (Sub, Function, or Property) in your VB6 code, because you can never be sure that you will catch every error otherwise.

Here's a quick example to show that error handling might not always work the way you think it should in VB6.

Create a new Standard EXE project and add CommandButton (Command1) and ComboBox (Combo1) to the default form and add the following code to the form:

Private Sub Combo1_Change()

   Dim a As Long
   a = 1/0 '<-- this will cause a divide-by-zero runtime error'

End Sub

Private Sub Command1_Click()

    On Error GoTo MyErrorHandler

    'Change the combobox text.'
    'This will cause the Change event to fire' 

    Combo1.Text = "test"

    Exit Sub

MyErrorHandler:
    'This code will not be executed if an error occurs in Combo1_Change...'
    MsgBox "My error-handler called."

End Sub

      



If you compile the project and run the resulting EXE, you will get a runtime error when you press Command1 and the program will exit. This is because the error handling code that was added ( MyErrorHandler

in the example) is not called. However, if you add error handling code to your event handler Combo1_Change

, you can catch the error and try to deal with it (at least you can prevent the program from crashing).

So I would make sure that there is error handling code in each event procedure, and add it if it is missing. This should make it easier to pinpoint the exact location of the error. For example, if you have code in an event procedure cmbAIDFile_Change

, make sure it has error handling. I would add line numbers to my code (if you don't already have them): this way you can use Erl

in your error handling code to get the actual line number where the error occurred. See the following code for an example of how to write line numbers in error messages.

Using Erl to Send Line Numbers in Error Messages

Private Sub cmbAIDFile_Change()

1000   On Error Goto ErrorHandler

1010   DoSomething
1020   DoSomethingElse

ErrorHandler:

1030   Dim sErrMsg As String
       sErrMsg = "A fatal error occurred." & vbCrLf & vbCrLf  & _
                 "Method: cmbAIDFile_Change" & vbCrLf & _
                 "Line: " & Erl & vbCrLf & _ 
                 "Err.Number: " & Err.Number & vbCrLf & _
                 "Err.Description: " & Err.Description

1040   MsgBox sErrMsg, vbCritical+vbOKOnly, "Fatal error"

End Sub 

      

Once you have finer error handling, you can start investigating why you are only seeing the problem on one machine, because you should have much more reliable information about the error that is happening and be in a much better understanding of what the underlying problem is. reason.

+6


source


What's the difference between Vista machines?

  • version
  • Settings
  • User rights


Al may affect the operation of the application.

+1


source


Mike Spears' suggestion is fair for the money you need to put error handlers on all of your events, since assigning a string to combo text raises multiple events.

My tab is to try the following.

Dim TempS as String
TempS = clsTonyToolkit.GetSetting("ExportAIDFile",gtypmetadata.gcnnCentral) & ""
cmbAIDFile.Text = TempS

      

Something funky can happen in Unicode. This is evidenced by error 0 "Invalid procedure call or argument" for a normal assignment. Again, if you have event routines for the cmbAID file, you need to trap them so you can see if there is an error.

+1


source


Use these codes

Private Sub Command1_Click()
    On Error Resume Next
        'Your combo-box code here
    On Error GoTo 0
End Sub

      

0


source







All Articles