⑴ VB程序代码编写
你不是想说求s>2000时n的值?
s = 0
i = 0
While s < 2000
i = i + 1
s = s + i ^ 2
Wend
MsgBox "s=" & s & " , n=" & i
⑵ 在VB上如何编写程序
两个正整数的最小公倍数Private Sub Command1_Click()
Label4.Caption = "该功能用来求你马上要输入的各数据的最小公倍数!注:(1)你输入的数据个数不能少于2;(2)你输入的各数据的值不能少于1,并且应该全部是整数!"
Label6.Caption = ""
Dim j#, i#, l#, k#, x#, z As Boolean, gbs1() As Double, sj$, gbs() As Double, zxbs#, tt, js1() As Boolean
z = True
tiao:
If z Then
l = InputBox("请问你要求几个数的最小公倍数?", , 2)
Else
l = InputBox("请你重新输入要求几个数的最小公倍数的个数。注:“值不能少于2;也必需是正整数。”!", , 2)
End If
If l < 2 Or l > Fix(l) Then
MsgBox "你的输入有误,求公倍数的参数个数不能少于2,同时必需是正整数!你刚才输入的是:" & l, 64, "求最小公倍数"
z = False
GoTo tiao
End If
ReDim gbs(l)
For j = 0 To l - 1
z = True
tiao1:
If z Then
gbs(j) = InputBox("请输入第" & j + 1 & "个数!")
Else
gbs(j) = InputBox("请重新输入第" & j + 1 & "个数!数据不能少于1并且必需是正整数!")
End If
If gbs(j) < 1 Or gbs(j) > Fix(gbs(j)) Then
MsgBox "你的输入有误,求公倍数的参数不能少于1,同时必需是正整数!你刚才输入的是:" & gbs(j), 64, "求最小公倍数"
z = False
GoTo tiao1
End If
Next j
tt = Now
ReDim gbs1(l)
For j = 0 To l - 1
gbs1(j) = gbs(j)
Next j
zxbs = 1
求最大 k, l, gbs(), zxbs, js1()
For j = 0 To l - 1
zxbs = zxbs * gbs(j)
sj = sj & gbs1(j) & ";"
Next j
tt = Now - tt
tt = Round(tt * 10 ^ 8, 0)
RichTextBox1.Text = "计算完毕!用了:(" & tt & ")毫秒;你刚才输入了(" & l & ")个数据;它们分别是:(" & sj & ");它们的最小公倍数是:(" & zxbs & ")!"
MsgBox "计算完毕!用了:(" & tt & ")毫秒;你刚才输入了(" & l & ")个数据!它们的最小公倍数是:(" & zxbs & ")", 64, "求最小公倍数!"
End Sub
'求出数组里面的最大数!做为循环的上界!
Public Sub 求最大(k#, l#, gbs() As Double, zxbs#, js1() As Boolean)
k = gbs(0)
For j = 0 To l - 1
If gbs(j) > k Then k = gbs(j)
Next j
求约数 k, l, gbs(), zxbs, js1()
End Sub
'找出数组里面数据的公有约数(只要有两数据有相同的约数,就把该约数给计下来)
Public Sub 求约数(k#, l#, gbs() As Double, zxbs#, js1() As Boolean)
Dim x&, c&, js As Boolean, y&, y1&
If k > 1 Then
js = True
ReDim Preserve js1(k)
For x = 2 To k
If js1(x) = False Then
js1(x) = True
For c = 0 To l - 2
If gbs(c) Mod x = 0 Then
For y = c + 1 To l - 1
If gbs(y) Mod x = 0 Then
js = False
For y1 = 0 To l - 1
If gbs(y1) Mod x = 0 Then gbs(y1) = gbs(y1) / x
Next y1
'把求出来的约数相乘
js1(x) = False
zxbs = zxbs * x
End If
Next y
End If
Next c
End If
If js = False Then Exit For
Next x
If js = False Then
求最大 k, l, gbs(), zxbs, js1()
End If
End If
End Sub
⑶ 用VB编写一个程序
给你写好代码了,需要一个command按钮,一个textbox控件!
Dim try As Integer
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "请输入信用卡密码!", vbExclamation + vbOKOnly, "操作提示"
Text_name.SetFocus
Exit Sub
End If
If Trim(Text1.Text) <> "123456" Then
MsgBox "密码错误", vbExclamation + vbOKOnly, "操作提示"
Text1.SetFocus
try = try + 1
On Error GoTo trytimes
Else
MsgBox "密码正确", vbExclamation + vbOKOnly, "操作提示"
Unload Me '密码正确卸载窗体,加载新的窗体你自己加上吧!
End If
trytimes:
If try >= 3 Then
MsgBox "因多次错误操作,信用卡被没收!”", vbExclamation + vbOKOnly, "操作提示"
End '三次错误操作,结束程序
Else
Exit Sub
End If
End Sub
不懂的网络hi留言!
⑷ VB程序怎么写
Sub a()
For Each sh In Sheets
Sheet1.Range("A1").Copy Sheets(sh.Name).Range("A6")
Next
End Sub
⑸ VB程序编写
下面是我帮你修改简化后的程序,你对比一下:
Private Sub Command1_Click()
Dim a%(10, 10), i%, j%
Cls
For i = 1 To 10
For j = 1 To 10
If i = j Or i = 11 - j Then
a(i, j) = 1
Else
a(i, j) = 0
End If
Print a(i, j);
If j = 10 Then Print
Next j
Next i
End Sub
第一,
For i = 1 To 10
For j = 1 To 10
Print a(i, j)
End If
Next i
Next j
这段程序根本就是多写的,你直接把print放到上面的循环不就好了。另外要注意十个数就要换一行,所以要添加If j = 10 Then Print的语句。
第二,你的Next i,Next j,End If的顺序有问题,你对比下我的就知道了。
你把这些该过来应该就没问题了。