Umm, I'm a newbie in VB6, so I am currently facing the procedure being too large during the run of the program. For example:

If txt6 > 0 Then
lblItem6 = "W6~ Jane Doe"
lblItemprice6 = "9.00"
lblItemquantity6 = txt6
lblTotal6 = TotW6Price
ElseIf txt7 > 0 Then
lblItem6 = "W7~ John Doe"
lblItemprice6 = "10.50"
lblItemquantity6 = txt7
lblTotal6 = TotW7Price
(....... it goes on)

End If

(and then, again).....
If txt7 > 0 Then
lblItem7 = "W7~ John Doe"
lblItemprice7 = "10.50"
lblItemquantity7 = txt7
lblTotal7 = TotW7Price
ElseIf txt8 > 0 Then
lblItem7 = "W8~ Mary Doe"
lblItemprice7 = "10.90"
lblItemquantity7 = txt8
lblTotal7 = TotW8Price
......(it goes up to 72 ElseIf's)

End If


I have a lot of these inputted into the code, which probably explains the problem I am facing now. Could someone tell me how I solve this?

Thank you!
wookinhung

Hi,

Yes, there is a Limitation of Procedure Size, in VB6..
Looking at your code, appears, there is a Lot of Repeatation,
say for example, this part :

ElseIf txt7 > 0 Then
lblItem6 = "W7~ John Doe"
lblItemprice6 = "10.50"
lblItemquantity6 = txt7
lblTotal6 = TotW7Price

Is repeated TWICE in the above code..
Why not Put Such Repeated Parts in another Proc / or Function and call that..?

Another way around can be, Instead of HARD_Coding,
Save In an Access Database, and Retrive Later depending on the IF Condition..

REgards
Veena

Thanks, but thing is.... I don't really understand "Why not Put Such Repeated Parts in another Proc / or Function and call that..?" and also "Save In an Access Database, and Retrive Later depending on the IF Condition"

How can I do that? Do you know any websites that provide information or step by step tutorials? Thanks a lot!

Thanks
wookinhung

Hi,

Tell me, what are you trying to do with the Procedure Block..
You are checking for what? and What is there in txt6, txt7
Then it will be easy for me to suggest an Alternative solution

Regards
Veena

Hi,

I hope my pictures can clear up a bit of what I'm going to tell you. I'm currently working on my school's project on a restaurant menu. The menu has 72 different dishes and it requires the patron to input the quantity of what they want in the textboxes. As you can probably see, txt1,2,6,7,etc are the textboxes that represent the number of dishes.

After they have finished choosing what they want, they click on the the billing form. Thats where the "procedure too large" comes in place because I inputted too much repetitions of (for ex.):

If txt1 > 0 Then
lblItem1 = "W1~ Black Pepper Chicken Chop"
lblItemprice1 = "RM 10.90"
lblItemquantity1 = txt1
lblTotal1 = TotW1Price
ElseIf txt2 > 0 Then
lblItem1 = "W2~ Barbequed Chicken Chop"
lblItemprice1 = "RM 10.90"
lblItemquantity1 = txt2
lblTotal1 = TotW2Price
ElseIf txt3 > 0 Then
lblItem1 = "W3~ Lamb Chop"
......... it goes on and on...... for the other labels in the billing form.

I really appreciate your help. Thanks a lot!

Regards
wookinhung

I hope this is in VB6 or VBA.....

On the form load event, you need to loop through all the check boxes and set all values to False (not selected):

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
End If
Next
Set ctrl = Nothing


You need to create many variables and assign them the Prices or Values first. Replace the ton of If Then statements with a Loop, and create a variable to grab each Control/Field value dynamically.

Should look something like this:
dim c1, c2, c3, c4, c5, c6 as Double (Change Double to whatever datatype you need)
'Make sure c1, c2, c3
c1 = 10.00
c2 = 3.00
c3 = 5.95
..... keep on assigning values here and make some coffee beforehand:D . It appears you may have to do the same for the labels, quantity and total price also. This would be much easier if you through this data into an Access table and used queries/vb recordsets to perform the calculations.

Once you get all that done, you need the total number of checkboxes and controls (labels, quantity, etc.....) to loop through and bring it all together. I believe you said 72. Should look something like this:


Dim i as Integer
i = 1
Do Until i = 73 ' Go to 73 to make this stop looping after 72 times....

If Me("txt" & (i)).Value > 0 Then ' Me("txt" & (i)) = txt1
Me("lblItemprice" & (i)).Text = ("c" & (i)) ' is c1, which = 10.00
' Do the same as the previous line for all fields
' lblItem, lblItemprice, lblItemquantity, lblTotal

End If
Loop


c1 will only take care of the field lblItemprice. You need to Dim 3 other fields to take care of the other fields, which is four fields total times 72 items is 288 total - Wow!.
a1, b1, c1, d1 ' Use these for the first four Controls ending in 1
a2, b2, c2, d2 ' Use these for the first four Controls ending in 2
.... keep doing this till 72
If VB blows up and melts your PC, break this into seperate Sub Procedures. You can use If statements to call in different procedures.

You really need to learn how to work this with a Database, which is probably around the corner. :icon_eek:

Hope this helps, you may have to tweek it a bit.... Happy Coding!

Hi,

If you Have Named all the Controls Uniformly From 1 To 72, then
You can do all that Calculation in Just 2 Steps.
Some thing Like This :

Dim i As Integer
Dim MyTot As Currency
Dim ctlText As TextBox
Dim ctlLabel As Label
MyTot = 0
For i =1 To 72
    Set ctlText = Me.Controls("txt" & i)
    Set ctlLabel = Me.Controls("lblItemprice" & i)
    MyTot = MyTot + (Val(Trim(Mid(ctlLabel.Caption,3))) * Val(ctlText.Text))
Next
MsgBox MyTot

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.