1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development help read txt files

Discussion in 'Software' started by ahug4122, 13 Oct 2004.

  1. ahug4122

    ahug4122 What's a Dremel?

    Joined:
    16 Sep 2004
    Posts:
    60
    Likes Received:
    0
    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
    :duh:
    i so need this i am doing an prac test soon and i can find any info
    plz help
     
  2. kplonk

    kplonk What's a Dremel?

    Joined:
    1 Mar 2002
    Posts:
    44
    Likes Received:
    0
    a bit more info, possible an example of what the file will look like?
     
  3. ahug4122

    ahug4122 What's a Dremel?

    Joined:
    16 Sep 2004
    Posts:
    60
    Likes Received:
    0
    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")
     
  4. kplonk

    kplonk What's a Dremel?

    Joined:
    1 Mar 2002
    Posts:
    44
    Likes Received:
    0
    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
     
  5. Hepath

    Hepath Minimodder

    Joined:
    20 Oct 2003
    Posts:
    730
    Likes Received:
    0
    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.....
     
  6. ahug4122

    ahug4122 What's a Dremel?

    Joined:
    16 Sep 2004
    Posts:
    60
    Likes Received:
    0
    on that frist one yea it works but if i put a string of nothin in the input box "i am in" :wallbash:

    what about reading the file until eof(end of file) and dumping in a array would that work????
     
  7. kplonk

    kplonk What's a Dremel?

    Joined:
    1 Mar 2002
    Posts:
    44
    Likes Received:
    0
    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
     
  8. ahug4122

    ahug4122 What's a Dremel?

    Joined:
    16 Sep 2004
    Posts:
    60
    Likes Received:
    0
    yes i dont mind how it works and casesentive would be good
     
  9. ahug4122

    ahug4122 What's a Dremel?

    Joined:
    16 Sep 2004
    Posts:
    60
    Likes Received:
    0
    IS ANY body going to help me please
     
  10. djengiz

    djengiz Pointless.

    Joined:
    16 Aug 2002
    Posts:
    1,129
    Likes Received:
    0

Share This Page