用VB写个小程序

用VB写个小程序,第1张

Private Sub form_click()

MeShow

m = 10

n = 1

Print Int(Rnd (m - n - 1) + n + 1)

End Sub

第二题

Private Sub Form_Load()

Timer1Enabled = True

Timer1Interval = 1000

End Sub

Private Sub Timer1_Timer()

Cls

Print Format(Now, "long date") & " " & Time

End Sub

'添加一个名为label1的标签控件,并将其index设为0;再添加一个名为command1的按钮控件

Dim a(1 To 9) As Boolean

Dim win As Boolean, begin As Boolean, haveload As Boolean, start As BooleanPrivate Sub Command1_Click()

start = True: begin = False

For i = 1 To 9

a(i) = False

Next i

Form_Load

End SubPrivate Sub Form_Load()

a(9) = True

Label1(0)Visible = False

MeHeight = 4400

MeWidth = 4000

Scale (0, 0)-(3, 33)

If haveload = False Then

haveload = True: start = True

Command1Top = 3: Command1Left = 2

Command1Width = 1: Command1Height = 03

Command1Caption = "开始"

For i = 1 To 9

Load Label1(i)

Next i

End If

For i = 1 To 9

Label1(i)Height = 1

Label1(i)Width = 1

Label1(i)Visible = True

Label1(i)Top = (i - 1) \ 3

Label1(i)Left = (i - 1) Mod 3

Label1(i)Caption = Str(i)

Label1(i)BackColor = QBColor(i)

Label1(i)FontBold = True

Label1(i)FontSize = 40

Next i

Label1(9)Caption = "": Label1(9)BackColor = vbWhite

Randomize

For i = 1 To 500

r% = Int(9 Rnd) + 1

Call Label1_Click(r)

Next i

begin = True

End SubPrivate Sub Label1_Click(index As Integer)

Dim x1 As Integer, y1 As Integer

If start = True Then

If a(index) = False Then

x1 = (index - 1) Mod 3: y1 = (index - 1) \ 3

If x1 - 1 > -02 Then

If a(x1 + y1 3) = True Then Call yidong(x1 + y1 3, index)

End If

If x1 + 1 < 22 Then

If a(x1 + y1 3 + 2) = True Then Call yidong(x1 + y1 3 + 2, index)

End If

If y1 - 1 > -02 Then

If a(x1 + 1 + (y1 - 1) 3) = True Then Call yidong(x1 + (y1 - 1) 3 + 1, index)

End If

If y1 + 1 < 22 Then

If a(x1 + 1 + (y1 + 1) 3) = True Then Call yidong(x1 + 1 + (y1 + 1) 3, index)

End If

End If

win = True

For i = 1 To 8

If Val(Label1(i)Caption) <> i Then win = False

Next i

If win = True And begin = True Then MsgBox ("恭喜你成功了"): begin = False: start = False

End If

End Sub

Sub yidong(x, index)

Label1(0)Caption = Label1(index)Caption

Label1(index)Caption = Label1(x)Caption

Label1(x)Caption = Label1(0)Caption

a(index) = True: a(x) = False

Label1(0)BackColor = Label1(index)BackColor

Label1(index)BackColor = Label1(x)BackColor

Label1(x)BackColor = Label1(0)BackColor

End Sub

MsgBox上的内容是静态静态的,如果要使它倒计时,必须自己建一个Form,然后在上面拖个Timer控件来实现。然后d出时用 Form1Show vbModal 使它像MsgBox那样作为模态窗口d出就行了~~

按功能键盘上的F5 运行就可以! 如果有错误,VB会出现新窗口,用汉字写出如何错误。在新窗口内点击调试,在代码窗口中出错的代码为**背景。 最后保存程序,单击“文件”菜单——选择“保存工程”。需要保存两个窗体,首先是frm的应用程序窗体,然后是vbp的工程文件。

第一个:

Private Sub Command1_Click()

Text2Text = "我来自" + Text1Text

End Sub

第二问:

回楼主:这个需要用到截取字符串函数。

如“省”字是左起第3个数,就用语句:

(设将字符串设为a)

b=Left(a,3)

则“省”就赋值给了b

第二个也同理

以上就是关于用VB写个小程序全部的内容,包括:用VB写个小程序、求一个VB的经典小程序、初学请教VB小程序怎么编等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10054014.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存