Solved

arrays with checkboxes

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

739 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