在桌面上,鼠标左键双击程序,在打开的VB6主界面上,左边是工具菜单栏,单击标签按钮,在Form1窗口上,绘制出一Label1,然后在其属性窗口上改个名字,如Caption为第一数,如下图所示。
接着,用同样的方法,在Form1窗口上绘制出第二数,并且在左边工具菜单栏,单击文本框按钮,并绘制出来。在文本框属性栏的Text属性上,将其Text1删除,也就是清空数据,如下图所示。
然后,反复用第一步骤和第二步骤做成如图所示的界面来,学习需要反复练习,在练习中不断进步。这里是做简单的加法程序,如下图所示。
接着,加法程序的界面做好后,还不能执行加法运算,必须还要在Form1窗口上绘制出一个命令按钮来,在左边工具菜单栏,单击命令按钮,并绘制出来。然后给其属性窗口下Caption改名为计算,如下图所示。
然后,程序看起来是做好了,单击如图所示的运行按钮,d出自己做出的Form1窗口,输入数字3和6,然后单击计算。可是结果并没有出现,如下图所示。
最后,前面5个步骤只是做了程序的界面,想要程序出结果,那必须加些代码了,既然是简单程序,只加一行代码就可以了。双击命令按钮,在代码窗口中输入如下:Text3.Text = Val(Text1.Text) + Val(Text2.Text)后,再单击运行,输入数字,单击计算,此时就出现结果了,如下图所示。
加入标签Label1,Caption设置为“你好,请输入你的姓名”加入文本框Text1,用来输入姓名的
加入标签Label2,按照你的要求设置字体属性,autosize属性设成true
分别加入确定,继续,结束按钮
以下是代码:
Private Sub Form_Load()
Me.结束.Visible = False
Me.继续.Visible = False
Label2.Visible = False
End Sub
Private Sub 继续_Click()
Me.结束.Visible = False
Me.继续.Visible = False
Label2.Visible = False
Me.确定.Visible = True
Label1.Visible = True
Text1.Visible = True
End Sub
Private Sub 结束_Click()
End
End Sub
Private Sub 确定_Click()
Label2.Caption = Text1.Text &"同学,你好,祝你学好vb程序设计"
Me.结束.Visible = True
Me.继续.Visible = True
Label2.Visible = True
Label1.Visible = False
Text1.Visible = False
Me.确定.Visible = False
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(Text1.Text)
n = Val(Text2.Text)
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()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <48 Or KeyAscii >57 Then MsgBox "数据错误": KeyAscii = 0: Text1.Text = ""
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii <48 Or KeyAscii >57 Then MsgBox "数据错误": KeyAscii = 0: Text1.Text = ""
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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)