问答题


【参考答案】

分析:在窗体上建立好控件后,先设置控件属性,再编写事件过程。
文本框显示的内容由Text属性设置:按钮的标题由......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

问答题
[解析]在窗体上建立好控件后,先设置控件属性,再编写事件过程。 要使文本框中的字符用于算术运算,首先要利用Val将文本框中输入的数字字符转换为数字类型(文本框中的内容默认为字符串类型)。解题步骤: 第一步:建立界面并设置控件属性。 第二步:编写程序代码。 程序提供的代码: Option Explicit Private Sub C1_Click() Dim i As Integer,s As Integer Dim a As Integer,b As Integer a = Val(Text1.Text) b = Val(Text2.Text) If a>b Then i = a a = b ’ b = End If s = 0 For i = a To b ’ s = s + Next i Text3.Text = s End Sub 参考代码: Option Explicit Private Sub C1_Click() Dim i As Integer, s As Integer Dim a As Integer, b As Integer a = Val(Text1.Text) b = Val(Text2.Text) If a > b Then i = a a = b b = i End If s = 0 For i = a To b s = s + i Next i Text3.Text = s End Sub 第三步:调试并运行程序。 第四步:按题目要求存盘。 (2)[解析]在窗体上建立好控件后,先设置控件的属性,再编写事件过程。 命令按钮的Caption属性用来设置其标题,单击命令按钮触发Click事件:在文本框中显示内容通过其Text属性来设置。解题步骤: 第一步:建立界面并设置控件属性。程序中用到的控件及其属性见表4-3。 第二步:编写程序代码。 标准模块代码: Option Explicit Sub putdata(t_FileName As String,t_Str As Variant) Dim SFile As String SFile = & t_FileName Open App.Path & SFile For Output As #1 Print #1, t_Str Close #1 End Sub 参考代码: Private Sub Cmd1_CliCk() Dim temp As Long Dim i As Integer For i = 100 To 200 If i Mod 3 = 0 Then temp = temp + i End If Next Text1.Text = temp putdata out.txt ,temp End Sub 第三步:调试并运行程序。 第四步:按题目要求存盘。