Sign in to follow this  
Followers 0
deef99

Lookup Value in Txt file and Display to User

5 posts in this topic

I've read around the forum but haven't really found what I am looking for. I feel it's fairly simple, so maybe someone can assist me...

I have a txt file that looks like this:

123456,800-232-2222,Project Blue

123423,800-232-2434,Red Clay

....

about 200 lines.

I need to do the following:

1. User enters the ID [which is the first 6 characters for EACH row. I believe I can do this with InputBox.

2. Now, search the text file for the ID.

3. Display the Information to the user as it appears in the file, no formatting required.

I am stuck on #2....I think I can figure out how to display...if I can figure out how to get the line of data!

Anyone got any code I can adjust that is similiar to this?

Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites



That's pretty much it I think. Hope it helps!

#include <File.au3>

Global $sLookUpID = 000008 ;Replace with your input method

Dim $aRecords

If Not _FileReadToArray("C:\Temp.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading file to Array     error:" & @error)
   Exit
EndIf

For $x = 1 to $aRecords[0]
    If StringLeft($aRecords[$x], 6) = $sLookUpID Then
        Msgbox(0, "ID Found", $aRecords[$x])
    Else
        ContinueLoop
    EndIf
Next

Share this post


Link to post
Share on other sites

Ok...based on what you gave me, this is what I have so far. However, I need it to JUST DISPLAY the line for the ID that the user entered...not every line. Is there a way to do that?

BTW...thank you very much for your fast and helpful response!

#include "File.au3"

#include "String.au3"

#include <Array.au3>

Opt("TrayMenuMode", 1) ;No icon in tray

$file = "c:\avaya\logins.txt"

Global $sLookUpID = InputBox("PHONE", "Enter Your Phone Extension:")

Dim $aRecords

If Not _FileReadToArray($file,$aRecords) Then

MsgBox(4096,"Error", " Error reading file to Array error:" & @error)

Exit

EndIf

For $x = 1 to $aRecords[0]

If StringLeft($aRecords[$x], 7) = $sLookUpID Then

Msgbox(0, "ID Found", $aRecords[$x])

Else

Msgbox(0, "NOT Found", $aRecords[$x])

ContinueLoop

EndIf

Next

Share this post


Link to post
Share on other sites

The only thing that shows you every line here is your MsgBox in the else case in the For loop. If you remove that msgbox, only the one that fit the required id will show up.

Share this post


Link to post
Share on other sites

Just need:

#include "File.au3"
#include "String.au3"
#include <Array.au3>
Opt("TrayMenuMode", 1) ;No icon in tray
$file = "c:\avaya\logins.txt"
Global $sLookUpID = InputBox("PHONE", "Enter Your Phone Extension:") 
Dim $aRecords
If Not _FileReadToArray($file,$aRecords) Then
MsgBox(4096,"Error", " Error reading file to Array error:" & @error)
Exit
EndIf
For $x = 1 to $aRecords[0]
If StringLeft($aRecords[$x], 7) = $sLookUpID Then Msgbox(0, "ID Found", $aRecords[$x])
Next

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0