Hi Jim,
When I first read your answer, I thought that wouldn't work. But I tried it
out and found it is interesting. I changed it a bit so I could get the two
values in two separated variables. Here is what I came up with:
Function IcelandBanking(ByRef strMsg As String) As Boolean
Dim WontPay As Long
Dim NoReserves As Boolean
'Code here to calculate WontPay and NoReserves
WontPay = 1
NoReserves = False
If WontPay > 0 Then
strMsg = "Small Withdrawals Only"
Else
strMsg = "You are out of luck"
End If
IcelandBanking = NoReserves
End Function
'--
Sub FinancialStatus()
Dim strText As String
Dim strTrueOrFalse As String
Dim strMsg As String
Dim strResult As String
Dim intPosVbCr As Integer
' MsgBox IcelandBanking(strText) & vbCr & strText
strResult = IcelandBanking(strText) & vbCr & strText
intPosVbCr = InStr(1, strResult, vbCr)
strTrueOrFalse = Mid(strResult, 1, intPosVbCr - 1)
strMsg = Mid(strResult, intPosVbCr + 1, Len(strResult) - intPosVbCr)
MsgBox "strTrueOrFalse = " & strTrueOrFalse & vbCrLf & _
"strMsg = " & strMsg
End Sub
It works OK, but I am not sure I will use it.
My problem is that I have to check 4 different information from a
transaction. I want to group the 4 validations in a separate procedure or
function. If an error occurs, I want to display a pertinent message and exit
the main proc. Here is another way I figured out to solve my problem:
Option Explicit
Public strMessage As String
' ---
Function fbooDataIsValid(ByVal pstrParam1 As String, _
ByVal pintParam2 As Integer) As Boolean
If pstrParam1 = "Hi Jim" Then
strMessage = "Error, my friend. You should have said Hello!."
fbooDataIsValid = False
Exit Function
End If
If pintParam2 < 100 Then
strMessage = "Error, your number is < 100."
fbooDataIsValid = False
Exit Function
End If
fbooDataIsValid = True
End Function
' ---
Sub TestDeJac()
Dim strText As String
strText = "Hi Jim"
If Not fbooDataIsValid(strText, 36) Then
MsgBox strMessage, vbCritical, "Sofica"
Exit Sub
End If
MsgBox "It's OK...", vbInformation, "Sofica"
End Sub
Thank you for your original comment and good night.