Forum Moderators: open

Message Too Old, No Replies

visual basic help

how to make a variable 2 dp

         

markharris1990

4:40 pm on Feb 25, 2009 (gmt 0)

10+ Year Member



im trying to make a virtual vending machine for my a levels and i have the machine working but all my money values are coming out as normal values and i would like them to be money values such as £1 has to be £1.00

my code so far is:

Private Sub cmdChoice_Click(Index As Integer)
Dim Choiceselect As Integer
Dim Quantity As Byte
Dim cost As Currency

Select Case Index

Case 1
Quantity = InputBox("Please enter the Quantity required", "Quantity")
If Quantity = 0 Then Exit Sub
If Quantity >= 1 <= 50 Then lblOrdered = " Item " & " Quantity " & "Cost " & vbCrLf & vbCrLf & Snackdata(1).Item & " " & Quantity & " " & Snackdata(1).cost & " "
If Quantity >= 51 Then MsgBox ("Invalid order please try again")
lblAmount = "£" & Snackdata(1).cost * Quantity

the code for the module is:

Option Explicit

'Virtual Vending Machine Program
'Main Menu form
'Author M Harris
'Date Feb 2009
'Version 1.0

Type SnackChoice

Item As String * 10
Quantity As Byte
cost As Currency
End Type

Public Snackdata(1 To 4) As SnackChoice

Public pointer As Byte

anyone help ?

darrenG

12:54 pm on Feb 27, 2009 (gmt 0)

10+ Year Member



Try:

Public Function SingleToCurrency(sngValue as Single) as String
Return String.Format("&pound;{0}", Math.Round(sngValue, 2))
End Function

(not tested)

carguy84

2:25 pm on Feb 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



VB has a FormatCurrency function - sounds like what you're looking for.