• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help...VB

IceT

Senior member
Is it possible to use the "rnd" function to have VB generates words that make sense? I have been reading the book and it only teaches me on how to randomly pick letters and make words that does not make sense. BTW, I am not asking for direct coding but just wanna know the logical steps toward it...

Another thing, how do I make VB to look into an external file like notepad which will pick up vocabs in it? I mean, like I want VB to pick up a word in the notepad and have it displayed in VB.

Your inputs are greatly appreciated.
 
OK, I have got an idea. How about asking VB to pick random words out of a dictionary file? How would I do so?
 
VB has native file reading functions but I don't know them. Instead I use the File System Object. Like this:

'this function opens a file called words.txt and gets a random
'word from the file
Function GetWord()
Dim fso

Set fso=CreateObject("Scripting.FileSystemObject&quot😉
Dim text, word As string

Set text=fs😵penTextFile("words.txt&quot😉

Randomize()

For i=0 to Int(Rnd() * 100)
text.SkipLine
Next
word=Trim(text.Readline)
Set fso=Nothing

GetWord=word
End Function


words.txt would look like this:

hello
computer
stock
offer
etc....
 
Hey KB, I tried to put your codes in a new form to test but it gave me an error message saying that it needed to have "End Sub". I have put this codes in a "Private Click_Command1()".

Anyway, would u mind explain to me what does the codes do?


----------------------------------------------------------------------------------------


Private Sub Command1_Click()


Function GetWord()
Dim fso

Set fso = CreateObject("Scripting.FileSystemObject&quot😉
Dim text, word As String
Set text = fs😵penTextFile("C:\My Documents\words.txt&quot😉

Randomize ()

For i = 0 To Int(Rnd() * 100)
text.SkipLine
Next
word = Trim(text.Readline)
Set fso = Nothing

GetWord = word
End Function
End Sub

----------------------------------------------------------------------------------------
 
Don't put the code in the commnad_click, call it from the command_click.
As for the Randomize function, highlight it and press F1 to have help.

My 2 cents
 
Back
Top