goldfingerpunk
asked on
need help figuring out the coding
Hi
I need to figure out how to code for a assignment and I'm confused I'm making a restaruant bill and I have to figure out when I click the add item button how to get the quantity, menu item and price over to the 3 matching listbox and what they should be dimed as also then I have to calculate the total of the items in the three lists box and get the total to a total text box. I wpuld really appriciate any help.
I need to figure out how to code for a assignment and I'm confused I'm making a restaruant bill and I have to figure out when I click the add item button how to get the quantity, menu item and price over to the 3 matching listbox and what they should be dimed as also then I have to calculate the total of the items in the three lists box and get the total to a total text box. I wpuld really appriciate any help.
In addition to posting any code...please tell us what types of controls you've chosen to use and how they are setup in your GUI. A labeled screenshot would be helpful...
ASKER
ok well what do i dim menu items as cause its not an integer and am i suppose to dim the total as double cause that is what i did so far
That really depends on HOW you are going to present the menu to the user.
Are you going to give them CheckBoxes, RadioButtons, a ListBox?...or are they going to enter a menu item number into a TextBox?
How many items are we talking here?...are there any specifics in the assignment that dictate what controls must be used?
Are you going to give them CheckBoxes, RadioButtons, a ListBox?...or are they going to enter a menu item number into a TextBox?
How many items are we talking here?...are there any specifics in the assignment that dictate what controls must be used?
ASKER
no i basically building it from scratch there are the items: quantity (which is how much of each item they want) i was guessing that was an integer then there is menu item and this one im not sure on because its text not a number so i dont know what to dim that as and then there is the price which i assumed is dimed as decimal and total which i wanna say is dimed as double. And i just figured out how to get the quantity, menu item and price to there individual list box so im moving on to the add total button. This is where i get confused on how to dim what and what goes in the loop. Oh btw thanks for not just giving me the code it helped figuring out the first part with the add button now come the tough part for me at least though
"And i just figured out how to get the quantity, menu item and price to there individual list box so im moving on to the add total button."
Ok...so it sounds like you three individual ListBoxes: quantity, item, price
(and corresponding rows from the ListBoxes constitute a "record")
I assume you have STRINGS in those ListBoxes right now?
Ok...so it sounds like you three individual ListBoxes: quantity, item, price
(and corresponding rows from the ListBoxes constitute a "record")
I assume you have STRINGS in those ListBoxes right now?
ASKER
this is how i dimed everything so far and i dont think its all right most of it i think is but here is what i got
Dim quantity As Integer = 0
Dim item As Object = (MenuItemTextBox.Text)
Dim price As Decimal = 0
Dim total As Double = 0
Dim quantity As Integer = 0
Dim item As Object = (MenuItemTextBox.Text)
Dim price As Decimal = 0
Dim total As Double = 0
When you added those items to the ListBoxes...did you simply add the .Text() property value directly from the TextBoxes?
ASKER
I get this error message with the line:quantity = QuantityListBox.Items.Item (QuantityL istBox.Tex t)
Conversion from string "" to type 'Integer' is not valid.
Here is what i have coded so far
Dim quantity As Integer = 0
Dim item As Object = (MenuItemTextBox.Text)
Dim price As Decimal = 0
Dim total As Double = 0
Do
quantity = QuantityListBox.Items.Item (QuantityL istBox.Tex t)
price = PriceListBox.Items.Item(Pr iceListBox .Text)
total = price * quantity
Loop Until price And quantity = PriceListBox.Items.Count And QuantityListBox.Items.Coun t
total = price * quantity
TotalLabel.Text = String.Format("{0:F}", total)
QuantityTextBox.Focus()
End Sub 'totalbutton_click
End Class
Conversion from string "" to type 'Integer' is not valid.
Here is what i have coded so far
Dim quantity As Integer = 0
Dim item As Object = (MenuItemTextBox.Text)
Dim price As Decimal = 0
Dim total As Double = 0
Do
quantity = QuantityListBox.Items.Item
price = PriceListBox.Items.Item(Pr
total = price * quantity
Loop Until price And quantity = PriceListBox.Items.Count And QuantityListBox.Items.Coun
total = price * quantity
TotalLabel.Text = String.Format("{0:F}", total)
QuantityTextBox.Focus()
End Sub 'totalbutton_click
End Class
ASKER
yeah what i did when i added the items to the list boxes was
'clear previous information
If TotalLabel.Text <> "" Then
TotalLabel.Text = ""
QuantityListBox.Items.Clea r()
MenuItemListBox.Items.Clea r()
PriceListBox.Items.Clear()
End If
'display information in list box
QuantityListBox.Items.Add( Val(Quanti tyTextBox. Text))
MenuItemListBox.Items.Add( MenuItemTe xtBox.Text )
PriceListBox.Items.Add(Pri ceTextBox. Text)
QuantityTextBox.Clear()
MenuItemTextBox.Clear()
PriceTextBox.Clear()
QuantityTextBox.Focus()
'clear previous information
If TotalLabel.Text <> "" Then
TotalLabel.Text = ""
QuantityListBox.Items.Clea
MenuItemListBox.Items.Clea
PriceListBox.Items.Clear()
End If
'display information in list box
QuantityListBox.Items.Add(
MenuItemListBox.Items.Add(
PriceListBox.Items.Add(Pri
QuantityTextBox.Clear()
MenuItemTextBox.Clear()
PriceTextBox.Clear()
QuantityTextBox.Focus()
ASKER
and this is frustrating as hell because i cant get the total into the total text box
ASKER
i need help anyone
You are clearing out the ListBoxes every time? Why have ListBoxes then if you're only going to have one thing?...
Let's start with adding new items. The first thing you should do is validate the textboxes to ensure valid data has been entered. Obviously the menu item is just a string so for that you'd just need to make sure it is not blank. For the quantity, an integer greater than zero would be required. Finally, for the price, a valid decimal value greater than zero would be good.
If all three values pass then you simply add them to their respective boxes.
For example, here is how to make sure that an Integer greater than zero has been entered into TextBox1:
Let's start with adding new items. The first thing you should do is validate the textboxes to ensure valid data has been entered. Obviously the menu item is just a string so for that you'd just need to make sure it is not blank. For the quantity, an integer greater than zero would be required. Finally, for the price, a valid decimal value greater than zero would be good.
If all three values pass then you simply add them to their respective boxes.
For example, here is how to make sure that an Integer greater than zero has been entered into TextBox1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim value As Integer
If Integer.TryParse(TextBox1.Text, value) AndAlso value > 0 Then
' ... do something with "value" in here ...
Else
MessageBox.Show("Please enter an integer greater than zero.")
End If
End Sub
ASKER
the adding the items to the listbox is working fine it adds as many as i want to i did test that out
Ok...assuming you have valid quantity and price values in your ListBoxes, you could compute the total like this:
Private Sub CalculateTotal()
Dim Total As Decimal = 0
Dim quantity As Integer
Dim price As Decimal
Dim subTotal As Decimal
For i As Integer = 0 To QuantityListBox.Items.Count - 1
quantity = CInt(QuantityListBox.Items(i))
price = CDec(PriceListBox.Items(i))
subTotal = quantity * price
Total = Total + subTotal
Next
TotalLabel.Text = "Total: " & Total.ToString("C")
End Sub
ASKER
ok that worked but what does the i stand for
>> ok that worked but what does the i stand for
Think of it in this manner and tell us what you think "i" stands for:
What is "i" in the latter statement?
Think of it in this manner and tell us what you think "i" stands for:
Saying, "For i As Integer" is similar to saying, "Dim i As Integer."
What is "i" in the latter statement?
ASKER
there is just one more part my teacher added and its the error check part. Its if one or more text boxes are empty display error message (when the add item button is clicked) and do not display anything in the list boxes so far what i have is
If QuantityTextBox.Text = "" Or MenuItemTextBox.Text = "" Or PriceTextBox.Text = "" Then
MsgBox("Information is missing in one or more text boxes!")
QuantityListBox.Items.Add( Val(Quanti tyTextBox. Text)) = False
but the quantitylistbox line is underlined in blue so im doing something wrong ive never had to make something not make something happen in this program yet.
If QuantityTextBox.Text = "" Or MenuItemTextBox.Text = "" Or PriceTextBox.Text = "" Then
MsgBox("Information is missing in one or more text boxes!")
QuantityListBox.Items.Add(
but the quantitylistbox line is underlined in blue so im doing something wrong ive never had to make something not make something happen in this program yet.
ASKER
would it be (i) would be the text
>> would it be (i) would be the text
Time for a lesson in syntax = )
.NET has the concept of collections, which you can think of as super-charged arrays. Collections can indexed (individual slots accessed) much the same way arrays can. VB uses parentheses as the indexing operator. You may have confused this for a function call--one of VB's shortcomings for new developers. In this case, QuantityListBox.Items is a collection and in the code Idle_Mind posted it is being indexed. "i" is just the variable being used to hold the value of the index you want to inspect at that point in time when the code is being executed. If you erased "i" and put "1", then you would be accessing the 2nd slot of the QuantityListBox.Items collection. Since you are in a loop, "i" is being used to access successive slots of QuantityListBox.Items.
What Idle_Mind's code is doing at that line is converting the value at item index "i" in QuantityListBox.Items and converting that string into an integer.
Time for a lesson in syntax = )
.NET has the concept of collections, which you can think of as super-charged arrays. Collections can indexed (individual slots accessed) much the same way arrays can. VB uses parentheses as the indexing operator. You may have confused this for a function call--one of VB's shortcomings for new developers. In this case, QuantityListBox.Items is a collection and in the code Idle_Mind posted it is being indexed. "i" is just the variable being used to hold the value of the index you want to inspect at that point in time when the code is being executed. If you erased "i" and put "1", then you would be accessing the 2nd slot of the QuantityListBox.Items collection. Since you are in a loop, "i" is being used to access successive slots of QuantityListBox.Items.
What Idle_Mind's code is doing at that line is converting the value at item index "i" in QuantityListBox.Items and converting that string into an integer.
>> but the quantitylistbox line is underlined in blue so im doing something wrong
Take a look at what you're doing:
What this code *appears* to do is add the string found in QuantityTextBox to the QuantityListBox, BUT, it is also trying to assign the value of "False" to the object returned by Add(). However, Add() returns an INTEGER so trying to assign False doesn't make sense.
Take a look at what you're doing:
QuantityListBox.Items.Add(Val(QuantityTextBox.Text)) = False
What this code *appears* to do is add the string found in QuantityTextBox to the QuantityListBox, BUT, it is also trying to assign the value of "False" to the object returned by Add(). However, Add() returns an INTEGER so trying to assign False doesn't make sense.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you post any code you've started?