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 / July 2007

Tip: Looking for answers? Try searching our database.

Textbox Value, Calculations, and Display with Decimals

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shane - 30 Jul 2007 05:38 GMT
Hi.

I want to have a userform that collects a whole dollar value.  A
calculation is carried out using that whole dollar value then the
result are put into bookmarks.

The calculations are fine except I can't get the trailing .00 to
appear in the original dollar amount.  I've tried the format()
function without any joy.  Also I need to get the results of
calculations showing the cents.

I don't want to use Excel.

While still a rough WIP, I've pasted my code below.

'##################################
' Declare variables
'
Dim vGST As Currency          ' I've tried single
Dim vAmount As Currency
Dim vTotal As Currency
Dim vBalance As Currency

'  format (or try to the tbAmount value
'
vAmount = Format(tbAmount.Text, "###0.00")

'  Calculate the tax and total due
'
vGST = Round(vAmount * 0.1, 2)
vTotal = Round(vAmount + vGST, 2)

'  Format to show whole cents
'
vGST = Format(vGST, "###0.00")
vTotal = Format(vTotal, "###0.00")

'   Put the form data into the Bookmarks
'  I'd normally use a separate UpdateBookmark() function but
'  this is for simplicity at this stage.
'
ActiveDocument.Bookmarks("Amount").Range.Text = vAmount
ActiveDocument.Bookmarks("GST").Range.Text = vGST
ActiveDocument.Bookmarks("Total").Range.Text = vTotal
ActiveDocument.Bookmarks("InvDate").Range.Text = tbInvDate.Text
ActiveDocument.Bookmarks("InvNo").Range.Text = tbInvNumber.Text
ActiveDocument.Bookmarks("Details").Range.Text = tbInvDetails.Text

'###########################################

Using a message box, vAmount show ony the whole dollar amount as
originally entered into the textbox.
vGST does not show the trailing 0 in the cents as does(n't) vTotal.
They do show the first decimal value i.e. 123.5

All assistance greatly appreciated as is constructive criticism of my
code.

Cheers
Shane
Doug Robbins - Word MVP - 30 Jul 2007 06:30 GMT
The format function returns a string.  There is no need to be using it until
you actually insert the values into the document

ActiveDocument.Bookmarks("Amount").Range.Text = Format(vAmount, "#,##0.00")

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi.
>
[quoted text clipped - 56 lines]
> Cheers
> Shane
Shane - 31 Jul 2007 00:41 GMT
>The format function returns a string.  There is no need to be using it until
>you actually insert the values into the document
>
>ActiveDocument.Bookmarks("Amount").Range.Text = Format(vAmount, "#,##0.00")

Thanks Doug.  That worked fine.

Cheers

Rate this thread:






 
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.