tmp = InputBox("随便输入几个数,用逗号隔开就可以了。")
s = Split(tmp, ",")
u = UBound(s)
For i = 0 To u
If Val(s(i)) Mod 2 = 1 Then
qs = qs + 1
Else
os = os + 1
End If
Next
Print qs & "个奇数," & os & "个偶数"
加入标签Label1,Caption设置为“你好,请输入你的姓名”
加入文本框Text1,用来输入姓名的
加入标签Label2,按照你的要求设置字体属性,autosize属性设成true
以下是代码:
Private Sub Form_Load()
Me结束Visible = False
Me继续Visible = False
Label2Visible = False
End Sub
Private Sub 继续_Click()
Me结束Visible = False
Me继续Visible = False
Label2Visible = False
Me确定Visible = True
Label1Visible = True
Text1Visible = True
End Sub
Private Sub 结束_Click()
End
End Sub
Private Sub 确定_Click()
Label2Caption = Text1Text & "同学,你好,祝你学好vb程序设计"
Me结束Visible = True
Me继续Visible = True
Label2Visible = True
Label1Visible = False
Text1Visible = False
Me确定Visible = False
End Sub
Option Explicit
Private Sub Command1_Click()
If Text1text = "" Or Text1text = "c" Then
Text1text = "a"
Else
Text1text = Chr(Asi(Text1text) + 1)
End if
End Sub
Private Sub Form_Load()
Text1text = ""
End Sub
分在多点,这些都给你搞定。
第一题
Dim k As Integer
Print "100-300的素数为"
For i = 100 To 300
k = 0
For j = 2 To i - 1
If i Mod j = 0 Then k = 1: Exit For
Next j
If k = 0 Then
Print i;
p = p + 1
If p Mod 6 = 0 Then Print
End If
Next i
第二题
Private Sub Command1_Click()
Dim m As Integer, n As Integer, n1 As Integer, m1 As Integer, p As Integer
m = Val(Text1Text)
n = Val(Text2Text)
n1 = n: m1 = m
If m = 0 Or n = 0 Then
MsgBox "数据错误"
Else
If n > m Then t = n: n = m: m = t
p = m Mod n
Do While p <> 0
m = n
n = p
p = m Mod n
Loop
Print "最大公约数"; n; "最小公倍数"; n1 m1 / n
End If
End Sub
Private Sub Form_Activate()
Text1Text = ""
Text2Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then MsgBox "数据错误": KeyAscii = 0: Text1Text = ""
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then MsgBox "数据错误": KeyAscii = 0: Text1Text = ""
End Sub
第三题
Dim a(1 To 10) As Integer, t As Integer
Print "排序前"
For i = 1 To 10
a(i) = Val(InputBox("请输入第" & i & "个数据", "数据输入"))
Print a(i);
If i Mod 6 = 0 Then Print
Next i
For i = 1 To 9
For j = 1 To 10 - i
If a(j) > a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = t
Next j
Next i
Print "排序后"
For i = 1 To 10
Print a(i);
If i Mod 6 = 0 Then Print
Next i
第四题
Dim a(10) As Integer, b(10) As Integer
a(1) = 1
a(2) = 1
Print Tab(8 2 + 1); " "; Format(a(1), "00"); " ";
Print Tab(7 2 + 1); " "; Format(a(1), "00"); " "; " "; Format(a(2), "00"); "";
For i = 3 To 9
b(1) = 1: b(i) = 1
For j = 2 To i - 1
b(j) = a(j - 1) + a(j)
Next j
Print Tab((9 - i) 2 + 1);
For j = 1 To i
Print " "; Format(b(j), "00"); " ";
Next j
For j = 1 To i
a(j) = b(j)
Next j
Next i
Private Sub Form_Load()
Timer1Interval = 1000
Timer1Enabled = True
End Sub
Private Sub Timer1_Timer()
Cls
Static a
Print Spc(10);
Select Case a
Case 0
Print "欢"
a = 1
Case 1
Print "迎"
a = 2
Case 2
Print "光"
a = 3
Case 3
Print "临"
a = 0
End Select
Print Now
End Sub
Dim sec, min, h
Private Sub Command1_Click()
Timer1Enabled = True
h = Text1Text
min = Text2Text
sec = Text3Text
Timer2Enabled = False
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Form1BackColor = &HFFFF00
Timer1Enabled = False
Timer1Interval = 1000
Timer2Enabled = True
Timer2Interval = 1000
Text1Text = 2
Text2Text = "00"
Text3Text = "00"
Command2Caption = "退出"
Command1Caption = "开始倒计时"
End Sub
Private Sub Timer1_Timer()
If sec > 0 Then
sec = sec - 1
Else:
If (min > 0 Or h > 0) Then
sec = 59
End If
If min > 0 Then
min = min - 1
Else:
If h > 0 Then
min = 59
End If
If h > 0 Then
h = h - 1
Else: Timer1Enabled = False
CreateObject("SAPISpVoice")Speak "GAME OVER!"
Form1BackColor = &HFF
End If
End If
End If
Text1Text = h
Text2Text = min
Text3Text = sec
Label6Caption = Now
End Sub
Private Sub Timer2_Timer()
Label6Caption = Now
End Sub
以上就是关于vb中编写简单程序全部的内容,包括:vb中编写简单程序、怎么用vb做一个简单的程序、用vb写一个很简单的程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)