Jump to content
Macro Express Forums

Text file lookup and display name associated to number


Recommended Posts

So i'm trying to make this macro look up a user id number from the text file and display the name associated to it.  If the number doesn't exist, it works correctly.  If it finds the number it displays the whole file.  Any ideas on how to make it just display the person that is associated to it?

 

Also I want to do the same with acronyms, will the same method still work

 

I appreciate the help

 

Thanks

 

Capture.PNG

Link to comment
Share on other sites

You should use ASCII Text File Process. Loop though it until you find the row you want then grab the other element of the text array. 

Sorry, I can't elaborate now, I need to leave shortly. 

  • Like 1
Link to comment
Share on other sites

It's basically as such

 

Column 1                Column 2

 

12345                      Smith, John

44921                      Jones, Mike

 

 

etc.  there is about 40 of these

 

also with acronyms, same thing

 

Column 1 with the acronym

Column 2 with the explanation

 

 

Link to comment
Share on other sites

Are these two files TXT as your first post seems to indicate, or CSV as per your last post?

 

Please post the full macro you have so far and its code, not just the command text.

 

It would also be helpful to post both files, suitably edited if confidential.

 

Are you using ME3 or ME Pro?

 

As usual, the devil is in the details.

Link to comment
Share on other sites

It's a text file, hasn't much been made yet as I'm trying to figure out how to snag those details.  CSV would be better to organize in my opinion if that's doable. I'm currently using macro express pro

 

I basically want two columns one with names and one with the numeric user id, and the same with an acronym macro which has two columns of text.  I'm just at home so I don't have access to the macro but I believe it would need a redesign based off what Cory was saying

Link to comment
Share on other sites

Thanks for the further details. Yes, I would use ASCll File Begin Process. Personally I would separate the two cols with a tab, to minimise any ambiguity with the Name (which contains a comma).

 

Seeing the variable 'V1' I assume you are using ME Pro? If so I suggest you name your variables meaningfully, especially when arrays are involved.

 

Note that your macro will fail because N2 is an integer but V1 is a string. You'd have to convert N2 first, using Variable Modify Intger > Convert to Text String.

 

I'll suggest a macro shortly.

 

Terry, East Grinstead, UK

 

Link to comment
Share on other sites

Here's one way to do it:

 

EDITED

// Two cols of info, User ID and Name, separated by a tab, are stored in G:\Traffic\IBS\Other\id.txt.
This macro prompts for a user id. If it is found it displays the name. Otherwise it displays an appropriate message and ends the macro.
// I've defined Use ID as a string variable. That not only allows future flexibility but simplifies the script. And unless you intend to do arithmetic on the User ID it's unnecessary to set it as an integer.
// Note: I prefix my string variables with 't' (for 'text'), and integer variables with 'n' (for 'number').
 
Variable Set String %tUser%: Prompt
ASCII File Begin Process: "G:\Traffic\IBS\Other\id.txt" (Tab Delimited Text (.txt))
  If Variable %tUser% Equals "%tLine[1]%" // This is a match.
    Text Box Display: User %tUser% is:
    Variable Set String %tResult% to "Matched"
    Macro Stop
  End If
ASCII File End Process
If Variable %tResult% Does not Equal "Matched" // There was no match
  Text Box Display: User %tUser% is:
End If

 

CODE:

 

<COMMENT Value="Two cols of info, User ID and Name, separated by a tab, are stored in G:\\Traffic\\IBS\\Other\\id.txt.\r\nThis macro prompts for a user id. If it is found it displays the name. Otherwise it displays an appropriate message and ends the macro."/>
<COMMENT Value="I've defined Use ID as a string variable. That not only allows future flexibility but simplifies the script. And unless you intend to do arithmetic on the User ID it's unnecessary to set it as an integer."/>
<COMMENT Value="Note: I prefix my string variables with 't' (for 'text'), and integer variables with 'n' (for 'number')."/>
<COMMENT/>
<VARIABLE SET STRING Option="\x01" Destination="%tUser%" Prompt="Enter the target User ID." Mask="FALSE" OnTop="TRUE" Left="Center" Top="Center" Monitor="0"/>
<ASCII FILE BEGIN PROCESS Filename="G:\\Traffic\\IBS\\Other\\id.txt" Format="Tab" Start_Record="1" Process_All="TRUE" Records="1" Variable="%tLine%" Start_Index="1" Parse_Blank_Lines="FALSE" Clear_Array="TRUE"/>
<IF VARIABLE Variable="%tUser%" Condition="\x00" Value="%tLine[1]%" IgnoreCase="FALSE" _COMMENT="This is a match."/>
<TEXT BOX DISPLAY Title="User %tUser% is:" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs20 %tLine[2]%\\f1 \r\n\\par }\r\n" Left="689" Top="334" Width="378" Height="138" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<VARIABLE SET STRING Option="\x00" Destination="%tResult%" Value="Matched" NoEmbeddedVars="FALSE"/>
<MACRO STOP/>
<END IF/>
<ASCII FILE END PROCESS/>
<IF VARIABLE Variable="%tResult%" Condition="\x01" Value="Matched" IgnoreCase="FALSE" _COMMENT="There was no match"/>
<TEXT BOX DISPLAY Title="User %tUser% is:" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs20 Not on record.\\f1 \r\n\\par }\r\n" Left="689" Top="334" Width="378" Height="138" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<END IF/>

 

 

