教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 法律文档 >

vb程序设计教程课后答案与实验题答案(第三版)(8)

来源:网络收集 时间:2026-08-29
导读: Function prime(ByVal m As Integer) As Boolean prime = True Dim i% For i = 2 To m - 1 If (m Mod i) = 0 Then prime = False: Exit Function '注意冒号和exit的范围 Next i End Function Private Sub Command1_

Function prime(ByVal m As Integer) As Boolean prime = True Dim i%

For i = 2 To m - 1

If (m Mod i) = 0 Then prime = False: Exit Function '注意冒号和exit的范围 Next i

End Function

Private Sub Command1_Click() n = 0

For i = 6 To 100 Step 2 For j = 3 To i \\ 2 If prime(j) Then If prime(i - j) Then

List1.AddItem i & \n = n + 1 End If End If Next j Next i

Picture1.Print \和100之间共有\对素数和\End Sub

F.6

Dim a%()

Private Sub Form_Click()

Print \以内的完数为:\ For i = 1 To 1000 If IsWs(i) Then Print i; \

For j = 1 To UBound(a) Print \ Next j Print End If Next i End Sub

Function IsWs(m) As Boolean Dim s% s = 0

For i = 1 To m \\ 2

If m Mod i = 0 Then ReDim Preserve a(j) a(j) = i

j = j + 1 s = s + i End If Next i

If m = s Then IsWs = True End Function

F.7

Private Sub DeleStr(s1 As String, ByVal s2 As String) Dim i%

ls2 = Len(s2) i = InStr(s1, s2) Do While i > 0

s1 = Left(s1, i - 1) + Mid(s1, i + ls2) ' 在s1中去除s2子串 i = InStr(s1, s2) Loop End Sub

Private Sub Command1_Click() ' 调用DeleStr子过程 Dim ss1 As String ss1 = Text1

Call DeleStr(ss1, Text2) Text3 = ss1 End Sub

Private Sub Command2_Click()

End Sub

F.8

Private Sub Command1_Click() Dim maxw$

maxlen Text1 & \Text2 = maxw End Sub

Sub maxlen(s$, maxw$) Dim word$ maxw = \

Do While s <> \ i = InStr(s, \

word = Left(s, i - 1)

If Len(word) > Len(maxw) Then maxw = word s = Mid(s, i + 1) Loop

End Sub

G.1

Private Sub Command1_Click() List1.Clear

List1.AddItem Combo1

If Option1 Then List1.AddItem \ If Option2 Then List1.AddItem \ If Option3 Then List1.AddItem \ List1.AddItem Text1

If Check1 Then List1.AddItem \声卡\ If Check2 Then List1.AddItem \ If Check3 Then List1.AddItem \网络适配器\End Sub

Private Sub Text1_LostFocus() st = UCase(Trim(Text1)) le = Len(st)

If Not IsNumeric(Left(st, le - 2)) Or Right(st, 2) <> \ MsgBox \有不合法字符!\ Text1 = \

Text1.SetFocus End If End Sub

G.2

Private Sub Check1_Click()

Picture1.Font.Bold = Not Picture1.Font.Bold End Sub

Private Sub Check2_Click()

Picture1.Font.Italic = Not Picture1.Font.Bold End Sub

Private Sub Command1_Click() Picture1.Cls If Option1 Then

Picture1.Print Sin(Val(Text1)) ElseIf Option2 Then

Picture1.Print Exp(Val(Text1)) ElseIf Option3 Then

Picture1.Print Sqr(Val(Text1)) End If End Sub

Private Sub return_Click(Index As Integer) Form6.Show Unload Form2 End Sub

G.3

Private Sub HScroll1_Change() Text1 = VScroll1.Value Text2 = HScroll1.Value Text3 = HScroll2.Value

Text4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), \ Text5 = Format(Val(Text4) + Val(Text1), \End Sub

Private Sub HScroll2_Change() Text1 = VScroll1.Value Text2 = HScroll1.Value Text3 = HScroll2.Value

Text4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), \ Text5 = Format(Val(Text4) + Val(Text1), \End Sub

Private Sub VScroll1_Change() Text1 = VScroll1.Value Text2 = HScroll1.Value Text3 = HScroll2.Value

Text4 = Format(Val(Text1) * (Text3 / 100) * (Text2 / 12), \ Text5 = Format(Val(Text4) + Val(Text1), \End Sub

G.4

Dim t As Single

Private Sub Command1_Click() t = InputBox(\输入倒计时分钟数\t = t * 60

ProgressBar1.Min = 0 ProgressBar1.Max = t

ProgressBar1.Value = ProgressBar1.Max End Sub

Private Sub Command2_Click() Timer1.Interval = 1000 ProgressBar1.Visible = True Timer1.Enabled = True End Sub

Sub Timer1_Timer() Dim m%, s% t = t - 1

ProgressBar1.Value = t m = t \\ 60 s = t Mod 60

Label1 = m & \分\秒\If t = 0 Then

MsgBox \时间到!\ Timer1.Interval = 0 ProgressBar1.Visible = False End If End Sub

vb程序设计教程课后答案与实验题答案(第三版)(8).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/435676.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)