| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 372 人关注过本帖
标题:有一个程序请求指点一下
只看楼主 加入收藏
耿辉
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-5-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
有一个程序请求指点一下
编写程序计算1!+2!+3!+4!+5!+6!
   要求用sub过程和function过程分别编程。
   请求有人快速指点一下。
搜索更多相关主题的帖子: function 
2011-05-29 18:01
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:20 
玩玩看~

程序代码:
Private Sub Command1_Click()
Dim i As Long, j As Long, k As Long, Total As Long

    i = Val(Text1.Text)
    Total = 0

    Do While i > 0
        k = 1
        For j = i To 1 Step -1
            k = k * j
        Next j
        Total = Total + k
        i = i - 1
    Loop

 
    MsgBox Total
    Text1.Text = ""
End Sub

不要選我當版主
2011-05-29 19:21
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
还要分解动作~应该连说明都能省了~

程序代码:
Private Sub Command1_Click()
Dim i As Long

    i = Val(Text1.Text)

    MsgBox AAA(i)
    
    Text1.Text = ""
    
End Sub

Private Function AAA(i As Long) As Long
Dim j As Long, k As Long, Total As Long

    Total = 0

    Do While i > 0
        k = 1
        For j = i To 1 Step -1
            k = k * j
        Next j
        Total = Total + k
        i = i - 1
    Loop
    
    AAA = Total

End Function


[ 本帖最后由 wube 于 2011-5-29 19:29 编辑 ]

不要選我當版主
2011-05-29 19:27
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
再短一点~

程序代码:
Private Sub Command1_Click()
Dim i As Long, j As Long, k As Long

    i = Val(Text1.Text)

    MsgBox AAA(i)
    
    Text1.Text = ""
    
End Sub

Private Function AAA(i As Long) As Long
Dim j As Long, k As Long

    Do While i > 0
        k = 1
        For j = i To 1 Step -1
            k = k * j
        Next j
        AAA = AAA + k
        i = i - 1
    Loop

End Function

不要選我當版主
2011-05-29 19:32
快速回复:有一个程序请求指点一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026988 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved