Converting string to Double?

  • Thread starter Thread starter J
  • Start date Start date
J

J

Hi

I'm just trying to convert a small program that was written in VB6 to
VB.Net.

I'm stumbling at the first hurdle!

In VB I could do the following (ensuring that the textbox only contained
numeric input of course)...

Dim MyNumber as Double
MyNumber = CDbl(MyNumericTextString.text)

and that would work fine.

Vb.Net won't let me do the above. What do I use instead????
 
J said:
Hi

I'm just trying to convert a small program that was written in VB6
to VB.Net.

I'm stumbling at the first hurdle!

In VB I could do the following (ensuring that the textbox only
contained numeric input of course)...

Dim MyNumber as Double
MyNumber = CDbl(MyNumericTextString.text)

and that would work fine.

Vb.Net won't let me do the above.

Why? Error message? What is the value of MyNumericTextString.text? What is
the current culture setting? The input format must be compliant to the
current culture settings for numeric inputs.

What do I use instead????

If MyNumericTextString is a textbox containing "12345", it does work here.


Armin
 
J said:
Hi

I'm just trying to convert a small program that was written in VB6 to
VB.Net.

I'm stumbling at the first hurdle!

In VB I could do the following (ensuring that the textbox only contained
numeric input of course)...

Dim MyNumber as Double
MyNumber = CDbl(MyNumericTextString.text)

and that would work fine.

Vb.Net won't let me do the above. What do I use instead????

Strange, your example works without a problem for me (VB Express 2005). I
assume that .text is an email-typo, should be .Text, but normally the
program would make the change automatically if you type .text.
Precisely "what" does not work when you use your program?

Jaap
 
Ahhh.. On further investigation it only errors if the textbox contains a
null string, and obviously it can't convert that to a double. This was
obviously a fault that was in the original program as well. I've error
trapped it now and everything seems fine, sorry for that.
J
 
J,

Those things you can test in the way as Armin and Jaap wrote.

Just

Dim myDouble as Double = CDbl("12345")

Cor
 
Charles,

Hi glad to see you, had to think lately about you, not for the last because
I have send some samples of that JScript from you.

Why not use that so nice CDbl from VB.Net, it is something I really miss in
C#.

(I can make it of course but that is for me not documentative)

Cor
 
Hi Cor

I've been off in the wilderness, updating a VB6 application for a client,
for much longer than I would have liked. But I'm back at last, so I'm
revisiting some of my old haunts.

Good to hear from you.

Charles
 
Charles,

Now I see your message, it was not that javascrip.

I was explaining somebody about the Queue class. Now I hear that you are
back in civilisation that quarter felt in the right place.

(Although we don't have a quarter anymore here in Holland).

:-)

Cor
 
Cor said:
Why not use that so nice CDbl from VB.Net, it is something I really
miss in C#.

You could always add a reference to Microsoft.VisualBasic from your C#
project, then you can use all the nice ol' VB functions such as this in your
C# project without needing to rewrite them..?
 
Back
Top