Why can't I pass a concatenated string as the argument to a particular subroutine I'm using?
In the code below, you'll see that:
1. An event handler makes calls to a subroutine called "DebugMsg" that provides an easy way to turn on and off MsgBox statements used for debugging.
2. Whether or not the messages get passed to an actual MsgBox statement is based on the value of the constant "DEBUG_MESSAGES"
*** For some reason, the one line of code in "CODE EXAMPLE #2" throws an error, but the two lines of code in "CODE EXAMPLE #1" work fine. As far as I can tell, they are functionally equivalent.
*** This variation does not work either:
DebugMsg "NOT Nothing, Target.Rows.Count=" & CStr(Target.Rows.Count)
*** It's understood that in this trivial case for illustration, "Target" passed to the "Worksheet_Change" subroutine should never be "Nothing"
QUESTIONS
1. "CODE EXAMPLE #1" and "CODE EXAMPLE #2" are equivalent, correct?
2. In any case, do you know why "CODE EXAMPLE #2" does not work even though "CODE EXAMPLE #1" does work?
I love Zoho apps and the VBA support in the Sheet tool, but ...
3. Are there any specific plans to improve the VBA debugging process?
- break points?
- single stepping through code??
- variable inspection?? (hierarchical, in the case of types, arrays, objects, etc.)???
4. Is there any way to make a series of MsgBox statements fire individually (like in Excel)?
5. Is it possible to have more than one Macro Module?
6. (inevitably) I've noticed several differences in behavior between Zoho VBA and Excel VBA (and I don't simply mean what Zoho supports versus what Excel supports).
- Is there a document that lists all the known differences?
Thanks!
Matt
'=============== In a Sheet's Code Module =================
Private Sub Worksheet_Change(ByVal Target As Range)
Dim s1 as String
Application.EnableEvents = false
On Error Goto ENEV
If Target is Nothing Then
DebugMsg "Nothing"
Else
'CODE EXAMPLE #1
s1 = "NOT Nothing, Target.Rows.Count=" & Target.Rows.Count
DebugMsg s1
'CODE EXAMPLE #2
'DebugMsg "NOT Nothing, Target.Rows.Count=" & Target.Rows.Count
'END CODE EXAMPLES
End if
GOTO LEAVE
ENEV:
MsgBox "Worksheet_Change Error"
LEAVE:
Application.EnableEvents = true
End Sub
'=============== In "MACROS" Macro Module =================
PUBLIC CONST DEBUG_MESSAGES = TRUE
Public Sub DebugMsg(sMsg as String)
If DEBUG_MESSAGES then
MsgBox sMsg
End If
Goto LEAVE
ENEV:
Msgbox "DebugMsg ERROR"
LEAVE:
Application.EnableEvents = true
End Sub