秒表(2012-03-21 11:48:49)
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Time
End Sub
数据处理(2012-03-21 11:17:39)
Option Base 1
Dim a(10) As Integer
Private Sub Command1_Click()
For i = 1 To 10
a(i) = InputBox("输入第" & i & "个数")
Next i
End Sub
Private Sub Command2_Click()
Dim max As Integer
Dim min As Integer
Dim sum As Integer
max = a(1)
min = a(1)
sum = 0
Print
For i = 1 To 10
Print a(i);
sum = sum + a(i)
If max < a(i) Then max = a(i)
If min > a(i) Then min = a(i)
Next i
Print
Print "最大值是" & max
Print "最小值是" & min
Print "平均值" & sum / 10
End Sub
出现for就必须有next还有注意空格
素数的判断(2012-03-21 10:52:02)[编辑][删除]转载▼标签: 杂谈
Step1:从开始->程序->MicrosoftVisual Basic 6.0中文版启动VB开发软件
Step2:文件->新建工程,打开的窗口中选择“标准的.exe”->确定
Label
TextBox
CommandButton
Step3:绘制如下的界面
Step4:双击“开始计算”按钮,在光标闪烁的地方放置如下的代码
Option Explicit
Private Sub Command1_Click()
Dim M As Integer
Dim N As Integer
M = Int(Val(Text1.Text))
N = Int(Val(Text2.Text))
Dim TemporyValue As Integer
If M < N Then
TemporyValue = M
M = N
N = TemporyValue
End If
Dim Remainder As Integer
Remainder = M Mod N
While Remainder <> 0
M = N
N = Remainder
Remainder = M Mod N
Wend
Label4.Caption = Str(N)
End Sub
Dim Flag as boolean
Private Sub Command1_Click()
'html5
'css3
'javascript
Dim M As Integer
Dim N As Integer
Dim flag As Boolean
M = Int(Val(Text1.Text))
N = M - 1
flag = False '为true时表示M可
'被比他小的整数整除
While N >= 2
If M Mod N = 0 Then
flag = True
End If
N = N - 1
Wend
If flag = True Then
'Print "您不是素数"
lblIsPrimer.Caption = "您不是素数"
Else
'Print "您是素数"
lblIsPrimer.Caption = "您是素数"
End If
End Sub
复制粘贴老师的 不过也学到很多
圆的有关计算(2012-03-21 10:49:15)
Private Sub Command1_Click()
Dim r As Single
Dim s As Single
Dim l As Single
Const ip = 3.14
r = Val(Text1.Text)
s = ip * r * r
l = 2 * ip * r
Text2.Text = Str(s)
Text3.Text = Str(l)
End Sub
一开始没有成功,因为没有区分integer和single