40 likes | 49 Views
Miscellaneous Topics. Random Numbers. The Visual Basic function Rnd is used to return psuedo -random values (0 <= Rnd < 1 )
E N D
Random Numbers • The Visual Basic function Rnd is used to return psuedo-random values (0 <= Rnd < 1 ) • Use Randomize to initialize VB's random number generator. This is called seeding. To avoid generating the same sequence of psuedo-random values, call Randomize before you call Rnd • RandomizeVALUE=Int((HIGHESTNUM - LOWESTNUM) * Rnd + LOWESTNUM) • where VALUE is your variableHIGHESTNUMBER is the highest number for random generationLOWESTNUMBER is the lowest number for random generation • To Generate a Random number from 1 to 10: • RandomizeVALUE=Int((10 - 1) * Rnd + 1)
Reading Text from a file Open App.Path + "employee.dat" For Input As #1 Input #1, emp_num For i = 1 To emp_num Input #1, Id(i), Name(i), Salary(i) Next Close
Writing Text to a file Open App.Path + "employee.dat" For Output As #1 Write #1, emp_num For i = 1 To emp_num Write #1, Id(i), Name(i), Salary(i) Next Close