Macroman Posted April 5, 2020 Report Share Posted April 5, 2020 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 Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 5, 2020 Author Report Share Posted April 5, 2020 I'm also not married to the idea of using a text file, if it's possible to snag the information from column 1 and column 2 csv that would probably be more ideal. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 6, 2020 Report Share Posted April 6, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 6, 2020 Author Report Share Posted April 6, 2020 I had tried using that, but it didn't seem to work. No rush but if you could elaborate in the future, that'd be great! Quote Link to comment Share on other sites More sharing options...
rberq Posted April 6, 2020 Report Share Posted April 6, 2020 Could you show a few lines of the CSV file as an example? Does the file contain multiple user IDs, or is the entire file for a single user only? Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 6, 2020 Author Report Share Posted April 6, 2020 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 Quote Link to comment Share on other sites More sharing options...
terrypin Posted April 6, 2020 Report Share Posted April 6, 2020 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. Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 6, 2020 Author Report Share Posted April 6, 2020 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 Quote Link to comment Share on other sites More sharing options...
terrypin Posted April 6, 2020 Report Share Posted April 6, 2020 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 Quote Link to comment Share on other sites More sharing options...
terrypin Posted April 6, 2020 Report Share Posted April 6, 2020 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 Quote Link to comment Share on other sites More sharing options...
Samrae Posted April 6, 2020 Report Share Posted April 6, 2020 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". Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 6, 2020 Author Report Share Posted April 6, 2020 Thanks all, I will give these methods a try! Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 6, 2020 Author Report Share Posted April 6, 2020 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? Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 6, 2020 Author Report Share Posted April 6, 2020 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 Quote Link to comment Share on other sites More sharing options...
terrypin Posted April 6, 2020 Report Share Posted April 6, 2020 I think I see what’s wrong and I’ll fix when I get back to my PC in the morning. Terry 23:45 UK time, from my iPad. Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 6, 2020 Author Report Share Posted April 6, 2020 8 minutes ago, terrypin said: I think I see what’s wrong and I’ll fix when I get back to my PC in the morning. Terry 23:45 UK time, from my iPad. Thank you terry! Quote Link to comment Share on other sites More sharing options...
terrypin Posted April 7, 2020 Report Share Posted April 7, 2020 I've corrected a careless mistake and the edited macro now works consistently here. Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 11, 2020 Author Report Share Posted April 11, 2020 Can you upload the fix? Thanks! Quote Link to comment Share on other sites More sharing options...
Macroman Posted April 11, 2020 Author Report Share Posted April 11, 2020 On 4/6/2020 at 11:01 PM, terrypin said: I've corrected a careless mistake and the edited macro now works consistently here. Terry, East Grinstead, UK Hey nevermind, I found the edited and it works great, thank you Terry! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.