當前位置:編程學習大全網 - 編程軟體 - 簡單的VB編程練習題!急求答案!

簡單的VB編程練習題!急求答案!

我可是免費的哦

1、

Private Sub Form_Click()

Dim A(1 To 10) As Integer

Dim i As Integer

Dim iMax As Integer, iPos As Integer

Me.Show

Me.Cls

Randomize

iMax = 0

For i = 1 To 10

A(i) = Fix(Rnd * 41) + 60

Print A(i) & " ";

If A(i) > iMax Then

iMax = A(i)

iPos = i

End If

Next i

Print

Print iMax

Print iPos

End Sub

如果有好幾個數壹樣的話只能找到前面的(也算是壹個缺陷吧)

2.

Private Sub Command1_Click()

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _

(ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)

Private Sub Command1_Click()

Dim a(1 To 10) As Integer

Dim i As Integer

Me.Show

Me.Cls

Randomize

For i = 1 To 10'顯示最初順序

a(i) = Fix(Rnd * 101) + 100

Print a(i) & " ";

Next i

Print

Sort VarPtr(a(1))

For i = 1 To 10'輸出結果

Print a(i) & " ";

Next i

End Sub

Private Sub Sort(ByVal Head As Long)

Dim i As Integer, j As Integer, t As Integer

Dim b(1 To 10) As Integer

CopyMemory VarPtr(b(1)), Head, 20

For i = 1 To 9 '這節是排序的

For j = i + 1 To 10

If b(i) > b(j) Then

t = b(i)

b(i) = b(j)

b(j) = t

End If

Next j

Next i

CopyMemory Head, VarPtr(b(1)), 20

End Sub

  • 上一篇:中科院光電所在哪裏
  • 下一篇:學電腦去那裏學好啊?
  • copyright 2024編程學習大全網