Solved

arrays with checkboxes

Posted on 2000-04-07
3
125 Views
Last Modified: 2010-05-02
I need to change my code to calculate a restaurant order from using if/then statements to an array for the cost of each item and have the customer order stored in another array. Right now my code looks like this
'calculates frech fries
if chkFoxy.value=vbchecked then
subfries= 0.89 * txtFries
end if
it stores the items into a subtotal before it calculates the taxes to a total.
I also using textboxes.  I don't even know where to start in changing the program.
0
Comment
Question by:jonesie69
  • 3
3 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2695592
i'm not sure i quite understand.  youre using textboxes to store the quantity of each item bought correct?  and right now you are just having to hardcode the amount of the item by actually typing in .89 cents for example.  so you want to hold in an array all the prices for each item and then another array that holds the items that the customer bought?  then using those two arrays and the checkboxes get your amount?  if this is what you want let me know.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2695622
Assuming that this is what you want, what you will need to do is create an array of checkboxes.  This can be done by either dropping one checkbox on your form, copying it and pasting it. or dropping several checkboxes on your form and naming them all the same name. either way you will be prompted as to whether you want to create a control array or not.  say yes.  you will notices they will be named like Check1(0), Check1(1) etc depending on what name you have them.  You will want to do the same for the textboxes that go next to each checkbox indicating the number of items they want.  Now to create an array to hold all the item prices, lets say you have 5 items

Dim itemCosts(4) As Variant

Now in your form load event you can set the prices for each item. each item will have its own checkbox and textbox so be sure to keep the items in the same order.  for example, lets say you have fries or something. if you make Check1(0) the checkbox for fries, be sure text1(0) is for fries and when we enter the item prices into our array itemCosts, be sure that itemCosts(0) is the cost for fries. And so on for the other items.

So in your form load event you can enter all the prices.

Private Sub Form_Load()
itemCosts(0) = .83
itemCosts(1) = 1.27
itemCosts(2) = 2.36
etc
End Sub


Now lets say youre ready to ring up a subtotal.  all the entries have been made and the checkboxes that need to be checked are checked and the textboxes indicate all the quantities.

Lets say you have a button to press to calculate the total.  Implement it as such:

Private Sub Command1_Click()
Dim i As Integer
Dim subtotal As Integer
For i = 0 To Text1.Ubound
If check3(i).Value = vbChecked Then
  subtotal = subtotal + (itemCosts(i) * Text1(i).Text)
End If
Next
txtSubtotal.Text = subtotal
End Sub

this will iterate through each checkbox, determine if its checked or not, and if it is, muliply the correct price of the item by the quantity entered in the textbox.  it will return the subtotal into a textbox that i just called txtSubtotal


hope this is what you need.  let me know.




0
 
LVL 28

Accepted Solution

by:
AzraSound earned 150 total points
ID: 2695625
sorry dont know why i put check3(i) in the command click event.  it should be check1(i) to be consistent with the rest of my answer.  sorry to confuse.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 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

21 Experts available now in Live!

Get 1:1 Help Now