|
-
Feb 23rd, 2000, 01:57 AM
#1
Thread Starter
Member
I've gotten further along. I study on my own at home, now I am having trouble seeing why I cannot get my Function to pull into my program.
Option Explicit
Private Sub cmdCompute_Click()
'request order and calculate bill
Dim pizza As Single, fries As Single, sftdrks As Single, _
fmt As String, totPizza As Single, totFries As Single, _
totDrink As Single, totDue As Single, tp As Single, tf As Single, _
td As Single, a As Single, b As Single, c As Single
Call InputOrder(pizza, fries, sftdrks)
Call DisplayBill(fmt, totPizza, totFries, totDrink, Due, _ pizza, fries, sftdrks, tp, tf, td, a, b, c)
End Sub
Private Sub InputOrder(pizza As Single, fries As Single, _
sftdrks As Single)
'get the order
pizza = Val(txtPizza.Text)
fries = Val(txtFries.Text)
sftdrks = Val(txtDrink.Text)
End Sub
Private Sub DisplayBill(fmt As String, totPizza As Single, _
totFries As Single, totDrink As Single, totDue As Single, _
pizza As Single, fries As Single, sftdrks As Single, tp As Single, _
tf As Single, td As Single, a As Single, b As Single, c As Single)
'display order and amt due
picOutput.Cls
picOutput.FontBold = True
fmt = "@@@@@@@"
tp = FormatCurrency(totPizza)
tf = FormatCurrency(totFries)
td = FormatCurrency(totDrink)
totDue = FormatCurrency(totDue)
picOutput.Print "Item"; Tab(17); "Quantity"; Tab(40); "Price"
picOutput.Print
picOutput.FontBold = False
picOutput.Print "pizza slices"; Tab(17); pizza; Tab(40);
picOutput.Print Format(tp, fmt)
picOutput.Print "fries"; Tab(17); fries; Tab(40); Format(tf, fmt)
picOutput.Print "soft drinks"; Tab(12); Format(sftdrks, fmt); Tab(40);
picOutput.Print Format(td, fmt)
picOutput.Print
picOutput.FontBold = True
picOutput.Print "Total"; Tab(35); Format(td, fmt)
End Sub
Private Function totPizza(a As Single, pizza As Single) As Single
a = 1.25
totPizza = a * pizza
End Function
Private Function totFries(b As Single, fries As Single) As Single
b = 1
totFries = b * fries
End Function
Private Function totDrink(c As Single, sftdrks As Single) As Single
c = 0.75
totDrink = c * sftdrks
End Function
Private Function totDue(totPizza As Single, totFries As Single, _
totDrink As Single) As Single
totDue = totPizza + totFries + totDrink
End Function
Private Sub cmdExit_Click()
End
End Sub
MomOf3CollegeStudentTooMuchToDoNeverEnoughTime
Using VB6 Working Model Edition
-
Feb 23rd, 2000, 02:02 AM
#2
Fanatic Member
Look at this:
Code:
'the calls
tp = FormatCurrency(totPizza)
tf = FormatCurrency(totFries)
td = FormatCurrency(totDrink)
'the functions
Private Function totPizza(a As Single, pizza As Single) As Single
.
.
End Function
Private Function totFries(b As Single, fries As Single) As Single
.
.
End Function
Private Function totDrink(c As Single, sftdrks As Single) As Single
.
.
End Function
You are not giving the function calls any params
r0ach™
Don't forget to rate the post
-
Feb 23rd, 2000, 02:11 AM
#3
Thread Starter
Member
Re: home study - cannot print results of function
When I do I get a compile error: expected array with totPizza highlighted
tp = FormatCurrency(totPizza(a, pizza))
tf = FormatCurrency(totFries(b, fries))
td = FormatCurrency(totDrink(c, sftdrks))
totDue = FormatCurrency(totDue(totPizza, totFries, totDrink))
-
Feb 23rd, 2000, 02:26 AM
#4
Frenzied Member
Your main problem, I think, is that you have variables declared in cmdCompute_Click that have the same name as functions declared later on.
For example, you have:
totPizza As Single
in cmdCompute_Click, then later you have:
Private Function totPizza(a As Single, pizza As Single) As Single
Try this code instead:
Code:
Option Explicit
Private Sub cmdCompute_Click()
'request order and calculate bill
Dim pizza As Single, fries As Single, sftdrks As Single, _
fmt As String, totPizza As Single, totFries As Single, _
totDrink As Single, totDue As Single, tp As Single, tf As Single, _
td As Single, a As Single, b As Single, c As Single
Call InputOrder(pizza, fries, sftdrks)
Call DisplayBill(fmt, totPizza, totFries, totDrink, totDue, _
pizza, fries, sftdrks, tp, tf, td, a, b, c)
End Sub
Private Sub InputOrder(pizza As Single, fries As Single, _
sftdrks As Single)
'get the order
pizza = Val(txtPizza.Text)
fries = Val(txtFries.Text)
sftdrks = Val(txtDrink.Text)
End Sub
Private Sub DisplayBill(fmt As String, totPizza As Single, _
totFries As Single, totDrink As Single, totDue As Single, _
pizza As Single, fries As Single, sftdrks As Single, tp As Single, _
tf As Single, td As Single, a As Single, b As Single, c As Single)
'display order and amt due
picOutput.Cls
picOutput.FontBold = True
fmt = "currency"
tp = totalPizza(a, pizza)
tf = totalFries(b, fries)
td = totalDrink(c, sftdrks)
totDue = FormatCurrency(totalDue(totPizza, totFries, totDrink))
picOutput.Print "Item"; Tab(17); "Quantity"; Tab(40); "Price"
picOutput.Print
picOutput.FontBold = False
picOutput.Print "pizza slices"; Tab(17); pizza; Tab(40); Format(tp, fmt)
picOutput.Print "fries"; Tab(17); fries; Tab(40); Format(tf, fmt)
picOutput.Print "soft drinks"; Tab(17); sftdrks; Tab(40); Format(td, fmt)
picOutput.Print
picOutput.FontBold = True
picOutput.Print "Total"; Tab(35); Format(td, fmt)
End Sub
Private Function totalPizza(a As Single, pizza As Single) As Single
a = 1.25
totalPizza = a * pizza
End Function
Private Function totalFries(b As Single, fries As Single) As Single
b = 1
totalFries = b * fries
End Function
Private Function totalDrink(c As Single, sftdrks As Single) As Single
c = 0.75
totalDrink = c * sftdrks
End Function
Private Function totalDue(totPizza As Single, totFries As Single, _
totDrink As Single) As Single
totalDue = totPizza + totFries + totDrink
End Function
Private Sub cmdExit_Click()
End
End Sub
Hope that helps!
~seaweed
Edited by seaweed on 02-23-2000 at 02:35 PM
-
Feb 23rd, 2000, 03:10 AM
#5
Frenzied Member
Here's another way, without so many function calls. It is also a little easier to read (who knows what a,b,c are?). The only thing that may be strange to you is the naming conventions. These are just the ones I learned in school. (mc_sng means ModuleLevel Constant Single).
Code:
Option Explicit
Const mc_sngPizzaPrice As Single = 1.25
Const mc_sngFriesPrice As Single = 1
Const mc_sngDrinkPrice As Single = 0.75
Private Sub cmdCompute_Click()
Dim sngPizzaQty As Single, _
sngFriesQty As Single, _
sngDrinkQty As Single
sngPizzaQty = Val(txtPizza)
sngFriesQty = Val(txtFries)
sngDrinkQty = Val(txtDrink)
Call DisplayBill(sngPizzaQty, sngFriesQty, sngDrinkQty)
End Sub
Private Sub DisplayBill(sngPizzaQty As Single, sngFriesQty As Single, sngDrinkQty As Single)
Dim sngPizzaTotal As Single, _
sngFriesTotal As Single, _
sngDrinkTotal As Single, _
sngTotalDue As Single
sngPizzaTotal = sngPizzaQty * mc_sngPizzaPrice
sngFriesTotal = sngFriesQty * mc_sngFriesPrice
sngDrinkTotal = sngDrinkQty * mc_sngDrinkPrice
sngTotalDue = sngPizzaTotal + sngFriesTotal + sngDrinkTotal
picOutput.Cls
picOutput.FontBold = True
picOutput.Print "Item"; Tab(15); "Quantity"; Tab(34); "Price"
picOutput.Print str
picOutput.Print
picOutput.FontBold = False
picOutput.Print "Pizza slices:"; Tab(17); sngPizzaQty; Tab(40); Format(sngPizzaTotal, "currency")
picOutput.Print "Fries:"; Tab(17); sngFriesQty; Tab(40); Format(sngFriesTotal, "currency")
picOutput.Print "Soft drinks:"; Tab(17); sngDrinkQty; Tab(40); Format(sngDrinkTotal, "currency")
picOutput.Print
picOutput.FontBold = True
picOutput.Print "Total:"; Tab(34); Format(sngTotalDue, "currency")
End Sub
Private Sub cmdExit_Click()
End
End Sub
Hope this helps a little...
~seawe
Edited by seaweed on 02-23-2000 at 03:14 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|