Solved

arrays with checkboxes

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

726 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