• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 541
  • Last Modified:

Object variable or With block variable not set


I am using error trapping, and I occasionaly get this error with details below...

An unexpected error has occurred in this application:

Error 91
Description: Object variable or With block variable not set
Project: Project1
Module: frmMain
Procedure: NewLog
Line: 77
Version: 1.0.50

And line 77 reads
77       frmTouchscreen.ResetLogData

and resetlogdata procedure is ...


Public Sub ResetLogData()
' <VB WATCH>
264        On Error GoTo vbwErrHandler
265        Const VBWPROCNAME = "frmTouchscreen.ResetLogData"
266        If vbwProtector.vbwTraceProc Then
267            Dim vbwProtectorParameterString As String
268            If vbwProtector.vbwTraceParameters Then
269                vbwProtectorParameterString = "()"
270            End If
271            vbwProtector.vbwProcIn VBWPROCNAME, vbwProtectorParameterString
272        End If
' </VB WATCH>
273      Dim i As Integer
274      intEnterLogStep = 0
275      intDefectNumber = 0
276      lblLogInput(0).Caption = "Start at Top"
277      For i = 1 To 15
278        lblLogInput(i).Visible = False
279      Next i
280      lblTagInput.Caption = ""
' <VB WATCH>
281        If vbwProtector.vbwTraceProc Then vbwProtector.vbwProcOut VBWPROCNAME
282        Exit Sub
    ' ----- Error Handler ------
vbwErrHandler:
    Const VBWPROCEDURE = "ResetLogData"

    Select Case vbwErrorHandler(Err.Number, Err.Description, VBWPROJECT, VBWMODULE, VBWPROCEDURE, Erl)
        Case vbwEnd
            End
        Case vbwRetry
            Resume
        Case vbwIgnoreLine
            Resume Next
        Case vbwDoDumpVariable
            vbwOpenDumpFile
            vbwReportToFile VBW_LOCAL_STRING
            vbwReportVariable "i", i
            vbwReportModuleVariables
            vbwReportGlobalVariables
            vbwCloseDumpFile
            Err.Number = -1
            GoTo vbwErrHandler
    End Select
    If vbwProtector.vbwTraceProc Then vbwProtector.vbwProcOut VBWPROCNAME
' </VB WATCH>
End Sub


This has only hapened 3 times in several weeks of running.  Any ideas.  
0
Tom_Hickerson
Asked:
Tom_Hickerson
  • 7
  • 5
  • 2
  • +4
1 Solution
 
PePiCommented:
this usually happens when there is no matching If - End Ifs, Do - Loop, While - Wend, With - End With, Select - end Select. Double check your code blocks.


HTH!!!


0
 
PePiCommented:
P.S. the error i believe is not in ResetLogData Subroutine. check it in the calling procedure (line 77). it should be around there somewhere.
0
 
PePiCommented:
P.S.S. This can also happen when an object is not properly SET or instantiated
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Tom_HickersonAuthor Commented:
Well, I don't think it is the ifs endif etc because the routine executes many times a day with no problem.  

Here is the calling procedure.  I am not familiar with SET or instantiated.  Any ideas


Public Sub NewLog()
' <VB WATCH>
46         On Error GoTo vbwErrHandler
47         Const VBWPROCNAME = "frmMain.NewLog"
48         If vbwProtector.vbwTraceProc Then
49             Dim vbwProtectorParameterString As String
50             If vbwProtector.vbwTraceParameters Then
51                 vbwProtectorParameterString = "()"
52             End If
53             vbwProtector.vbwProcIn VBWPROCNAME, vbwProtectorParameterString
54         End If
' </VB WATCH>

55       Dim i As Integer

56       txtOffset = "0.0"
57       txtFrontTrim = ""
58       txtEndTrim = ""
59       txtEndOfLog = "200.0"
60       CalcLogLength

61       optLogOrientation(0).Value = False
62       optLogOrientation(1).Value = False

63       For i = 0 To chkDefect.UBound
64         chkDefect(i).Caption = "#" & i + 1 & " at:"
65         chkDefect(i).Value = 0
66         txtDefect(i).Enabled = False
67         txtDefect(i).Text = ""
68         If i > 0 Then
69           chkDefect(i).Enabled = False
70         End If
71       Next i

72       g_iLogID = -1
73       cmdUndo.Enabled = False
74       cmdSort.Enabled = False
75       cmdOptimize.Enabled = True
76       lstSolutions.Clear

77       frmTouchscreen.ResetLogData

