Re: Visual Basic Express Edition Need advice
Evoluator
Well if I have understood you right, this is my advise:
Solution 1:
'When the exit button is envoked
Dim LetterArray As Char() = {"a", "A", "b", "B", "c", "C", "d"} '.....
Dim Loops As Integer = 0
Do Until Loops > 10 '10 specifies 10 files to be created
Dim FileName As Char()
For ii As Integer = 0 To 16 '16 specifies the maximum length of the file name
Randomize()
FileName(ii) = (LetterArray(CInt(Int((letterArray.Length - 1) * Rnd())) - 1))
Next
My.Computer.FileSystem.WriteAllText("The desired file location\" & FileName.ToString, "The contents you want to write", False) 'False = Creates a new file, True = adds the contents to existing file (if any)
Loops += 1
Loop
Solution 2:
Instead of creating a LetterArray you could use a byte array (Dim ByteArray As Byte())
and use:
Dim loops As Integer = 0
Do Until loops > 10 'Specified 10 files to be created
Randomize()
Dim byteArray As Byte() = New Byte(31) {} ' 31 = 32 - 1 Which is the length of the desired file name (16 characters)
For iii As Integer = 0 To 31 '31 specifies the maximum length of the file name = (31 +1 ) / 2
Randomize()
byteArray(iii) = (CInt(Int(256 * Rnd())))
' Don't go greddy and use a value higher than 256 Exceptions would be thrown to your face
Next
Dim FileName As String = Nothing
Dim strBuilder As Char() = New Char(15) {} '15 = 16 -1 Because the FileName is assumed to be 16 characters long
For i As Integer = 0 To byteArray.Length / 2 - 1
strBuilder(i) = BitConverter.ToChar(byteArray, 2 * i)
Next
For i As Integer = 0 To byteArray.Length / 2 - 1
FileName = FileName & strBuilder(i)
Next
My.Computer.FileSystem.WriteAllText("The desired file location\" & FileName.ToString, "The contents you want to write", False)
'False = Creates a new file, True = adds the contents to existing file (if any)
loops += 1
Loop
Solution two makes such random filenames, even if you know the file name you think it is random!!! But seriously it is random to an extent which your will be surprised when you see the file names generated!
I hope the code was helpful