快?的模?件?
水手砚陪?晷?
- 注册
- 2003-03-04
- 消息
- 6,470
- 荣誉分数
- 0
- 声望点数
- 0
Option Explicit
Dim numArray() As Integer
Private Sub Command1_Click()
MsgBox "Maximum in the List: " & ProcessArray("MAX")
End Sub
Private Sub Command2_Click()
MsgBox "Minimum in the List: " & ProcessArray("MIN")
End Sub
Private Sub Command3_Click()
MsgBox "Toal of the List: " & ProcessArray("TOT")
End Sub
Private Sub Command4_Click()
MsgBox "Average of the List: " & ProcessArray("AVG")
End Sub
Private Sub Command5_Click()
MsgBox "Dsc Sorted List: " & ProcessArray("SORTA")
End Sub
Private Sub Command6_Click()
MsgBox "Asc Sorted List: " & ProcessArray("SORTD")
End Sub
Private Sub Command7_Click()
ReDim Preserve numArray(0 To 12) As Integer
numArray(10) = 99
numArray(11) = 1
numArray(12) = 39
List1.AddItem numArray(10)
List1.AddItem numArray(11)
List1.AddItem numArray(12)
End Sub
Private Sub Command8_Click()
'sequencial write
Dim studentname(2) As String
Dim StudentAge(2) As Integer
Dim i As Integer
studentname(0) = "Tom"
studentname(1) = "Jack"
studentname(2) = "Sheena"
StudentAge(0) = 24
StudentAge(1) = 25
StudentAge(2) = 29
Open "C:\srecord.txt" For Output As #1
For i = 0 To 2
Write #1, studentname(i), StudentAge(i)
Next i
Close #1
End Sub
Private Sub Command9_Click()
' sequencial read
Dim StdName(5) As String
Dim StdAge(5) As Integer
Dim i, j As Integer
Open "C:\srecord.txt" For Input As #1
i = 0
Do Until (EOF(1) = True)
Input #1, StdName(i), StdAge(i)
i = i + 1
Loop
Close #1
For j = 0 To i - 1
Text1.Text = Text1.Text & StdName(j) & "-" & StdAge(j) & vbNewLine
Next
End Sub
Private Sub Form_Load()
Dim i As Integer
ReDim numArray(9)
numArray(0) = 10
numArray(1) = 11
numArray(2) = 5
numArray(3) = 99
numArray(4) = 19
numArray(5) = 55
numArray(6) = 81
numArray(7) = 2
numArray(8) = 3
numArray(9) = 44
For i = 0 To 9
List1.AddItem numArray(i)
Next
End Sub
Public Function ProcessArray(ArrayAction As String)
Dim i, j, hold As Integer
Dim lastValue As Integer
Dim sortedList As String
Select Case ArrayAction
Case "MAX"
lastValue = numArray(0)
For i = 0 To UBound(numArray)
If numArray(i) > lastValue Then
lastValue = numArray(i)
End If
Next
ProcessArray = lastValue
Case "MIN"
lastValue = numArray(0)
For i = 0 To UBound(numArray)
If numArray(i) < lastValue Then
lastValue = numArray(i)
End If
Next
ProcessArray = lastValue
Case "TOT"
For i = 0 To UBound(numArray)
lastValue = lastValue + numArray(i)
Next
ProcessArray = lastValue
Case "AVG"
For i = 0 To UBound(numArray)
lastValue = lastValue + numArray(i)
Next
ProcessArray = lastValue / UBound(numArray)
Case "SORTD"
For j = 1 To 10
For i = 0 To 8
If numArray(i) < numArray(i + 1) Then
hold = numArray(i)
numArray(i) = numArray(i + 1)
numArray(i + 1) = hold
End If
Next
Next
For i = 0 To 9
sortedList = sortedList & vbNewLine & numArray(i)
Next
ProcessArray = sortedList
Case "SORTA"
For j = 1 To 10
For i = 0 To 8
If numArray(i) > numArray(i + 1) Then
hold = numArray(i)
numArray(i) = numArray(i + 1)
numArray(i + 1) = hold
End If
Next
Next
For i = 0 To 9
sortedList = sortedList & vbNewLine & numArray(i)
Next
ProcessArray = sortedList
End Select
End Function
Dim numArray() As Integer
Private Sub Command1_Click()
MsgBox "Maximum in the List: " & ProcessArray("MAX")
End Sub
Private Sub Command2_Click()
MsgBox "Minimum in the List: " & ProcessArray("MIN")
End Sub
Private Sub Command3_Click()
MsgBox "Toal of the List: " & ProcessArray("TOT")
End Sub
Private Sub Command4_Click()
MsgBox "Average of the List: " & ProcessArray("AVG")
End Sub
Private Sub Command5_Click()
MsgBox "Dsc Sorted List: " & ProcessArray("SORTA")
End Sub
Private Sub Command6_Click()
MsgBox "Asc Sorted List: " & ProcessArray("SORTD")
End Sub
Private Sub Command7_Click()
ReDim Preserve numArray(0 To 12) As Integer
numArray(10) = 99
numArray(11) = 1
numArray(12) = 39
List1.AddItem numArray(10)
List1.AddItem numArray(11)
List1.AddItem numArray(12)
End Sub
Private Sub Command8_Click()
'sequencial write
Dim studentname(2) As String
Dim StudentAge(2) As Integer
Dim i As Integer
studentname(0) = "Tom"
studentname(1) = "Jack"
studentname(2) = "Sheena"
StudentAge(0) = 24
StudentAge(1) = 25
StudentAge(2) = 29
Open "C:\srecord.txt" For Output As #1
For i = 0 To 2
Write #1, studentname(i), StudentAge(i)
Next i
Close #1
End Sub
Private Sub Command9_Click()
' sequencial read
Dim StdName(5) As String
Dim StdAge(5) As Integer
Dim i, j As Integer
Open "C:\srecord.txt" For Input As #1
i = 0
Do Until (EOF(1) = True)
Input #1, StdName(i), StdAge(i)
i = i + 1
Loop
Close #1
For j = 0 To i - 1
Text1.Text = Text1.Text & StdName(j) & "-" & StdAge(j) & vbNewLine
Next
End Sub
Private Sub Form_Load()
Dim i As Integer
ReDim numArray(9)
numArray(0) = 10
numArray(1) = 11
numArray(2) = 5
numArray(3) = 99
numArray(4) = 19
numArray(5) = 55
numArray(6) = 81
numArray(7) = 2
numArray(8) = 3
numArray(9) = 44
For i = 0 To 9
List1.AddItem numArray(i)
Next
End Sub
Public Function ProcessArray(ArrayAction As String)
Dim i, j, hold As Integer
Dim lastValue As Integer
Dim sortedList As String
Select Case ArrayAction
Case "MAX"
lastValue = numArray(0)
For i = 0 To UBound(numArray)
If numArray(i) > lastValue Then
lastValue = numArray(i)
End If
Next
ProcessArray = lastValue
Case "MIN"
lastValue = numArray(0)
For i = 0 To UBound(numArray)
If numArray(i) < lastValue Then
lastValue = numArray(i)
End If
Next
ProcessArray = lastValue
Case "TOT"
For i = 0 To UBound(numArray)
lastValue = lastValue + numArray(i)
Next
ProcessArray = lastValue
Case "AVG"
For i = 0 To UBound(numArray)
lastValue = lastValue + numArray(i)
Next
ProcessArray = lastValue / UBound(numArray)
Case "SORTD"
For j = 1 To 10
For i = 0 To 8
If numArray(i) < numArray(i + 1) Then
hold = numArray(i)
numArray(i) = numArray(i + 1)
numArray(i + 1) = hold
End If
Next
Next
For i = 0 To 9
sortedList = sortedList & vbNewLine & numArray(i)
Next
ProcessArray = sortedList
Case "SORTA"
For j = 1 To 10
For i = 0 To 8
If numArray(i) > numArray(i + 1) Then
hold = numArray(i)
numArray(i) = numArray(i + 1)
numArray(i + 1) = hold
End If
Next
Next
For i = 0 To 9
sortedList = sortedList & vbNewLine & numArray(i)
Next
ProcessArray = sortedList
End Select
End Function