' <VB WATCH>
78         If vbwProtector.vbwTraceProc Then vbwProtector.vbwProcOut VBWPROCNAME
79         Exit Sub
    ' ----- Error Handler ------
vbwErrHandler:
    Const VBWPROCEDURE = "NewLog"

    Select Case vbwErrorHandler(Err.Number, Err.Description, VBWPROJECT, VBWMODULE, VBWPROCEDURE, Erl)
        Case vbwEnd
            End
        Case vbwRetry
            Resume
        Case vbwIgnoreLine
            Resume Next
        Case vbwDoDumpVariable
            vbwOpenDumpFile
            vbwReportToFile VBW_LOCAL_STRING
            vbwReportVariable "i", i
            vbwReportModuleVariables
            vbwReportGlobalVariables
            vbwCloseDumpFile
            Err.Number = -1
            GoTo vbwErrHandler
    End Select
    If vbwProtector.vbwTraceProc Then vbwProtector.vbwProcOut VBWPROCNAME
' </VB WATCH>
End Sub
0
 
PePiCommented:
are you using any objects in your application? like what is vbwProtector? is it a function? a Sub? a Class?
0
 
Tom_HickersonAuthor Commented:
vbwProtector is the program I use to create the error trapping.  They are functions in a bas file
0
 
PePiCommented:
this is a bit odd. and you cannot step through the code because the error is intermittent right? How about checking the procedure that's calling NewLog? have you checked that?
0
 
Tom_HickersonAuthor Commented:
I am just printing the info from the error handler and storing it in a text file.  The error has only occured 3 times, but the code has executed 2006 times.  I have error checking in all procedures so how could be in the procedure calling newlog?  

Is there some additional error checking code I can put in place to help find this error?
0
 
PePiCommented:
this is sometimes the crux in programming. I usually don't put in error handling until i've fully tested my codes. this enables me to find out exactly where the error occurs. using error handling sometimes is deceiving as it jumps away from the actual line of code that caused the error. error handling should only take care of unexpected errors that can happen. and you may say that this is an unexpected error right?

you'll never know. i've seen stranger things in my life. my suggestion is to comment out all of your error handling routine. run the application again and again and again and hopefully you can come up with the same error (then again it might not be the same). some errors are a spin-off of another error.
0
 
PSSUserCommented:
How about putting a message box in the first line of the error handler for ResetLogData showing the error line.

I think you will find that the error is on this line:
266        If vbwProtector.vbwTraceProc Then

and that somewhere in you code the vbcProtector object is being closed/set to nothing.
0
 
PreeceCommented:
Another thing to try is to go to Tools > Options > General, and select "Break on All Errors".  This way, you don't need to comment out all of your error handling code...

Also, I would definitely step thru ResetLogData.  Well, if it only happens once in a while, add some logging code...

For example, put this in a class module and call it claLogToFile, or something:

Option Explicit
Private pvsLogFile As String

Public Property Let gpSetFile(sLogFile As String)
    pvsLogFile = sLogFile
End Property

Public Sub gsnLogToFile(sData As String, bPrintDate As Boolean)
    Dim lFile As Long
   
    lFile = FreeFile()
    Open pvsLogFile For Append As #lFile
    If bPrintDate Then
        Print #lFile, Now & ":   " & sData
    Else
        Print #lFile, sData
    End If
    Close #lFile
   
End Sub


Declare and instantiate it like this, perhaps in your startup module:

'Gen Declarations
Public oLogToFile As claLogToFile

Sub main()
    Set oLogToFile = New claLogToFile
End Sub


Then, add logging code, such as:

Public Sub ResetLogData()
' <VB WATCH>
264        On Error GoTo vbwErrHandler
265        Const VBWPROCNAME = "frmTouchscreen.ResetLogData"
             
             oLogToFile.gsnLogToFile "ResetLogData:  If vbwProtector.vbwTraceProc Then", True

266        If vbwProtector.vbwTraceProc Then
267            Dim vbwProtectorParameterString As String

                 oLogToFile.gsnLogToFile "ResetLogData:  If vbwProtector.vbwTraceParameters Then", True

268            If vbwProtector.vbwTraceParameters Then
269                vbwProtectorParameterString = "()"
270            End If

                 oLogToFile.gsnLogToFile "ResetLogData:  vbwProtector.vbwProcIn VBWPROCNAME, vbwProtectorParameterString", True

