Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox or Label that shows $ value 2

Status
Not open for further replies.

homesick

Programmer
Dec 5, 2001
55
CA
How do i default a textbox and or Label to show a $ value when a calculation is perofmed? Curretn;y just the number appears but i want it to be shown in dollars. Can anyone suggest anything?
 
Use the Format() function when setting the value of the textbox.

An alternate solution is a masked edit box instead of a textbox. I tend to avoid these, however.
 
It formats it ok.....but now it won't sum the textbox amounts into my label......
here is part my code.....any suggestions?


Private Sub Command22_Click()

Text1.Text = TotalColumn(MSFlexGrid1, 12)

Dim amount As Single
amount = Text1.Text
Text1.Text = Format(amount, "currency")

End Sub
Private Function TotalColumn(grid As MSFlexGrid, ByVal ColIndex As Long) As Long
Dim R As Long
Dim Total As Long

For R = 0 To grid.Rows - 1
If IsNumeric(grid.TextMatrix(R, ColIndex)) Then
Total = Total + (grid.TextMatrix(R, ColIndex))
End If
Next R

TotalColumn = Total

End Function


Private Sub Command23_Click()
Text7.Text = TotalColumn(MSFlexGrid1, 9)

Dim amount As Single
amount = Text7.Text
Text7.Text = Format(amount, "currency")
End Sub

Private Sub Command24_Click()

Dim first, second, third, fourth 'declare variables

first = Val(Text1.Text)
second = Val(Text3.Text)
third = Val(Text4.Text)
fourth = Val(Text7.Text)

Label1.Caption = first + second + third + fourth

Dim amount As Single
amount = Label1.Caption
Label1.Caption = Format(amount, "currency")


End Sub
 
I havn't worked with basic in a while, but 3 things;

1: Try useing "as integer" instead of "as single", since you're going to have a decimal ammount.

2: it's good practice to declare all variables useing the "as" conjunction (eg. dim first as integer)

3: I would recomend not formating the text fields until after makeing the sum calculation.

Hope this helps,
Rob
 
You have a lot more lines of code for each step than is necessary. For example:

Text1.Text = TotalColumn(MSFlexGrid1, 12)
Dim amount As Single
amount = Text1.Text
Text1.Text = Format(amount, "currency")

instead of...

Text1.Text = FormatCurrency(TotalColumn(MSFlexGrid1, 12))
 
convert your data value when sum. That's what I would do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top