查看: 936|回复: 5
|
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
请问我做错什么? |
|
|
|
|
|
|
|
发表于 9-1-2007 03:25 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 9-1-2007 04:00 PM
|
显示全部楼层
原帖由 abc321 于 9-1-2007 03:25 PM 发表
你要问什么问题?output怎么了?
不是拉,我这个code run 不到,应该是private function 有问题
所以找人checkcheck |
|
|
|
|
|
|
|
发表于 9-1-2007 04:33 PM
|
显示全部楼层
做什么会有这样子分的呢?
Module_level variables : intStoryQty, intMagazineQty, intAcademicQty
Local_level variables : sngTotalCost
Constant variables: sngSTORYPRICE, sngMAGAZINEPRCIE, sngACADEMICPRICE
想问问下?不能直接的放TEXTBOX然后在ONCLICK BUTTON (EVEN PROCESURE)时候 CALCULATE吗? |
|
|
|
|
|
|
|
发表于 9-1-2007 04:33 PM
|
显示全部楼层
怎样讲 run 不到呢?
出现什么 error message ? |
|
|
|
|
|
|
|
发表于 10-1-2007 11:11 AM
|
显示全部楼层
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
这段有问题,Function 没有Return Value
,还有msgbox 不该在Function里执行。
以下是个简单的例子:
Private Function ADD(A as integer, B as Integer) as Integer
ADD = A + B
End Function
Private Sub cmdTotal_Click()
Dim intTotal as Integer
intTotal = Add(123, 456)
msgbox ("The Total is " & ctr(intTotal))
End Sub
[ 本帖最后由 extrem23 于 10-1-2007 11:13 AM 编辑 ] |
|
|
|
|
|
|
| |
本周最热论坛帖子
|