查看: 1060|回复: 1
|
Private Funtion(....) As .... {VB}
[复制链接]
|
|
A bookstore vendor sells storybook (RM15 each), magazine (RM10 each) and academic reference ( RM45 each) to the customer. Write a program to calculate a customer total cost when user click on the "Total Cost" command button.The program shouild request the quantity of each item ordered from a sub procedure "Quantity" where the parameter of this procedure are pass by reference.calculate the total cost with a fucntion " Total" and use a message box to display the result. You have to use the following variables in your program :
Module_level variables : intStoryQty, intMagazineQty, intAcademicQty
Local_level variables : sngTotalCost
Constant variables: sngSTORYPRICE, sngMAGAZINEPRCIE, sngACADEMICPRICE
Private Sub cmdTotal_Click()
Const sngSTORYPRICE As Single = 15
Const sngMAGAZINEPRICE As Single = 10
Const sngACADEMICPRICE As Single = 45
Call Quantity(intStoryQty, intMagazineQty, intAcademicQty)
ComputeTotal = Total(txtStoryBook, txtMagazine, txtAcademic)
End Sub
Private Sub Quantity(ByRef intStoryQty As Integer, ByRef intMagazineQty As Integer, ByRef intAcademicQty As Integer)
intStoryQty = Val(txtStoryBook.Text)
intMagazineQty = Val(txtMagazine.Text)
intAcademicQty = Val(txtAcademic.Text)
End Sub
Private Function Total(intStoryQty As Integer, intMagazineQty As Integer, intAcademicQty As Integer) As Integer
Dim sngTotalCost As Single
sngTotalCost = intStoryQty * sngSTORYPRICE + intMagazineQty * sngMAGAZINEPRICE + intAcademictQty * sngACADEMICPRICE
MsgBox " Total Cost is " & sngTotalCost, vbOKOnly, "Result"
End Function
请问我做错什么? |
|
|
|
|
|
|
|
发表于 13-1-2007 09:45 AM
|
显示全部楼层
回复 #1 schoe 的帖子
试试看这个:
Const sngSTORYPRICE As Single = 15
Const sngMAGAZINEPRICE As Single = 10
Const sngACADEMICPRICE As Single = 45
Public intStoryQty as integer
Public intMagazineQty as integer
Public intAcademicQty as integer
Private Sub cmdTotal_Click()
intStoryQty = 0
intMagazineQty = 0
intAcademicQty = 0
Call Quantity(intStoryQty, intMagazineQty, intAcademicQty)
MsgBox "Total Cost is " & Total(), vbOKOnly, "Result"
End Sub
Private Sub Quantity(ByRef intStoryQty As Integer, ByRef intMagazineQty As Integer,ByRef intAcademicQty As Integer)
intStoryQty = Val(txtStoryBook.Text)
intMagazineQty = Val(txtMagazine.Text)
intAcademicQty = Val(txtAcademic.Text)
End Sub
Private Function Total() As Integer
Dim sngTotalCost As Single
sngTotalCost = intStoryQty * sngSTORYPRICE + intMagazineQty * sngMAGAZINEPRICE + intAcademictQty * sngACADEMICPRICE
Quantity = sngTotalCost
End Function |
|
|
|
|
|
|
| |
本周最热论坛帖子
|