有趣的vb小程序代码(有趣的vb小程序代码有哪些)

http://www.itjxue.com  2023-03-19 03:10  来源:未知  点击次数: 

VB猜数字游戏程序代码

Option?Explicit

Private?Sub?Command1_Click()

On?Error?Resume?Next

Dim?I?As?Integer

I?=?MsgBox("下面游戏开始,你准备好了吗?",?vbYesNo)

If?I?=?6?Then?Frame1.Visible?=?True:?Text1?=?""?Else?Frame1.Visible?=?False

Text1.SetFocus

Randomize?(Timer)

Text2?=?Int(Rnd()?*?10)?+?1

Text3?=?0

End?Sub

Private?Sub?Command2_Click()

End

End?Sub

Private?Sub?Form_Load()

Me.Height?=?5000

Me.Width?=?10500

Me.BorderStyle?=?1

Me.Caption?=?"猜数游戏"

Label1.Left?=?0

Label1.Top?=?1000

Label1.Caption?=?"欢迎进入猜数游戏"

Label1.FontName?=?"楷体_GB2312"

Label1.ForeColor?=?H80FF

Label1.FontSize?=?48

Command1.Caption?=?"开始"

'Command1.Default?=?True

Command2.Caption?=?"退出"

Command2.Cancel?=?True

End?Sub

Private?Sub?Text1_KeyPress(KeyAscii?As?Integer)

If?(KeyAscii??48?Or?KeyAscii??57)?And?KeyAscii??13?Then?KeyAscii?=?0

If?KeyAscii?=?13?Then

??If?Text1??""?Then?Jysz

End?If

End?Sub

Private?Function?Jysz()?As?Boolean

??Text3?=?Val(Text3)?+?1

??If?Val(Text1)?=?Val(Text2)?Then

????MsgBox?"猜对了,你真棒"??Chr(13)??Chr(10)??"请猜下一个……"

????Command1_Click

??ElseIf?Val(Text1)??Val(Text2)?Then

????MsgBox?"猜大了。"

??Else

????MsgBox?"猜小了。"

??End?If

??Text1?=?""

??If?Val(Text3)?=?3?Then

??MsgBox?"呵呵,没猜对!正确的答案是"??Text2??"。别气馁,再来!"

??Command1_Click

??End?If

End?Function

具体程序已经发到你的邮箱songxing_cool@yahoo.com.cn

更多代码请参阅我的博客

用VB编写一个小程序

Dim a, b

Private Sub Command1_Click()

End

End Sub

Private Sub Form_Load()

Text.Text = "Visual Basic程序设计"

Command1.Caption = "结束"

Text.Left = 0: Text.Top = 0: Text.Width = 0.5 * Form1.Width

Text.Height = 0.5 * Form1.Height

a = Form1.Width - Command1.Left

b = Form1.Height - Command1.Top

End Sub

Private Sub Form_Resize()

Text.Left = 0: Text.Top = 0: Text.Width = 0.5 * Form1.Width

Text.Height = 0.5 * Form1.Height

Command1.Left = Form1.Width - a

Command1.Top = Form1.Height - b

End Sub

注意,各变量名,控件名保持一致,你题目中的文本框名称为text

请高手编个VB小程序 代码短一点 什么都行 ,老师要求交的期末作业,我初学者 什么也不懂 简单点的,

给你个计算器的代码

一个单选按钮组,里面有4个单选按钮

3个文本框

1个命令按钮

代码如下

Private Sub Command1_Click()

Dim a, b, r As Double

Dim x As Integer

a = Val(Text1.Text)

b = Val(Text2.Text)

r = 0

If (Option1(0).Value) Then

r = a + b

ElseIf (Option1(1).Value) Then

r = a - b

ElseIf (Option1(2).Value) Then

r = a * b

ElseIf (Option1(3).Value) Then

r = a / b

End If

Text3 = r

End Sub

Private Sub Form_Load()

Option1(0).Value = True

End Sub

vb有趣小程序

整人的小程序,会弹出对话框提示:快说我是猪,不输入的话会在1分钟之内自动关机,输入的话,当让会被笑话啦,呵呵

将以下文字粘贴到记事本上后将后缀名改为:vbe,然后双击即可!(里面的那些词语可以自行修改),经测试肯定可以使用。

on error resume next

dim WSHshellA

set WSHshellA = wscript.createobject("wscript.shell")

WSHshellA.run "cmd.exe /c shutdown -r -t 60 -c ""说[我是猪],不说[我是猪],不信,试试···"" ",0 ,true

dim a

do while(a "我是猪")

a = inputbox ("说[我是猪],就不关机,快撒,说 ""[我是猪]"" ","说不说","不说",8000,7000)

msgbox chr(13) + chr(13) + chr(13) + a,0,"MsgBox"

loop

msgbox chr(13) + chr(13) + chr(13) + "早说就行了嘛"

dim WSHshell

set WSHshell = wscript.createobject("wscript.shell")

WSHshell.run "cmd.exe /c shutdown -a",0 ,true

msgbox chr(13) + chr(13) + chr(13) + "承认就好了嘛"

阻止关机的方法:按键盘上的Win键+R键,在出来的窗口中输入:shutdown -a 再按回车即可取消关机命令。

(责任编辑:IT教学网)

更多

推荐java认证文章