Group:  Microsoft Word ยป microsoft.public.word.vba.userforms
Thread: How to make a text field numeric

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

How to make a text field numeric
"Bruce Stradling" <bstradling[ at ]cox.net> 18.07.2006 13:13:18
I wanted to calculate a text field based on the falues of 3 other text
fileds.

The problem arose that when I did this:

FieldA.Value=800.00
FieldB.Value=200.00
FieldA.Value=.00
FieldD.Value = FormatNumber(FieldA.Value + FieldB.Value + FieldB.Value, 2)

I got a text value of 800.00200.00.00

How do I define a numeric field in a userform instead of using a text field?


Re: How to make a text field numeric
"Jean-Guy Marcil" <NoSpam[ at ]LeaveMeAlone> 18.07.2006 13:37:52
Bruce Stradling was telling us:
Bruce Stradling nous racontait que :

[Quoted Text]
> I wanted to calculate a text field based on the falues of 3 other text
> fileds.
>
> The problem arose that when I did this:
>
> FieldA.Value=800.00
> FieldB.Value=200.00
> FieldA.Value=.00
> FieldD.Value = FormatNumber(FieldA.Value + FieldB.Value +
> FieldB.Value, 2)
> I got a text value of 800.00200.00.00
>
> How do I define a numeric field in a userform instead of using a text
> field?

You are concatenating strings with your code. You know that FieldA.Value is
in fact a number, but as far as the compiler is concerned, it is a string.

It is always better to do your own data-conversion in your code then to let
the compiler do it for you...

Try something like:

FieldD.Value = CStr(FormatNumber(Val(FieldA.Value) + _
Val(FieldB.Value) + Val(FieldC.Value), 2))


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE[ at ]CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Re: How to make a text field numeric
"Bruce Stradling" <bstradling[ at ]cox.net> 18.07.2006 13:59:48
Thanks


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net