Jump to content
Macro Express Forums

How can I find a variable in a .txt Text file


svallie

Recommended Posts

I have a tab delimited text file something like this:

 

============

 

John 5

Tim 6

Sally 3

Fred 9

Bill 2

Bob 11

Robert 10

Tom 7

Elliott 1

 

============

 

I have a macro that grabs a string variable (%T1%) from another file. For example [Variable set String %T1% = "Sally"]. I am trying to find a way to have the macro look in this .txt file and find %T1% (Sally) and use the reference number for the "Sally" (3) and set 3 to integer %N1%. Basically I am trying to find an easier way to loop through a text file and find the assigned integer that corresponds with the string instead of my current macro that looks like:

 

If %T1% = "John" Then %N1% = 5

Else

If %T1% = "Tim" Then %N1% = 6

Else

If %T1% = "Sally" Then %N1% = 3

Else

If %T1% = "Fred" Then %N1% = 9

Else

If %T1% = "Bill" Then %N1% = 2

Else

If %T1% = "Bob" Then %N1% = 11

Else

If %T1% = "Robert" Then %N1% = 10

Else

If %T1% = "Tom" Then %N1% = 7

Else

If %T1% = "Elliott" Then %N1% = 1

Else

End If

 

Mind you, the text file is actually much longer.

 

Bottom line, the reference number is the number of times I need to tab.

GOAL:

 

If %T1% = "Sally" Text Type: <TAB> 3 Times

 

Your cooperation to assist me in this matter is very much appreciated

Link to comment
Share on other sites

For this example I used a comma delimited file because it is easier to see in this post. To use a .csv file make your text file look like this:

John,5
Tim,6
Sally,3
Fred,9
Bill,2
Bob,11
Robert,10
Tom,7
Elliott,1

Then use this macro:

// Set T1 to the name you want

ASCII File Begin Process: "names.txt" (Comma Delimited Text )
 If Variable %T1% = variable %T10%
Variable Modify String: Convert %T12% to integer %N12%
Repeat Start (Repeat %N11% times)
  Text Type: <TAB>
Repeat End
 End If

To get this into your macro file copy and paste this:

<REM2:Set T1 to the name you want><REM2:><ADFBEG:F10:010:000001:000000:\names.txt><IFVAR2:4:01:1:T10><TMVAR2:05:12:12:000:000:><REP3:01:000001:000001:%N11%:0:01:><TEXTTYPE:<TAB>><ENDREP><ENDIF>

You could easily use a tab delimited file by modifying the ASCI Text File Begin Process command.

Link to comment
Share on other sites

Try launching notepad to open the text file. (Launch "C:\Windows\system32\cmd.exe /C notepad.exe textfile.txt")

 

Then Text Type keystrokes to find the id within Notepad: ALTD-E-ALTU, F(ind), %T1% as the find argument, ENTER. This should position you at the correct line within the text file, if it exists.

 

Text Type the HOME key to assure you are at the beginning of the line. SHIFTD - END - SHIFTU to highlight the whole line, copy to clipboard, save clipboard to another variable like T2. Change variable T2 by editing out the numeric digits (and maybe the Tab character?) -- changing them to nulls or spaces.

 

Compare T1 to T2 to make sure you really found what you think you found (in case the name is not in the file at all).

 

Text Type HOME again, then END, to position to the end of the line after the numeric digits.

 

Text Type SHIFTD - ARROW LEFT as many times as the number of digits - SHIFTU to highlight the digits, copy into clipboard, save in a variable like T3. This will be easier if you standardize the number of digits -- that is, the text file should contain

SALLY 009

GEORGE 010

rather than

SALLY 9

GEORGE 10

 

Close notepad, switch to the screen where you have to do the tabbing.

REPEAT %T3%

Text Type Tab

REPEAT END

 

I have probably missed a detail or two, but you get the picture....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...