Solved

arrays with checkboxes

Posted on 2000-04-07
3
126 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now