Terry, UK

 

 

MacromanDemo-Edited.mex

Link to comment
Share on other sites

There is another example of using the ASCII Text File Process command in the samples.mex macro file. This file should be located somewhere in your My Documents folder. You can also copy it from the folder where the Macro Express Program files is installed (do not try to use it from the Program Files folder).

    C:\Program Files (x86)\Macro Express Pro 6\samples.mex

 

Or, you can download it from this page: Sample Macros

 

Look for the macro "Process a CSV Delimited File".

Link to comment
Share on other sites

10 hours ago, terrypin said:

Here's one way to do it:

 


// Two cols of info, User ID and Name, separated by a tab, are stored in G:\Traffic\IBS\Other\id.txt.
This macro prompts for a user id. If it is found it displays the name. Otherwise it displays an appropriate message and ends the macro.
// I've defined Use ID as a string variable. That not only allows future flexibility but simplifies the script. And unless you intend to do arithmetic on the User ID it's unnecessary to set it as an integer.
// Note: I prefix my string variables with 't' (for 'text'), and integer variables with 'n' (for 'number').
 
Variable Set String %tUser%: Prompt
ASCII File Begin Process: "G:\Traffic\IBS\Other\id.txt" (Tab Delimited Text (.txt))
  If Variable %tUser% Equals "%tLine[1]%" // This is a match.
    Text Box Display: User %tUser% is:
    Macro Stop
  Else
    Repeat Exit
  End If
ASCII File End Process
Text Box Display: User %tUser% is:

 

CODE:

 


<COMMENT Value="Two cols of info, User ID and Name, separated by a tab, are stored in G:\\Traffic\\IBS\\Other\\id.txt.\r\nThis macro prompts for a user id. If it is found it displays the name. Otherwise it displays an appropriate message and ends the macro."/>
<COMMENT Value="I've defined Use ID as a string variable. That not only allows future flexibility but simplifies the script. And unless you intend to do arithmetic on the User ID it's unnecessary to set it as an integer."/>
<COMMENT Value="Note: I prefix my string variables with 't' (for 'text'), and integer variables with 'n' (for 'number')."/>
<COMMENT/>
<VARIABLE SET STRING Option="\x01" Destination="%tUser%" Prompt="Enter the target User ID." Mask="FALSE" OnTop="TRUE" Left="Center" Top="Center" Monitor="0"/>
<ASCII FILE BEGIN PROCESS Filename="G:\\Traffic\\IBS\\Other\\id.txt" Format="Tab" Start_Record="1" Process_All="TRUE" Records="1" Variable="%tLine%" Start_Index="1" Parse_Blank_Lines="FALSE" Clear_Array="TRUE"/>
<IF VARIABLE Variable="%tUser%" Condition="\x00" Value="%tLine[1]%" IgnoreCase="FALSE" _COMMENT="This is a match."/>
<TEXT BOX DISPLAY Title="User %tUser% is:" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs20 %tLine[2]%\\f1 \r\n\\par }\r\n" Left="689" Top="334" Width="378" Height="138" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<MACRO STOP/>
<ELSE/>
<REPEAT EXIT/>
<END IF/>
<ASCII FILE END PROCESS/>
<TEXT BOX DISPLAY Title="User %tUser% is:" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs20 Not on record.\\f1 \r\n\\par }\r\n" Left="689" Top="334" Width="378" Height="138" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

Terry, UK

 

MacromanDemo-1.mex 2.98 kB · 1 download

Terry, I tried the sample macro you provided and it works for the entry on line 1, but not line 2 or 3 any thoughts?   Do you think it'll be better to use a csv file?  Thanks

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