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