i need to be able to put a heap of words in a txt file so i can read every line until the end a if the word in the txt file is there then msgbox if not end does any body no how to do this in visual basics i so need this i am doing an prac test soon and i can find any info plz help
umm c:\pop.txt is the file to read file contains top cat hat popular cats basket i want the inputbox to check if it contains one of the words in this file and if it does then msgbox("password correct") else msgbox("worng")
to get you going creat a project and add a command button then add this to the the sub_click for that button Dim test As String Dim filetext As String test = InputBox("enter password") 'open file fnum = FreeFile Open "c:\pop.txt" For Input As fnum txt = Input$(LOF(fnum), #fnum) Close fnum filetext = txt i = InStr(filetext, test) If i > 0 Then MsgBox ("your in") Else MsgBox ("wrong password") End If
as an alternative.... Dim oFSO as New Scripting.FileSystemObject set ts = oFSO.OpenFile(filename) Dim contents as string string = ts.ReadAll() dim found as bool found = false; if (instr(lookfor, contents) > 0) found = true; or summat like that.....
on that frist one yea it works but if i put a string of nothin in the input box "i am in" what about reading the file until eof(end of file) and dumping in a array would that work????
There is another option, you can open the file for random access, and add this to an array, the problem is do you want to match exact words only and full case? K
Look on: www.planet-source-code.com www.vbforums.com www.visualbasicforum.com they have lots of examples.