Home > Software engineering >  Tell me the steps, vb programming, have bosses had better have the code, thank you
Tell me the steps, vb programming, have bosses had better have the code, thank you

Time:02-17

A in your class personnel as the foundation, random write a class named program, can't repeat roll, roll call results to write to file

CodePudding user response:

Step1:
A class of personnel list, need to have a field corresponding to the people in the class, this field can be a student number;
Step2:
Call random function, the range between the scope of this student id, of course not repeat;
Step3:
Random named program open, to create a code written to the file

CodePudding user response:

1. The name is into an array
2. Record the number of random class a, the default for the length of the array
3. A random generation 0 ~ a integer I
4. The array arr (I) written to the file, at the same time will be arr (I) and arr (a) exchange, and a -
5. Repeat 3

CodePudding user response:

 Option Explicit 
Dim arr
Dim As a Integer
'initialize
Private Sub Form_Load ()
Arr=Split (" A001 A002, A003, A004, A005, A006 ", ", ")
A=UBound (arr)
End Sub
A random out 'point time,
Private Sub Command1_Click ()
Dim I As an Integer, intRnd As an Integer, strTmp As String

If a=1 Then
MsgBox "all members random once!" , vbExclamation
The Exit Sub
End the If

Randomize
IntRnd=Int (Rnd * a)

Me. Print "index:" & amp; IntRnd, arr (intRnd), "extraction front:" & amp; The Join (arr, ", ") & amp; "To participate in the random" & amp; A + 1 & amp; "A", 'output and written to the file
The Open ". TXT "For Append As # 1
Print # 1, arr (intRnd)
Close # 1

StrTmp=arr (intRnd)
Arr (intRnd)=arr (a)
Arr=strTmp (a)
A=a - 1
Me. Print "after the extraction:" & amp; The Join (arr, ", ") & amp; "The rest" & amp; A + 1 & amp; "A"
End Sub


CodePudding user response:


In a way of thinking, the students name written on a deck of CARDS, then shuffle shuffled, lift one teacher with this deck of CARDS to read names, whether to reach you randomly and don't repeat the request?
Then see how to reshuffle to try to "random"
Recommend simple efficient method and mathematical proof knuth shuffle
The following is a routine, but does not contain parts of your document named results,

A form a button to copy the following code

 
Option Explicit
Dim arr () As String
'initialize
Private Sub Form_Load ()
Arr=Split (" A001 A002, A003, A004, A005, A006 ", ", ")
End Sub

Private Sub Command1_Click ()
'knuth shuffle algorithm to disrupt the order
Dim As Integer I
For I=UBound (arr) To LBound (arr) Step - 1
Dim STRTMP As String, irnd As Integer
Irnd=Rnd (Now ()) * I
STRTMP=arr (I)
Arr (I)=arr (irnd)
Arr (irnd)=STRTMP
Next

'output named order
For I=LBound (arr) To UBound (arr)
Me. Print arr (I),
Next
Me. Print
End Sub

  • Related