Private Function a%(b)
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:空間域名、虛擬主機(jī)、營(yíng)銷軟件、網(wǎng)站建設(shè)、市中網(wǎng)站維護(hù)、網(wǎng)站推廣。
s = 1
For i = 1 To b
s = s * i
Next i
a = s
End Function
Private Sub Form_activate()
For i = 1 To 10
n = n + a(i)
Next i
Print n
End Sub
Public Class Form1
Inherits System.Windows.Forms.Form#Region " Windows 窗體設(shè)計(jì)器生成的代碼 " Public Sub New()
MyBase.New() '該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。
InitializeComponent() '在 InitializeComponent() 調(diào)用之后添加任何初始化 End Sub '窗體重寫 dispose 以清理組件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub 'Windows 窗體設(shè)計(jì)器所必需的
Private components As System.ComponentModel.IContainer '注意: 以下過程是 Windows 窗體設(shè)計(jì)器所必需的
'可以使用 Windows 窗體設(shè)計(jì)器修改此過程。
'不要使用代碼編輯器修改它。
System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1" End Sub#End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
Dim i As Integer, f As Long
For i = 0 To 10
f = Factor(i)
s = s i "!=" f vbNewLine
Next i
MsgBox(s)
End Sub
Function Factor(ByVal n As Integer) As Long
End Function
End Class
首先在窗體上畫兩個(gè)控件:TextBox1和Button1
TextBox1用來輸入需要計(jì)算那個(gè)數(shù)的階乘
雙擊Button1進(jìn)入輸入代碼,代碼如下
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim Factorial As Integer = 1 '定義一個(gè)變量用來記錄階乘的結(jié)果
Dim count As Integer '定義一個(gè)變量用來記錄需要計(jì)算那個(gè)數(shù)的階乘
Dim i As Integer = 1 '定義一個(gè)數(shù)用來循環(huán)
count = Int(Val(Me.TextBox1.Text)) '把TextBox1的值賦值給count
Do While i = count '下面開始計(jì)算階乘
Factorial = Factorial * i '計(jì)算階乘
i += 1 '自增1
Loop
MessageBox.Show(Int(Val(Me.TextBox1.Text)) "的階乘是:" Factorial, "完成", MessageBoxButtons.OK) '彈出計(jì)算結(jié)果
Catch ex As Exception '出錯(cuò)提示
MessageBox.Show(Err.Description, "出錯(cuò)了", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Command1_Click()
Dim A, B, C
A = 10
B = 3
C = f(A) / (f(B) * f(A - B))
Print C
End Sub
Private Function f(n)
Dim I As Integer
f = 1
For I = 1 To n
f = f * I
Next I
End Function