VB实验2 答案顺序结构程序设计Word文档下载推荐.docx
- 文档编号:8158251
- 上传时间:2023-05-10
- 格式:DOCX
- 页数:12
- 大小:503.21KB
VB实验2 答案顺序结构程序设计Word文档下载推荐.docx
《VB实验2 答案顺序结构程序设计Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《VB实验2 答案顺序结构程序设计Word文档下载推荐.docx(12页珍藏版)》请在冰点文库上搜索。
TextBox3.Text=Math.(Val()+Val(TextBox2.Text))
TextBox4.Text=(TextBox3.Text)
TextBox5.Text=(Val(TextBox3.Text),2)
P23
IfNotIsNumeric(TextBox1.Text)Then
MsgBox("
输入有非数字字符,请重新输入"
,"
数据检验"
)
TextBox1.Text="
"
TextBox1.Focus()
EndIf
三、实验步骤及结果:
(实验结果截图,代码拷贝过来。
1.
(1)
即时窗口=视图/其他窗口/输入immed
?
16/4-2^5*8/4mod5\2
4.0
int(199.555*100+0.5)/100
199.56
123+mid("
123456"
3,2)
157.0
ucase(mid("
adcdefgh"
3,4))
CDEF"
今天是"
+today()
今天是-3-10"
123&
instr(“”,””)
1235"
10>
5and“人”>
”人民”ortrue>
false
False
10mod3=1or"
电脑"
<
>
计算机"
True
math.Round(123.456,2)+math.Sqrt(9)
126.46
abcdefg"
like"
*de*"
or"
A"
="
a"
and2>
1
(2)
第一个函数
x=1:
y=14
math.Sin(30*3.14/180)+(math.Exp
(2)+math.Log(10))/math.Sqrt(x+y+1)
2.9226804006242761
第二个函数
y=0.5
math.Cos(75*3.14/180)+math.sqrt(x+math.Exp(3))/math.abs(x-y)-math.Log(3*x)
8.3446458014779559{Double}
Double:
8.3446458014779559{Double}
(3)
代码:
PublicClassForm1
PrivateSubTextBox1_TextChanged(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesTextBox1.TextChanged
TextBox3.Text=Math.Sqrt(Val(TextBox1.Text)+Val(TextBox2.Text))
TextBox4.Text=Int(Val(TextBox3.Text))结果取整
TextBox5.Text=Math.Round(Val(TextBox3.Text),2)结果取两位小数
EndSub
PrivateSubTextBox2_TextChanged(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesTextBox2.TextChanged
TextBox4.Text=Int(Val(TextBox3.Text))
TextBox5.Text=Math.Round(Val(TextBox3.Text),2)
EndClass
2.中等题
(1)
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
Randomize()随机
TextBox1.Text=Int(Rnd()*(99-10+1)+10)
TextBox2.Text=Int(Rnd()*(999-100+1)+100)
TextBox3.Text=Int(Rnd()*(9999-1000+1)+1000)
EndSub
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
TextBox4.Text=(Val(TextBox1.Text)+Val(TextBox2.Text)+Val(TextBox3.Text))/3
TextBox4.Text=Format(Val(TextBox4.Text),"
0.0"
)取一个小数点
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
End
PrivateSubTextBox1_KeyPress(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.KeyPressEventArgs)HandlesTextBox1.KeyPress
Dimn,a,b,c,d,mAsInteger
IfAsc(e.KeyChar)=13Then
n=Val(TextBox1.Text)
a=nMod10取个位
b=n\10Mod10取十位
c=n\100Mod10取百位
d=n\1000取千位
2:
m=a*1000+b*100+c*10+d
Label2.Text="
逆序后整数为"
&
m
IfNotIsNumeric(TextBox1.Text)Then
EndIf
PrivateSubTextBox1_MouseUp(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)HandlesTextBox1.MouseUp
PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load
代码
PrivateSubLabel2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesLabel2.Click
Label2.Text=Button1.Text&
"
函数的结果"
TextBox2.Text=Len(TextBox1.Text)求字符串的长度
PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click
Label2.Text=Button5.Text&
Dimb$
b=InputBox("
输入查找字串"
"
inster函数"
TextBox2.Text=InStr(TextBox1.Text,b)
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click
Label2.Text=Button4.Text&
Dima%
a=Val(InputBox("
请输入重复出现的次数(必须为数字)"
strdup函数"
))
TextBox2.Text=StrDup(a,TextBox1.Text)
Label2.Text=Button2.Text&
TextBox2.Text=Trim(TextBox1.Text)
Label2.Text=Button3.Text&
Dimc%
c=Val(InputBox("
从字符串左边第几个位置开始取"
mid函数"
Dimd%
d=Val(InputBox("
向右取几个字符"
Ifc>
0And0<
dAndd<
(Val(TextBox1.Text)-c+1)Then
TextBox2.Text=Mid(TextBox1.Text,c,d)
PrivateSubButton6_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton6.Click
Label2.Text=Button6.Text&
Dimm$字符串
m=InputBox("
用什么来代替"
replace函数"
Dimn$
n=InputBox("
代替什么字符"
TextBox2.Text=Replace(TextBox1.Text,n,m)m代替n
(4)
vb
画图
Word
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
Shell("
C:
\ProgramFiles(x86)\MicrosoftVisualStudio8\Common7\IDE\devenv.exe"
1)
%windir%\system32\mspaint.exe"
D:
\ProgramFiles\MicrosoftOffice2007\MicrosoftOfficeWordPortable.exe"
四、实验心得:
1.即时窗口=视图/其他窗口/输入immed
2.TextBox4.Text=Int(Val(TextBox3.Text))结果取整
3.Randomize()随机
TextBox1.Text=Int(Rnd()*(99-10+1)+10)2位数
TextBox2.Text=Int(Rnd()*(999-100+1)+100)3位数
TextBox3.Text=Int(Rnd()*(9999-1000+1)+1000)4位数
Int(rnd()*(上界-下界+1)+下界)
4.TextBox4.Text=Format(Val(TextBox4.Text),"
5.Dimn,a,b,c,d,mAsInteger
6IfNotIsNumeric(TextBox1.Text)Then
Msgbox(提示,按钮样式,标题),省略部分要用逗号占位符跳过
7.inputbox(提示,标题,默认值)
8.shell函数在书本P52
是调用各种应用程序
Shell(路径,窗口类型)
9在VB上表示变量X在一定数值范围内(1<
x<
=10)
应该X>
1ANDX<
=10!
!
教师评语:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB实验2 答案顺序结构程序设计 VB 实验 答案 顺序 结构 程序设计