100个vb精彩小程序源码实例,vb编程代码100例
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 再按回车即可取消关机命令。
vb程序设计实例100
试题一.1
Private Sub Form_Click()
Print fs_sum(100)
End Sub
Function fs_sum(ByVal n As Integer) As Single
Dim s!, nc! '和与倒数
s=0
For i = 1 To n
nc = 1 / i
s = s + nc
Next i
fs_sum = s
End Function
试题一.2
Private Sub Form_Click()
For i = 1 To 4
Print Space(4 - i);
For j = 1 To i
Print "* ";
Next j
Next i
End Sub
待续,未完...
vb实用小程序源代码
Private Sub mianji()
Dim a As Single, b As Single, c As Single
a = Val(InputBox("请输入三角形的边a:", "输入"))
b = Val(InputBox("请输入三角形的边b:", "输入"))
c = Val(InputBox("请输入三角形的边c:", "输入"))
If (a + b) = c Or b + c =a Or a + c = b Then
MsgBox "三条边不能构成三角形,请重新输入!", , "注意"
Exit Sub
End If
q = (a + b + c) / 2
s = Sqr(q * (q - a) * (q - b) * (q - c))
Print "三角形的面积是: "; s
End Sub
这个是由键盘输入3个数,试编程判断它们是否可以构成一个三角形。如果能构成一个三角形,请计算该三角形的面积。
求简单的VB小游戏源代码
rem
窗体创建三个单选框按钮,option1、option2、option3
private
sub
form_activate()
option1.caption
=
"石头"
option2.caption
=
"剪刀"
option3.caption
=
"布"
option1.value
=
false
option2.value
=
false
option3.value
=
false
end
sub
private
sub
option1_click()
randomize
select
case
int(3
*
rnd)
case
0:
msgbox
"对方也出石头!继续!"
case
1:
msgbox
"哈哈!你赢了!对方出的是剪刀!奖励你一个苹果!"
case
2:
msgbox
"你输了!对方出的是布哦!不好意思,苹果给对方了哈!"
end
select
option1.value
=
false
end
sub
private
sub
option2_click()
randomize
select
case
int(3
*
rnd)
case
0:
msgbox
"你输了!对方出的是石头哦!不好意思,苹果给对方了哈!"
case
1:
msgbox
"对方也出剪刀!继续!"
case
2:
msgbox
"哈哈!你赢了!对方出的是布!奖励你一个苹果!"
end
select
option2.value
=
false
end
sub
private
sub
option3_click()
randomize
select
case
int(3
*
rnd)
case
0:
msgbox
"哈哈!你赢了!对方出的是石头!奖励你一个苹果!"
case
1:
msgbox
"你输了!对方出的是剪刀哦!不好意思,苹果给对方了哈!"
case
2:
msgbox
"对方也出布!继续!"
end
select
option3.value
=
false
end
sub
vb编程实例
下面的代码是利用三边计算三角形面积
Private Sub Command1_Click()
a=val(text1.text)
b=val(text2.text)
c=val(text3.text)
p=(a+b+c)/2
s=sqr(p*(p-a)*(p-b)*(p-c))
if a+bc and b+ca and a+cb then
text4.text="三角形的面积是:" s
else
text4.text="不能构成三角形"
end if
end sub
下面是计算两数之和的代码
private sub command1_click()
a=val(text1.text)
b=val(text2.text)
text3.text=a+b
end sub