Home > Software engineering >  VB exercises great god answers
VB exercises great god answers

Time:11-12

I am a novice, please answer, it is an array,

CodePudding user response:

Dim arr
Dim Max
Arr=array (1,5,4,3,2,7,9,8,11,4)
Max=0
Dim I
For I=1 to 9
If arr (Max) & lt; Arr (I) then Max=I
Next
Dim t
If Max & gt; 0
T=arr (Max)
Arr (Max)=arr (Max - 1)
Arr (Max - 1)=t
Msgbox arr (Max) & amp; ", "& amp; max

CodePudding user response:

I also wrote a, the code is as follows:
 
Option Explicit

Dim arr
Arr=array (10,9,8,7,6,5,4,1,2,3)

Printarray (arr)

Dim minIndex
Minindex=0

Dim I
For I=lbound (arr) To ubound (arr)
If arr (minindex) & gt; Arr (I) Then
Minindex=I
End the If
Next

Msgbox "minimum number:" & amp; Arr (minindex) & amp; "The subscript:" & amp; Minindex

If minindex & gt; 0 Then
Dim temp
Temp=arr (minindex)
Arr (minindex)=arr (minindex - 1)
Arr (minindex - 1)=temp
End the If

Printarray (arr)

Sub printarray (ByRef arr)
Dim MSG
MSG=""

Dim I
For I=lbound (arr) To ubound (arr)
MSG=MSG & amp; Arr (I) & amp; "
"Next

Msgbox MSG
End Sub

Download address:
Link: https://pan.baidu.com/s/1txK1364SnWfUm4fn3BMaSA
The extracted code: yytz

Run the example:



CodePudding user response:

refer to the second floor milaoshu1020 response:
I also wrote a, the code is as follows:
 
Option Explicit

Dim arr
Arr=array (10,9,8,7,6,5,4,1,2,3)

Printarray (arr)

Dim minIndex
Minindex=0

Dim I
For I=lbound (arr) To ubound (arr)
If arr (minindex) & gt; Arr (I) Then
Minindex=I
End the If
Next

Msgbox "minimum number:" & amp; Arr (minindex) & amp; "The subscript:" & amp; Minindex

If minindex & gt; 0 Then
Dim temp
Temp=arr (minindex)
Arr (minindex)=arr (minindex - 1)
Arr (minindex - 1)=temp
End the If

Printarray (arr)

Sub printarray (ByRef arr)
Dim MSG
MSG=""

Dim I
For I=lbound (arr) To ubound (arr)
MSG=MSG & amp; Arr (I) & amp; "
"Next

Msgbox MSG
End Sub

Download address:
Link: https://pan.baidu.com/s/1txK1364SnWfUm4fn3BMaSA
The extracted code: yytz

Run the example:




Before this, I wrong thought strives for the biggest
  • Related