271            vbwProtector.vbwProcIn VBWPROCNAME, vbwProtectorParameterString
272        End If
' </VB WATCH>
273      Dim i As Integer
274      intEnterLogStep = 0
275      intDefectNumber = 0
276      lblLogInput(0).Caption = "Start at Top"
277      For i = 1 To 15
278        lblLogInput(i).Visible = False
279      Next i
280      lblTagInput.Caption = ""
' <VB WATCH>
281        If vbwProtector.vbwTraceProc Then vbwProtector.vbwProcOut VBWPROCNAME
282        Exit Sub
    ' ----- Error Handler ------
vbwErrHandler:
    Const VBWPROCEDURE = "ResetLogData"

    Select Case vbwErrorHandler(Err.Number, Err.Description, VBWPROJECT, VBWMODULE, VBWPROCEDURE, Erl)
        Case vbwEnd
            End
        Case vbwRetry
            Resume
        Case vbwIgnoreLine
            Resume Next
        Case vbwDoDumpVariable
            vbwOpenDumpFile
            vbwReportToFile VBW_LOCAL_STRING
            vbwReportVariable "i", i
            vbwReportModuleVariables
            vbwReportGlobalVariables
            vbwCloseDumpFile
            Err.Number = -1
            GoTo vbwErrHandler
    End Select
    If vbwProtector.vbwTraceProc Then vbwProtector.vbwProcOut VBWPROCNAME
' </VB WATCH>
End Sub


Be sure to destroy the oLogToFile object when done:

Set oLogToFile = Nothing


Hope this helps!
Preece
0
 
Tom_HickersonAuthor Commented:

I was getting occasional errors without the error handling code.  I put it in to try and find the errors.  If I take it out I won't know where the error came from or if they had any.  The error handler helped me find a couple of other odd occurances.  Unfortunatly I can not set and watch the program.  It took 2 weeks for the 3 errors to show up in the logfile.  

 
0
 
PePiCommented:
When an error occurs without the proper error handling, a popup messsage box will appear with 4 buttons. this popup message box tells you something about the error. The 4 buttons are Continue, End, Debug & Help.

Usually Conitnue is disabled. Clicking End will stop the execution of the application. Clicking debug will pause the application and will highlight the line that caused the error. Clicking the Help button will launch the MSDN Library (if installed) and will explain something about the error.
0
 
AzraSoundCommented:
Looks like its all related to the code generated by VB Watch.  Why don't you write the guys at aivosto as that would be the most logical place to go for support.
0
 
ArkCommented:
Object variable or With block variable not set means frmTouchscreen is nothing
0
 
Tom_HickersonAuthor Commented:

PePi... I think you are refering to vb.net.  I am using vb 6.0.  When the compiled program errors out I only get a single msgbox with an OK choice.

AzraSound... The reason for the VBWatch code is to find the errors.  I put it in to find out why the application was shutting down.  

I put the error trapping code in so I could log the errors.  The people who are using the program don't relay the VB errors when they have problems.  I get messages like "It had some kinda error thing on the screen"  Yes it would be nice if they would write down the exact error, and what they did prior to getting the error, but that is not going to happen.  

So If you can spot an error that might occur in my code please point it out to me.  If nothing is obvious then please tell me how I might better trap this error.  

Tom
0
 
AzraSoundCommented:
>>The reason for the VBWatch code is to find the errors

Yes but now you are getting errors from within the VBWatch error handling code itself...like I said, this sounds like something you need to bring to their (the creators of VBWatch at aivosto.com) attention.  By the way, VBWatch has the option for adding the ability to have the trapped errors emailed to you from a customer if your customer's are incapable of providing any details to you when they encounter one.
0
 
cjardCommented:

you cant debug a VB6 exe. you need to install the visual basic IDE on the server, then run the server app that youre having trouble with, by pressing PLAY  icon(or F5 key) in the IDE..

none of the guys here seme to have realised youve compiled a full EXE, so they are giving all htis advice about "Break on all errors" (which is good advice, do it) but noone is telling you to run your program in the IDE. Do it, even if it means installing the ide on the server, run your program and wait for it to break. you will then be able to see which object is not set. im guessing its the form object frmTouchScreen.

forms are objects. by default, one instance of each form is created and loaded.. so you always say frmTouchScreen.whatever...

but you COULD also say Dim x as New frmTouchScreen, and gthen show it etc.. so it is entirely feasible that somewhere your code actually unloads the only instance of frmTouchScreen

debug it and see, but remember, you cant debug an exe, you have to debug in the VB IDE
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now