⑴ VB编程:编写程序,产生50个互不相同的10~99的随机整数,统计各数值段有多少个数
Dim a(1 To 50) As Integer, b(1 To 9) As Integer
Dim i As Integer, j As Integer
Randomize
For i = 1 To 9
b(i) = 0 '初始化数组
Next
For i = 1 To 50
a(i) = Int(90 * Rnd + 10) '产生随机数
For j = 1 To 9 '判定范围存入数组
If a(i) > j * 10 - 1 And a(i) < j * 10 + 10 _
Then b(j) = b(j) + 1
Next
Next
'输出
For i = 1 To 50
Debug.Print "数" & i & "=" & a(i)
Next
For j = 1 To 9
Debug.Print "范围" & (j * 10) & "到" & (j * 10 + 9) & "的数有" & b(j) & "个。"
Next
⑵ VB编程,超简单的。求编写代码
第一题:
Private Sub Form_Click()
Dim x As Double, Y As Double
x = InputBox("请输入当前顾客购买鸡蛋的重量(以公斤为单位)")
If x < 3 Then
Y = 7.6 * x
Else
Y = 7.6 * x * 0.8
End If
Print Format(Y, "0.00")
End Sub
第二题:
Private Sub Form_Click()
Dim x As Double, Y As Double
x = InputBox("请输入顾客所乘的公里数")
If x / Fix(x) = 1 Then
x = x
Else
x = Fix(x) + 1
End If
If x > 15 Then
Y = 7 + 13 * 1.5 + (x - 15) * 2.1
ElseIf x > 2 Then
Y = 7 + (x - 2) * 1.5
Else
Y = 7
End If
Print Y
End Sub
⑶ 求VB中必须背过的命令
789+
456-
123*
0.=/
每个一个按钮(每个按钮对应数字),一个文本框。
一下是最基础代码(其实可以用按钮数组)
----------------------
Dim d As Integer
Dim x As String
Dim y As String
Dim k As Integer
Private Sub Command1_Click(Index As Integer)
Label1.Caption = Label1.Caption + Command1(Index).Caption
End Sub
Private Sub Command2_Click()
y = Label1.Caption
If d = 0 Then
Label1.Caption = Val(x) + Val(y)
End If
If d = 1 Then
Label1.Caption = Val(x) - Val(y)
End If
If d = 2 Then
Label1.Caption = Val(x) * Val(y)
End If
If d = 3 Then
If Val(y) = 0 Then
Label1.Caption = "被除数不能为零"
Else
Label1.Caption = Val(x) / Val(y)
End If
End If
End Sub
Private Sub Command3_Click()
x = Label1.Caption
Label1.Caption = ""
d = 0
k = 0
End Sub
Private Sub Command4_Click()
x = Label1.Caption
Label1.Caption = ""
d = 1
k = 0
End Sub
Private Sub Command5_Click()
x = Label1.Caption
Label1.Caption = ""
d = 2
k = 0
End Sub
Private Sub Command6_Click()
x = Label1.Caption
Label1.Caption = ""
d = 3
k = 0
End Sub
Private Sub Command7_Click()
Label1.Caption = Sqr(Val(Label1.Caption))
End Sub
Private Sub Command8_Click()
Label1.Caption = ""
d = 9
k = 0
End Sub
Private Sub Command9_Click()
If k = 0 Then
If Label1.Caption = "" Then
Label1.Caption = Label1.Caption + Str(0) + Command9.Caption
k = k + 1
Else
Label1.Caption = Label1.Caption + Command9.Caption
k = k + 1
End If
End If
End Sub
⑷ VB编程的程序
'再窗体上放一个按钮command1,一个图形控件image1,和一个滚动条HScroll1,代码如下:
Dim W, H As Double
Private Sub Command1_Click() '按钮单击事件
Image1.Stretch = True
With HScroll1
.Enabled = True
.Min = 100
.Max = 2400
.LargeChange = 200
.SmallChange = 20
End With
End Sub
Private Sub Form_Load()
HScroll1.Enabled = False
W = Me.Image1.Width
H = Me.Image1.Height
End Sub
Private Sub HScroll1_Change()
Me.Image1.Width = W + Me.HScroll1.Value
Me.Image1.Height = H + Me.HScroll1.Value
End Sub