十一、简单综合题:
Private Sub COMEXIT_Click() End End Sub
Private Sub COMSTART_Click() Dim g As Single, N As Integer, S As Single myfile1 = App.Path & "\" & "grade.DAT" myfile2 = App.Path & "\" & "average.dat" Open myfile1 For Input As #1 Open myfile2 For Output As #2 Do While Not EOF(1) Input #1, g N = N + 1 S = S + g Loop Close #1 S = S / N Write #2, S Close COMSTART.Caption = "完成" COMSTART.Enabled = False End Sub | 十二、文本加密题:
Private Sub C1_Click() Dim strinfo As String Open "in7.txt" For Input As 1 Input #1, strinfo Close #1 Text1.Text = strinfo End Sub
Private Sub C2_Click() Dim strchange As String Dim i As Integer For i = 1 To Len(Text1.Text) strchange = strchange + Chr(Asc(Mid(Text1.Text, i, 1)) + 2) Next Text1.Text = strchange End Sub
Private Sub C3_Click() Open "out7.txt" For Output As 1 Print #1, Text1.Text Close #1 End Sub | 十三、数组综合应用题:
本程序解答分二部分,一部分在窗体模块:
Option Explicit Dim a(1 To 100) Dim i As Integer Dim n As Integer Dim f As Integer Dim s As Long
Private Sub Cmd1_Click() Open App.Path & "\in.txt" For Input As #1 For i = 1 To 100 Input #1, n a(i) = n Text1.Text = Text1.Text & a(i) & " " Next i Close #1 End Sub
Private Sub Cmd2_Click() For i = 1 To 100 If a(i) <= 700 Then s = s + a(i) Next i Call putdata("out.txt", s) Text1.Text = s End Sub | 另一部分在标准模块:
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 i As Integer Dim temp As Long temp = 0
If Opt2.Value Then For i = 200 To 400 If isprime(i) Then temp = temp + i End If Next Else For i = 100 To 200 If isprime(i) Then temp = temp + i End If Next End If Text1.Text = temp End Sub
Private Sub Cmd2_Click() putdata "\out.txt", Text1.Text End Sub | 第二部分在标准模块:
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
Function isprime(t_I As Integer) As Boolean Dim J As Integer isprime = False For J = 2 To t_I / 2 If t_I Mod J = 0 Then Exit For Next J If J > t_I / 2 Then isprime = True End Function |
|
|