I have a function "CheckModifyState" in a module:

private Function CheckModifyState(byval ExitMsg as string, byval MsgReturn as Integer) as Boolean
'set the message text
ExitMsg = "The document has been modified, do you want to save it?"

'check if the content of the current document has been modified or not
If SendMessage(rtfText.hwnd, EM_GETMODIFY, 0, 0) = true then
'if true then show a messagebox asking if he would like to save the doc.
MsgReturn = MsgBox(ExitMsg, vbQuestion + vbYesNoCancel, "Note Editor")
'if Yes then save the document
If MsgReturn = vbYes then
mnuFileSaveAs_Click
'if cancel then return to application
ElseIf MsgReturn = vbCancel then
CheckState = false
else
Exit Function
End If
'if the document has not been modified then return true
else
CheckState = true
End If
End Function



And this function is called by mnuFileNew_OnClick event

private Sub mnuFileNew_Click()
Dim ModifyState as Boolean
'check if the current document has been modified or not
ModifyState = CheckModifyState(byval ExitMsg, byval MsgReturn)
'if modified then ask to save the document
If ModifyState = true then
'open a new file
rtfText.SelStart = 0
rtfText.SelLength = len(ActiveControl.Text)
rtfText.Text = ""
me.Caption = "Note Editor - [Untitled]"
End If
End Sub



When I click "New" menu, it returns compiler error: Variable not defined
And highlights "ExitMsg"

ModifyState = CheckModifyState(byval ExitMsg, byval MsgReturn)



What could be the problem? Isn't this how to call a function or do I have to define variable before calling?
Like this;

Dim ExitMsg as string
Dim MsgReturn as Integer
Dim ModifyState as Boolean
'check if the current document has been modified or not
ModifyState = CheckModifyState(byval ExitMsg, byval MsgReturn)



Other questions;
Is there any limitation of number of modules one can have in a project?
Is it a good idea to have a modules for a Sub procedure or function called from more than two places?
What is the best situation in which one should have a module?

Thanks
Simon