M
Mole Hunter
I am having trouble trying to pass a control (textbox) object to a
function I wrote. I want to pass the textbox so that I can manipulate
its properties more easily without having to worry about which textbox
I am working with. (It is some repetitive code and I am trying to be
good by creating subroutines to do things in a generic manner.)
I realize that the passed "callername" parameter in the function is
probably redundant, I just haven't taken it out yet. (It can be
replaced by using the control's .NAME property...if it worked right.
It is a bit cleaner to use "callername".)
When I debug the code the value of the passed parameter shows up as
the controls value. For example, if the textbox contains "11" the
control CALLER in the function shows as having the value of "11" and
not as the name of the text box control that I sent it.
However, if you look in the function, there is a msgbox that I build
that uses a property of the control thusly: caller.Name. In debug
mode that does have the correct value, i.e. it returns the name of the
control that I passed to the function. But it is the other attempts
to use the control that don't appear to be working: caller.value.
They don't evaluate to anything an my ISDATE check fails. The whole
purpose of this routine is to do some data validation of what was
entered into the box. I am trying to capture a time value from the
user, hours at a minimum and maybe some minutes.
There may be typos further down in the code, I noticed a few and
corrected them while pasting it into this message. But the code is
failing near the top at the IF NOT ISDATE line, so they shouldn't
matter at this point.
Here is my code for the function call:
---------------------
<...>
numChkResult = NumberCheck(txtbxEndTime, "End")
<...>
---------------------
Function NumberCheck(caller As Control, callername As String) As
Integer
Dim splArray As Variant
Dim convArr
Dim arrCallerName(2) As String
Dim callingbox As Object 'Want to be able to return to source
control
Dim arrayCount As Integer 'Don't exactly have an array.count
property, so using this instead w/ UBOUND
splArray = Split(caller.Value, ":")
If Not IsDate(caller.Value) Then
MsgBox "The value of the calling box is: " & caller.Value &
vbCrLf & _
"The calling text box, " & caller.Name & ", doesn't appear to have
a valid time in it."
NumberCheck = 1 'setting return value to 1, indicating a
problem
Exit Function
End If
arrayCount = UBound(splArray) + 1 'Just setting the variable
here to clean up the code a bit
If arrayCount > 2 Then
MsgBox "There were too many colons in the " & caller.Name & " text
box. Go back and try again."
MsgBox "Trying to set the focus back to the original text box that
made the call: " & caller.Name
NumberCheck = 1 'setting return value to 1, indicating a
problem
Exit Function
End If
If Not IsEmpty(splArray(0)) Then
Select Case splArray(0)
Case 1 To 12
MsgBox "The first portion of the array appears to be
between 1 and 12, and is therefore valid."
Case Else
MsgBox "The hours entered for " & caller.Name & " Time
don't appear to be actual numbers or are not between 1 and 12. " &
vbCrLf & _
"This input only accepts numbered hours from 1 to 12.
Then use the AM/PM selector to choose the time of day." & vbCrLf & _
"Go back and try again."
NumberCheck = 1 'set return value =1, indicates a
problem
End Select
Else
MsgBox "There doesn't appear to be anything entered into the " &
caller & "."
End If
If arrayCount > 1 Then 'get array index errors if they don't
enter colon and minutes, so put this check in
If Not IsEmpty(splArray(1)) Then
Select Case splArray(0)
Case 0 To 59
MsgBox "The first portion of the array appears to be
between 0 and 59, and is therefore valid."
Case Else
MsgBox "The MINUTES entered for " & caller.Name & "
Time don't appear to be actual numbers or are not between 0 and 59. "
& vbCrLf & _
"This input only accepts numbered hours from 0 to 59.
Then use the AM/PM selector to choose the time of day." & vbCrLf & _
"Go back and try again."
NumberCheck = 1 'set return value =1, indicates a
problem
End Select
End If
End If
End Function
function I wrote. I want to pass the textbox so that I can manipulate
its properties more easily without having to worry about which textbox
I am working with. (It is some repetitive code and I am trying to be
good by creating subroutines to do things in a generic manner.)
I realize that the passed "callername" parameter in the function is
probably redundant, I just haven't taken it out yet. (It can be
replaced by using the control's .NAME property...if it worked right.
It is a bit cleaner to use "callername".)
When I debug the code the value of the passed parameter shows up as
the controls value. For example, if the textbox contains "11" the
control CALLER in the function shows as having the value of "11" and
not as the name of the text box control that I sent it.
However, if you look in the function, there is a msgbox that I build
that uses a property of the control thusly: caller.Name. In debug
mode that does have the correct value, i.e. it returns the name of the
control that I passed to the function. But it is the other attempts
to use the control that don't appear to be working: caller.value.
They don't evaluate to anything an my ISDATE check fails. The whole
purpose of this routine is to do some data validation of what was
entered into the box. I am trying to capture a time value from the
user, hours at a minimum and maybe some minutes.
There may be typos further down in the code, I noticed a few and
corrected them while pasting it into this message. But the code is
failing near the top at the IF NOT ISDATE line, so they shouldn't
matter at this point.
Here is my code for the function call:
---------------------
<...>
numChkResult = NumberCheck(txtbxEndTime, "End")
<...>
---------------------
Function NumberCheck(caller As Control, callername As String) As
Integer
Dim splArray As Variant
Dim convArr
Dim arrCallerName(2) As String
Dim callingbox As Object 'Want to be able to return to source
control
Dim arrayCount As Integer 'Don't exactly have an array.count
property, so using this instead w/ UBOUND
splArray = Split(caller.Value, ":")
If Not IsDate(caller.Value) Then
MsgBox "The value of the calling box is: " & caller.Value &
vbCrLf & _
"The calling text box, " & caller.Name & ", doesn't appear to have
a valid time in it."
NumberCheck = 1 'setting return value to 1, indicating a
problem
Exit Function
End If
arrayCount = UBound(splArray) + 1 'Just setting the variable
here to clean up the code a bit
If arrayCount > 2 Then
MsgBox "There were too many colons in the " & caller.Name & " text
box. Go back and try again."
MsgBox "Trying to set the focus back to the original text box that
made the call: " & caller.Name
NumberCheck = 1 'setting return value to 1, indicating a
problem
Exit Function
End If
If Not IsEmpty(splArray(0)) Then
Select Case splArray(0)
Case 1 To 12
MsgBox "The first portion of the array appears to be
between 1 and 12, and is therefore valid."
Case Else
MsgBox "The hours entered for " & caller.Name & " Time
don't appear to be actual numbers or are not between 1 and 12. " &
vbCrLf & _
"This input only accepts numbered hours from 1 to 12.
Then use the AM/PM selector to choose the time of day." & vbCrLf & _
"Go back and try again."
NumberCheck = 1 'set return value =1, indicates a
problem
End Select
Else
MsgBox "There doesn't appear to be anything entered into the " &
caller & "."
End If
If arrayCount > 1 Then 'get array index errors if they don't
enter colon and minutes, so put this check in
If Not IsEmpty(splArray(1)) Then
Select Case splArray(0)
Case 0 To 59
MsgBox "The first portion of the array appears to be
between 0 and 59, and is therefore valid."
Case Else
MsgBox "The MINUTES entered for " & caller.Name & "
Time don't appear to be actual numbers or are not between 0 and 59. "
& vbCrLf & _
"This input only accepts numbered hours from 0 to 59.
Then use the AM/PM selector to choose the time of day." & vbCrLf & _
"Go back and try again."
NumberCheck = 1 'set return value =1, indicates a
problem
End Select
End If
End If
End Function