五、倒计数器
Private Sub C1_Click(Index As Integer) Select Case Index Case 1 Timer1.Enabled = False Case 0 Timer1.Enabled = True End Select End Sub
Private Sub Form_Load()
End Sub
Private Sub Timer1_Timer() Text1.Text = Text1.Text + 1 End Sub | 六、文本框的使用
Private Sub C1_Click() Open App.Path & "\out7.txt" For Output As #2 Print #2, Text1.Text Close #2 End Sub
Private Sub Form_Load() Open App.Path & "\in7.txt" For Input As #1 Do While Not EOF(1) Input #1, mystring Text1.Text = Text1.Text + mystring Loop Close #1 Text1.Text = "计算机等级考试" + Text1.Text End Sub | 七、求某类数的和等:
Private Function fun(a As Integer) As Integer s% = 0 For i% = 500 To 600 If Int(i% / a) = i% / a Then s% = s% + i% End If Next fun = s% End Function
Private Sub C1_Click()
If Op1.Value Then Text1 = fun(7) End If If Op2.Value Then Text1 = fun(3)
End Sub
Private Sub Form_Unload(Cancel As Integer) Open "out7.txt" For Output As #1 Print #1, Op1.Value, Op2.Value, Text1.Text Close #1 End Sub | 八、文本框的使用
Private Sub C1_Click() Open App.Path & "\in7.txt" For Input As #1 Do While Not EOF(1) Input #1, mystring Text1.Text = mystring Loop Close #1 End Sub
Private Sub C2_Click() Text1.Text = UCase(Text1.Text) End Sub
Private Sub C3_Click() Open App.Path & "\out7.txt" For Output As #2 Print #2, Text1.Text Close #2 End Sub | 九、文本框应用第二例:
第一部分,窗体程序部分:
Dim a(100) As Integer Private Sub Cmd1_Click() Open App.Path & "\in.txt" For Input As #1 Text1.Text = "" For i = 1 To 100 Input #1, a(i) Text1.Text = Text1.Text & a(i) & Space(1) Next i Close #1
End Sub
Private Sub Cmd2_Click() Text1.Text = "" s = 0 For i = 1 To 100 If a(i) Mod 2 <> 0 Then Text1.Text = Text1.Text & a(i) & Space(1) s = s + a(i) End If Next putdata s End Sub | 第二部分,模块程序部分:(如没有,需要自行添加一个标准模块)
Sub putdata(ByVal a As Integer) Dim sFile As String sFile = "\out.txt" Open App.Path & sFile For Output As #1 Print #1, a; Close #1 End Sub |
|
|