Textbox.Value to Double won't work

M

Marc from Belgium

Hi,

I have a form with a textbox where you can put in a number (or somthing
else). I want to convert the textboxvalue to a double. I use somthing like
this but it won't work.

on error resume next
LocalDbl = CDbl(StupidTextBox.Value)
if err.Number = not 0 then LocalDbl = 0
....

The types doen't match.
I don't understand what I'm doeing wrong.

Please give me a hint.

Thanks,
Marc From Belgium
 
B

Bear

Marc:

I tried this out on a selection object. If the selection is text, I get a
type mismatch. You may have to verify that the user's input is numeric to
begin with.

Also, is LocalDbl dimensioned as a double?

Bear
 
H

Helmut Weber

Hi Marc,

how about this one:

Private Sub CommandButton1_Click()
Dim d As Double
On Error Resume Next
d = CDbl(TextBox1.Value)
If Err Then
d = 0
Err = 0
End If
MsgBox d
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

Marc from Belgium

Thanks Helmut,

That's my code! But it don't work!
I thought with the error resume next I could filter out the not-numbers.
But I still get the type mistake.

I just don't understand what I'm doing wrong.

THanks,
Marc From Belgium
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
M

Marc from Belgium

Dear Great Bear :) ,

First: LocalDbl is dimensioned as a double.

Second: How can I check if it is a number? I thought that the Error resume
next could fix that but it don't.

Could it be that a setting of the TextBox is getting me in trouble?

Thanks,
Marc From Belgium
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
H

Helmut Weber

Hi Marc,

I'm really puzzled.
Here and now, whatever text there is in the textbox,
i can't get a not trapped error.

####34´ß6 -> 0
§$%§&$§&%$§& -> 0

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

Marc from Belgium

Hi Helmut,

I solved it!

I had set the error handler in the option menu to stop at all errors. And so
it did! Just by changing it back to the default to stop at unsolved errors it
works fine.

Thanks for your help. It made me think that it wasn't the code but the
settings.

Marc From Belgium
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top