Help...VB

IceT

Senior member
Aug 14, 2000
320
0
0
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.
 

IceT

Senior member
Aug 14, 2000
320
0
0
OK, I have got an idea. How about asking VB to pick random words out of a dictionary file? How would I do so?
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
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")
Dim text, word As string

Set text=fso_OpenTextFile("words.txt")

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....
 

IceT

Senior member
Aug 14, 2000
320
0
0
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")
Dim text, word As String
Set text = fso_OpenTextFile("C:\My Documents\words.txt")

Randomize ()

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

GetWord = word
End Function
End Sub

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

IceT

Senior member
Aug 14, 2000
320
0
0
Also, when I pasted the codes in, Randomize() was highlighted in red.
 

Oli

Member
Jul 20, 2000
98
0
0
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