?
Solved

arrays with checkboxes

Posted on 2000-04-07
3
Medium Priority
?
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

770 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