JeffCorkern
New Member
- Joined
- Jul 8, 2012
- Messages
- 14
The following statement crashes with a "Type mismatch" error in a userform event-handler:
CDbl(DOTextbox.Value)
I can't find out why it's crashing. Msgbox TypeName(DOTextbox.Value) returns "String." MsgBox CDbl(DOTextbox.Value) also crashes with a "Type mismatch" error. The general help just says CDbl(expression) but doesn't specify what the "expression" has to be. It also doesn't list what error CDbl returns when it's unable to convert "expression".
(Excel 2010 VBA no longer has highly specific context-specific help and simply kicks you to a Web page where you wander around a lot and maybe you find the answer but mostly you don't. I find this EXTREMELY aggravating.)
Here's the code, for what it's worth. The CStr is me trying to beat VBA into submission. It's not working. It's crashing on the Select Case Statement.
Private Sub OKButton_Click()
Select Case CDbl(CStr(DOTextBox.Value)) <> 0 And CDbl(CStr(TemperatureTextBox.Value)) <> 0
Case True
ActiveCell.Value = CDbl(DOTextBox.Value)
ActiveCell.Offset(0, 3).Value = ActiveCell.Offset(0, 3).Value & " " & CDbl(TemperatureTextBox.Value) & "C"
Case False
If CDec(DOTextBox.Value) = 0 Then
MsgBox DOTextBox.Value & " is not a number. Please enter a number."
DOTextBox.SetFocus
End If
If CDec(TemperatureTextBox.Value) = 0 Then
MsgBox TemperatureTextBox.Value & " is not a number. Please enter a number."
TemperatureTextBox.SetFocus
End If
End Select
End Sub
CDbl(DOTextbox.Value)
I can't find out why it's crashing. Msgbox TypeName(DOTextbox.Value) returns "String." MsgBox CDbl(DOTextbox.Value) also crashes with a "Type mismatch" error. The general help just says CDbl(expression) but doesn't specify what the "expression" has to be. It also doesn't list what error CDbl returns when it's unable to convert "expression".
(Excel 2010 VBA no longer has highly specific context-specific help and simply kicks you to a Web page where you wander around a lot and maybe you find the answer but mostly you don't. I find this EXTREMELY aggravating.)
Here's the code, for what it's worth. The CStr is me trying to beat VBA into submission. It's not working. It's crashing on the Select Case Statement.
Private Sub OKButton_Click()
Select Case CDbl(CStr(DOTextBox.Value)) <> 0 And CDbl(CStr(TemperatureTextBox.Value)) <> 0
Case True
ActiveCell.Value = CDbl(DOTextBox.Value)
ActiveCell.Offset(0, 3).Value = ActiveCell.Offset(0, 3).Value & " " & CDbl(TemperatureTextBox.Value) & "C"
Case False
If CDec(DOTextBox.Value) = 0 Then
MsgBox DOTextBox.Value & " is not a number. Please enter a number."
DOTextBox.SetFocus
End If
If CDec(TemperatureTextBox.Value) = 0 Then
MsgBox TemperatureTextBox.Value & " is not a number. Please enter a number."
TemperatureTextBox.SetFocus
End If
End Select
End Sub