Help w/ coding

This is a "Vending Machine" project for a VB intro class. This code below I have came up with is not working for me. When I run my program a message box should appear and state what has been purchased with the total price. Currently I have 6 items in the lstMenu that the user can select from. What am I doing wrong!?!?!?! Thank for Helping!


Dim IntTotal As Integer
Dim IntCnt As Integer
Dim IntPos As Integer
Dim StrPrice As String
Dim IntValue As Integer

If lstMenu.Selected(0) Then
For IntCnt = 0 To 5
IntPos = InStr(lstMenu.Selected(IntCnt), "$")
StrPrice = Mid$(lstMenu.Selected(IntCnt), IntPos, Len (lstMenu.Selected(IntCnt)))
IntValue = Val(StrPrice)
IntTotal = IntTotal + IntValue
Next IntCnt

MsgBox "You have purchased" & vbCrLf & IntTotal & "." & vbCrLf & "The total is " & Format$(Total, "Currency") & "."




Comments

  • : This is a "Vending Machine" project for a VB intro class. This code below I have came up with is not working for me. When I run my program a message box should appear and state what has been purchased with the total price. Currently I have 6 items in the lstMenu that the user can select from. What am I doing wrong!?!?!?! Thank for Helping!
    :
    :
    : Dim IntTotal As Integer
    : Dim IntCnt As Integer
    : Dim IntPos As Integer
    : Dim StrPrice As String
    : Dim IntValue As Integer
    :
    : If lstMenu.Selected(0) Then
    : For IntCnt = 0 To 5
    : IntPos = InStr(lstMenu.Selected(IntCnt), "$")
    : StrPrice = Mid$(lstMenu.Selected(IntCnt), IntPos, Len (lstMenu.Selected(IntCnt)))
    : IntValue = Val(StrPrice)
    : IntTotal = IntTotal + IntValue
    : Next IntCnt
    :
    : MsgBox "You have purchased" & vbCrLf & IntTotal & "." & vbCrLf & "The total is " & Format$(Total, "Currency") & "."
    :
    :
    :
    :
    :


    This should work if you want only 2 be able 2 buy 1 thing at a time.
    It works best wt comboboxes.
    You'll have 2 call the function, you can do this wt this code;
    "Call BuyIt()"
    [code]
    dim MyMoney as currency '<<<This is in General declarations
    dim ThePrice(9) as currency 'the prices of the various things
    dim TheName(9) as string
    private function BuyIt()
    dim MySel as integer
    MySel = lstMenu.listindex
    if mymoney > theprice(mysel) then
    mymoney = mymoney - theprice(mysel)
    msgbox "You just bought a " & thename(mysel) & " for $" & _
    theprice(mysel) & "."
    else
    msgbox "You do not have enough money!" & vbCrLf & "You only have $" & _
    mymoney & ", and you need $" & theprice(mysel) & "!"
    end if
    end function
    [/code]

    Hope this helps.
    [b][red]Dragon[/red][purple]storM[/purple][/b]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion