【2017年整理】vb新手事例.doc
文本预览下载声明
Vb编程 示例
猜数字游戏
控件名称 属性
form1 caption(“猜数游戏“) ,maxbutton(false)
label1 caption (”请输入一个数字(0-100):‘)
label2 caption (“”) autosize (true) forecolor(红色)
text text(“”)
command1 caption(“开始游戏”)
command2 caption (“让我猜),default(true )
command3 caption (” 退出游戏“) ,cancel (true )
private sub command1 _click ()
dim n as integer
randomize
n = int (rnd * 101)
form1.tag = n
command1.enabled = false
text1.setfocus 文本框获得焦点
end sub
private sub command2 _click ()
dim m as integer
m =val(text1.text )
if m form1.tag then
label2.caption = 你猜的数字太大了!
下面两条语句实现选中文本框内容
text1.selstart = 0
text1.sellength = len(text1.text)
elseif m form1.tag then
label2.caption = 你猜的数字太小了!
下面两条语句实现选中文本框内容
text1.selstart = 0
text1.sellength = len(text1.text)
else
label2.caption = 恭喜你!猜对了!
command1.enabled = true
end if
end sub
private sub command3 _click ()
unload me
end sub
private sub form_ unload (cancel as integer)
dim n as integer
当用户退出系统时,提示用户是否退出
n = msgbox (确实要退出游戏吗? , vbyesno = vbformtion ,游戏提示)
if n= vbno then
cancel = true
end if
end sub
运行时的图片为 ;
制作一个登录窗口
制作一个登陆窗口,在窗口上绘制2个标签控件,两个文本控件 2个命令按钮
对象 属性
label1 caption ( 请输入账号), autosize (ture )
label2 caption ( 请输入密码), autosize (ture )
tetusername text (清空),maxlenth (10) ,tooltiptext (账号不超过10位)
tetpasssword text (清空),passwordchar (*)
command1 caption(确定OK) , default (true )
command2 caption(取消cancer),cancer( true)
form1 caption(登录窗口),maxbutton(false)
运行时 如图
制作一个要求 输入年龄和性别的窗口
要求用户输入年龄和性别
private sub command1_click ()
dim age as integer,sex as string
age = val(text1.
显示全部