View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Type Mismatch Error when calling Function

First, drop the Single's and use Double's. It'll be easier for you to remember
and you're not gaining anything with modern computers.

(Same thing with Integer's and Long's.)

So this:
Function InvalidDimensions(Hft As Single, Hins As Single, _
Wft As Single, Wins As Single, _
Optional Dft As Single, Optional Dins As Single)

becomes

Function InvalidDimensions(Hft As Double, Hins As Double, _
Wft As Double, Wins As Double, _
Optional Dft As Double, Optional Dins As Double)

And then when you call your function, convert those textbox values to doubles:

If InvalidDimensions(cdbl(tbxHeightFt), _
cdbl(tbxHeightIns), _
cdbl(tbxWidthFt), _
cdbl(tbxWidthIns)) then
....

You are checking that those textboxes are numeric first, right???




Ryan H wrote:

Why am I getting a Type Mismatch error an the line indicated below when call
the function? Thanks in advance!!!

Sub Test()

' test if dimensions are rounded to nearest 16th
Error If InvalidDimensions(tbxHeightFt, tbxHeightIns, tbxWidthFt,
tbxWidthIns) Then
MsgBox "Please round all dimensions to the nearest 1/16''.",
vbCritical
StopCode = True
Exit Sub
End If

End Sub

' ensure dimensions must be rounded to the nearest 1/16th of an inch
Function InvalidDimensions(Hft As Single, Hins As Single, _
Wft As Single, Wins As Single, _
Optional Dft As Single, Optional Dins As Single)
As Boolean

' height
If (Hft = 0 And Hins = 0) Or _
((Hft * 12 + Hins) * 16 < Int(Hft * 12 + Hins) * 16) Then
InvalidDimensions = True
Exit Function
End If

' width
If (Wft = 0 And Wins = 0) Or _
((Wft * 12 + Wins) * 16 < Int(Wft * 12 + Wins) * 16) Then
InvalidDimensions = True
Exit Function
End If

' width
If Not IsMissing(Dft) Or Not IsMissing(Dins) Then
If (Dft = 0 And Dins = 0) Or _
((Dft * 12 + Dins) * 16 < Int(Dft * 12 + Dins) * 16) Then
InvalidDimensions = True
Exit Function
End If
End If

End Function
--
Cheers,
Ryan


--

Dave Peterson