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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Question - Format in a Label

Status
Not open for further replies.

Milin

Technical User
Jan 5, 2000
33
US
I am trying to currency format a label field (the final calculated result--LblEI.Caption) in a small calculator program I have written. I keep going over and over solutions in my books to try to make this label format the result as currency. The closest I can get it is below -- I really want the format as $###,### Can someone give me what I'm sure is an easy solution? Is it because my variables are not formatted correctly?<br>
Thanks so much!<br>
<br>
Private Sub BtnCalc_Click()<br>
<br>
Dim Vara 'Attendance entry<br>
Dim Varprc 'Peak Room Count entry<br>
Dim EI 'EI if Attendance and PRC are equal<br>
<br>
'declare variables<br>
Vara = Val(TxtAttend.Text) 'Attendance<br>
Varprc = Val(TxtPRC.Text) ' Peak Room Count<br>
EI = Vara * 1.451<br>
<br>
If (Vara = Varprc) Then<br>
LblEI.Caption = EI<br>
LblEI.Caption = Format(EI, &quot;$###,###.000&quot;)<br>
<br>
Else: Call BookingFormula1<br>
End If<br>
' If attendance and Peak Room Count are equal,<br>
' there is a straight calculation -- the EI variable.<br>
' If the values are not equal, BookingFormula1 is called<br>
End Sub<br>
<br>
<br>
Private Sub BookingFormula1()<br>
Dim Vara ' Attendance from above<br>
Dim Varprc& 'Peak Room Count from above<br>
Dim XPrv ' adjusted Peak Room Count<br>
Vara = Val(TxtAttend.Text) 'Attendance<br>
Varprc = Val(TxtPRC.Text) 'Peak Room COunt<br>
XPrv = Varprc * 1.8 'Adjusted Peak Room Count<br>
<br>
If XPrv &lt; Vara Then<br>
LblEI.Caption = XPrv * 1.451<br>
LblEI.Caption = Format(XPrv, &quot;$###,###.000&quot;)<br>
Else: LblEI.Caption = Vara * 1.451<br>
LblEI.Caption = Format(Vara, &quot;$###,###.000&quot;)<br>
End If<br>
<br>
' if the Adjusted peak room count is less than Attendance<br>
' then multiply aprc x 1.451 else, muliply attendance x 1.451<br>
<br>
End Sub<br>
<br>
<br>

 
milin,<br>
Try this:<br>
<br>
Private Sub BtnCalc_Click()<br>
<br>
Dim Vara 'Attendance entry<br>
Dim Varprc 'Peak Room Count entry<br>
Dim EI 'EI if Attendance and PRC are equal<br>
<br>
'declare variables<br>
Vara = Val(TxtAttend.Text) 'Attendance<br>
Varprc = Val(TxtPRC.Text) ' Peak Room Count<br>
EI = Vara * 1.451<br>
<br>
If (Vara = Varprc) Then<br>
LblEI.Caption = FormatCurrency(EI, 0) 'zero dec places<br>
<br>
Else: Call BookingFormula1<br>
End If<br>
' If attendance and Peak Room Count are equal,<br>
' there is a straight calculation -- the EI variable.<br>
' If the values are not equal, BookingFormula1 is called<br>
End Sub<br>
<br>
<br>
Private Sub BookingFormula1()<br>
Dim Vara ' Attendance from above<br>
Dim Varprc& 'Peak Room Count from above<br>
Dim XPrv ' adjusted Peak Room Count<br>
Vara = Val(TxtAttend.Text) 'Attendance<br>
Varprc = Val(TxtPRC.Text) 'Peak Room COunt<br>
XPrv = Varprc * 1.8 'Adjusted Peak Room Count<br>
<br>
If XPrv &lt; Vara Then<br>
XPrv = XPrv * 1.451<br>
LblEI.Caption = FormatCurrency(XPrv, 0)<br>
Else: Vara = Vara * 1.451<br>
LblEI.Caption = FormatCurrency(Vara, 0)<br>
End If<br>
<br>
' if the Adjusted peak room count is less than Attendance<br>
' then multiply aprc x 1.451 else, muliply attendance x 1.451<br>
<br>
End Sub<br>
<br>
<br>
<br>

 
any time you output to the label <br>
<br>
Label1.Caption = format(LocalVar, &quot;currency&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top