Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

On more Q! Why can't I calculate with decimals???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Guus van Waardenburg - 04 May 2006 14:49 GMT
Hi all,

Another problem I can't solve singlehandedly...

When I fill in digits in textboxes, want to calculate them and put the
outcome in a label the outcome always round up to an integer digit...
Even when I set the format of the txtbxs and the label so it wil show
decimals, the decimals always stay at 0.

Example:
txtbox1 = 13,23
txtbox2 = 1,00
lable1 should be 14,23 offcourse but
label1 = 14,00

Can anyone help me?
Guus van Waardenburg - 04 May 2006 15:13 GMT
Here is an example of my code, lightly changed, since it contains some dutch...

   Dim i As Currency
       i = textbox1.Value * textbox2.Value \ 1000
      If textbox1.Value = True Then
           If textbox1.Value = False Then
           label1.Caption = False
           Else
           label1.Caption = i
           End If
       Else
           label1.Caption = False
       End If

> Hi all,
>
[quoted text clipped - 12 lines]
>
> Can anyone help me?
Er - 04 May 2006 18:46 GMT
> Here is an example of my code, lightly changed, since it contains some
> dutch...
>
>    Dim i As Currency
>        i = textbox1.Value * textbox2.Value \ 1000

I am no expert, but shouldn't this read:

  i = textbox1.Value * textbox2.Value / 1000

The '\' rounds off the results to a whole number, with MOD giving the
remainder.

Erwin
Helmut Weber - 04 May 2006 20:14 GMT
Hi Guus,

apart from datatype conversion issues,
this will hardly make sense:

> If textbox1.Value = True Then
>     If textbox1.Value = False Then

Depending on regional settings
on how to display numbers,
you have to be very careful,
when converting strings to doubles or singles.

Whereas the surface of windows
may use the international settings,
the VBA-code doesn't.

When you convert a string to a single,
the VBA-code expects a string like "1000.14".
So you have to remove possible 1000s seperators,
and to make sure, that the decimal seperator is a period (.)

If I had to create a userform, which should accept decimal fractions,
i would use _two_ textboxes. One for the whole number,
one for the fractions:
like [xxxxx],[xxxxxx] on the european continent.

And as input I would allow nothing but digits.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Guus van Waardenburg - 05 May 2006 08:12 GMT
Thank you Guys,

Ik know I have to work on the functionality of my code! It's my first one.

I flipped the slash and indeed it works out fine.

The program works fine now. Now for stripping the code to functionality...

Best regards.

> Hi Guus,
>
[quoted text clipped - 24 lines]
>
> And as input I would allow nothing but digits.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.