Home > Software engineering >  For everyone a great god help!
For everyone a great god help!

Time:09-27

Vb is a beginner, run into a problem now, asking our great god help me! I thank you very much! Operation interface is as follows:

Sort program after the operation, the user clicks on the "start" button, after the emergence of an input box, the request user input the number of array elements, the corresponding program randomly generated number 2 digits, and put them one by one shown on the left side of list1 list box, and then the index to each array element according to its corresponding array element value from big to small order, will the subscript displayed in the list box on the right 2, I wrote the code, but there is a big flaw: when each array element value is not in at the same time, the subscript display is completely normal; When the same array element, the subscript in the display will appear empty project, the code is as follows:
Private Sub Command1_Click ()
Dim I %, j %
Dim n % 'the number of array elements
Dim a % ()
N=Val (InputBox (" please enter the number of array elements "))
ReDim a % (1 To n)
Randomize
For I=1 To n
A (I)=Int (100 * Rnd + 10)
List1. AddItem Str (a) (I) & amp; "" & amp; I
List2. AddItem ""
Next I
Dim, k % m %
For I=1 To n
K=1
For j=1 To n
If a (I) & lt; A (j) Then k=k + 1
Next j
List2. List (k - 1)=Str (I)
Next I
End Sub
Please master directions fan law!

CodePudding user response:

 Private Sub Command1_Click () 
Dim n As an Integer, I, As an Integer, j As an Integer, k As Integer
Dim (a) As an Integer
N=Val (InputBox ("?" ))
ReDim a (1 To n)
Dim (b) As an Integer
ReDim b (1 To n)
22: a (1)=a (2)=24: a (3)=23:23: a (4)=a (5)=14
Randomize
For I=1 To n
A (I)=Int (Rnd * 90 + 10)
List1. AddItem a (I) & amp; "" & amp; I
B (I)=I
Next I
Dim t As Integer
For I=1 To n
For j=I + 1 To n
If a (b) (I) & lt; (j) a (b) Then
T=b (j) : b (j)=b (I) : (I)=b t
End the If
Next j
List2. AddItem a (b) (I) & amp; "" & amp; B (I)
Next I
End Sub

CodePudding user response:

reference 1st floor myownroc response:
 Private Sub Command1_Click () 
Dim n As an Integer, I, As an Integer, j As an Integer, k As Integer
Dim (a) As an Integer
N=Val (InputBox ("?" ))
ReDim a (1 To n)
Dim (b) As an Integer
ReDim b (1 To n)
22: a (1)=a (2)=24: a (3)=23:23: a (4)=a (5)=14
Randomize
For I=1 To n
A (I)=Int (Rnd * 90 + 10)
List1. AddItem a (I) & amp; "" & amp; I
B (I)=I
Next I
Dim t As Integer
For I=1 To n
For j=I + 1 To n
If a (b) (I) & lt; (j) a (b) Then
T=b (j) : b (j)=b (I) : (I)=b t
End the If
Next j
List2. AddItem a (b) (I) & amp; "" & amp; B (I)
Next I
End Sub

There was a line a (0)=22: a (1)=24 what please ignore...

CodePudding user response:

That you can think of some way to randomly in the repeat, take it again, know not to repeat,

CodePudding user response:

Teacher, is the last time I didn't say very clearly, now I to the specific requirements of the questions presented to you in the form of capture, please the teacher to give directions, thank you!

CodePudding user response:

 Private Sub Command1_Click () 
'is not empty, only a test, disdain... '
List1. Clear
List2. Clear

Dim I %, j %
Dim n % 'the number of array elements
Dim a % ()
N=Val (InputBox (" please enter the number of array elements "))
ReDim a % (1 To n)
Randomize
For I=1 To n
A (I)=Int (100 * Rnd + 10)
List1. AddItem Str (a) (I) & amp; "" & amp; I
List2. AddItem ""
Next I
Dim, k % m %
For I=1 To n
K=1 'is used to statistics a (I) after the sorting is the first name of k'
For j=1 To n
If a (I) & gt; A (j) Then k=k + 1 'so you should judge is smaller than a (I) the number of'
Next j

'add this period, many of the same (I) a tied for first k value, then the corresponding position occupied in List2 to the row'
While List2. List (k - 1) & lt;> "
"K=k + 1
Wend

List2. List (k - 1)=Str (a) (I) the 'correct one'
Next I
End Sub

CodePudding user response:

Use ArrayList
  • Related