Error message - state all strings

C

cereldine

Hi i'm trying to improve an error handler that i'm putting together. I
have a case statement based on an error number. If the error is due to
a string value being null i would like to list all strings in a message
box or something and show all the values?

My question is whether there is a function that will state all strings
being used at that time and their particular value? My code is
relativly long and this would help with debugging Thanks
 
P

Peter T

I'm not sure what you mean by "a string value being null". A variable
declared As String can be empty (unassigned), a vbNullString, or empty
string "", technically not quite the same but for most practical purposes
can be regarded as such and confirmed with -

Len(myString) = 0

A String cannot contain a Null value which can only be assigned to a
Variant. However trying to assign Null to a string would indeed raise an
error (94 probably) but would not change any existing string value.

You would need to roll your own function to return values of your strings.

Regards,
Peter T
 
C

cereldine

Sorry should have explained myself better, i have a lot of worksheets
that open depending on a string value, there have been occassions when
i have been debugging when these strings or search values have been
blank, i thought that if i could output all the current strings with
the value they hold at the time of error then i could narrow down
problem.

Perhaps a better way of putting it would be how do i return the values
for all variables in my procedure at the time when code breaks?
 
P

Peter T

Better ways but to quickly find out what's going wrong something like this -

Public gbDebug As Boolean

Sub Test()
Dim bOK As Boolean
Dim s1$, s2$, s3
Dim n As Long

gbDebug = True ' normally set in some other proc
On Error GoTo errH:
s1 = "aaa"
s2 = "bbb"
n = 1 / 0
s2 = "ccc"
bOK = True
done:

MsgBox "All OK: " & bOK

Exit Sub
errH:
If gbDebug Then
Debug.Print "Err: " & Err.Number, Err.Description
Debug.Print "s1: "; s1
Debug.Print "s2: "; s2
Debug.Print "s3: "; s3
Stop
'ctrl-g to view Immediate window
' F8 to step to line that triggered error
' or drag yellow cursor down to skip
Resume
End If
Resume done
End Sub

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top