Solved

need help figuring out the coding

Posted on 2011-03-17
22
268 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:goldfingerpunk
  • 11
  • 7
  • 4
22 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35159824
We are not allowed to provide you with specific answers (nor should you be seeking such) due to academic integrity. We can, however, point out where you may be going astray or give you an idea why an approach may/may not work.

Can you post any code you've started?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35159871
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...
0
 

Author Comment

by:goldfingerpunk
ID: 35160315
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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35160436
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?
0
 

Author Comment

by:goldfingerpunk
ID: 35160538
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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35160573
"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?
0
 

Author Comment

by:goldfingerpunk
ID: 35160583
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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35160600
When you added those items to the ListBoxes...did you simply add the .Text() property value directly from the TextBoxes?
0
 

Author Comment

by:goldfingerpunk
ID: 35160768
I get this error message with the line:quantity = QuantityListBox.Items.Item(QuantityListBox.Text)
   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(QuantityListBox.Text)
            price = PriceListBox.Items.Item(PriceListBox.Text)
            total = price * quantity
        Loop Until price And quantity = PriceListBox.Items.Count And QuantityListBox.Items.Count


        total = price * quantity
        TotalLabel.Text = String.Format("{0:F}", total)
        QuantityTextBox.Focus()



    End Sub 'totalbutton_click
End Class
0
 

Author Comment

by:goldfingerpunk
ID: 35160787
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.Clear()
            MenuItemListBox.Items.Clear()
            PriceListBox.Items.Clear()
        End If

        'display information in list box
        QuantityListBox.Items.Add(Val(QuantityTextBox.Text))
        MenuItemListBox.Items.Add(MenuItemTextBox.Text)
        PriceListBox.Items.Add(PriceTextBox.Text)
        QuantityTextBox.Clear()
        MenuItemTextBox.Clear()
        PriceTextBox.Clear()
        QuantityTextBox.Focus()
0
 

Author Comment

by:goldfingerpunk
ID: 35160875
and this is frustrating as hell because i cant get the total into the total text box
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:goldfingerpunk
ID: 35161086
i need help anyone
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35161132
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:
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

Open in new window

0
 

Author Comment

by:goldfingerpunk
ID: 35161184
the adding the items to the listbox is working fine it adds as many as i want to i did test that out
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35161207
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

Open in new window

0
 

Author Comment

by:goldfingerpunk
ID: 35161283
ok that worked but what does the i stand for
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35161353
>>  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:

Saying, "For i As Integer" is similar to saying, "Dim i As Integer."

What is "i" in the latter statement?
0
 

Author Comment

by:goldfingerpunk
ID: 35161389
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(QuantityTextBox.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.
0
 

Author Comment

by:goldfingerpunk
ID: 35161397
would it be (i) would be the text
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35161576
>>  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.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35161640
>>  but the quantitylistbox line is underlined in blue so im doing something wrong

Take a look at what you're doing:

QuantityListBox.Items.Add(Val(QuantityTextBox.Text)) = False

Open in new window


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.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35161873
This is basically the same thing as I posted previously back here:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26894525.html#35161132

...but nested together to handle all three inputs from the user:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim quantity As Integer
        Dim price As Decimal

        If Integer.TryParse(QuantityTextBox.Text, quantity) AndAlso quantity > 0 Then
            If MenuItemTextBox.Text.Trim <> "" Then
                If Decimal.TryParse(PriceTextBox.Text, price) AndAlso price > 0 Then
                    QuantityListBox.Items.Add(quantity)
                    MenuItemListBox.Items.Add(MenuItemTextBox.Text)
                    PriceListBox.Items.Add(price)

                    QuantityTextBox.Clear()
                    MenuItemTextBox.Clear()
                    PriceTextBox.Clear()

                    CalculateTotal()

                    QuantityTextBox.Focus()
                Else
                    MessageBox.Show("Please enter a valid price greater than zero.")
                    PriceTextBox.Focus()
                    PriceTextBox.SelectAll()
                End If
            Else
                MessageBox.Show("Please enter a menu item.")
                MenuItemTextBox.Focus()
                MenuItemTextBox.SelectAll()
            End If
        Else
            MessageBox.Show("Please enter a valid quantity greater than zero.")
            QuantityTextBox.Focus()
            QuantityTextBox.SelectAll()
        End If
    End Sub

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now