webbhogg Posted February 7, 2009 Report Share Posted February 7, 2009 I have a .txt file containing the following list: name1@email.com,password1 name2@email.com,password2 name3@email.com,password3 name4@email.com,password4 name5@email.com,password5 name6@email.com,password6 name7@email.com,password7 What I need to do (if possible) is: Capture the the email address of LINE 1 (name1@email.com) and save it as variable %T1%. Capture the the password of LINE 1 (password1) and save it as variable %T2%. Then, remove the record from LINE 1 (name1@email.com,password1) and move the next record into LINE 1 (name2@email.com,password2). *All of this done without opening the .txt file but rather processing the file to accomplish these actons. I am using Macroexpress and understand that ME Pro seperates strings, but from what I've read you need to enter a specific number of characters to seperate. These email address' and passwords vary in length. I hope I'm worong and ME Pro can seperate strings by specific characters (in this case ","). Please let me know if my description is insufficient. Thanks for your help! Quote Link to comment Share on other sites More sharing options...
terrypin Posted February 7, 2009 Report Share Posted February 7, 2009 I have a .txt file containing the following list: name1@email.com,password1 name2@email.com,password2 name3@email.com,password3 name4@email.com,password4 name5@email.com,password5 name6@email.com,password6 name7@email.com,password7 What I need to do (if possible) is: Capture the the email address of LINE 1 (name1@email.com) and save it as variable %T1%. Capture the the password of LINE 1 (password1) and save it as variable %T2%. Then, remove the record from LINE 1 (name1@email.com,password1) and move the next record into LINE 1 (name2@email.com,password2). *All of this done without opening the .txt file but rather processing the file to accomplish these actons. I am using Macroexpress and understand that ME Pro seperates strings, but from what I've read you need to enter a specific number of characters to seperate. These email address' and passwords vary in length. I hope I'm worong and ME Pro can seperate strings by specific characters (in this case ","). Please let me know if my description is insufficient. Thanks for your help! Here's the main part, with a Text Display to show you what's going on. ME 3 Text File Begin Process: "webbhogg-data.txt" Variable Set Integer %N1% from Position of Text in Variable %T3% Variable Modify Integer: Dec (%N1%) Variable Modify String: Copy Part of %T3% to %T1% Variable Modify Integer: %N1% = %N1% + 2 Variable Modify String: Copy Part of %T3% to %T2% Text Box Display: Results Text File End Process Macro Return <BTFBEG:003:000001:000000:C:\Docs\SUNDRY\Macro Express\webbhogg-data.txt><IVAR2:01:13:3:,><NMVAR:09:01:0:0000001:0:0000000><TMVAR2:10:01:03:001:N01:><NMVAR:01:01:1:0000001:2:0000002><TMVAR2:10:02:03:N01:025:><TBOX4:T:1:CenterCenter000278000200:000:ResultsEmail = %T1% Password = %T2%><BTFEND><MRETURN> ME Pro Text File Begin Process: C:\Docs\SUNDRY\Macro Express\webbhogg-data.txt // String manipulation demonstration for webbhogg Variable Set Integer %N[1]% to the position of "," in %Both% // Find where the comma occurs Variable Modify Integer %N[1]%: Decrement Variable Modify String: Copy a substring in %Both%, starting at 1 and %N[1]% characters long to %T[1]% // Get email into T1 Variable Modify Integer: %N[1]% = %N[1]% + 2 Variable Modify String: Copy a substring in %Both%, starting at %N[1]% and 25 characters long to %T[2]% // Get password into T2 Text Box Display: Result so far Text File End Process Macro Return <TEXT FILE BEGIN PROCESS Filename="C:\\Docs\\SUNDRY\\Macro Express\\webbhogg-data.txt" Start_Record="1" Process_All="TRUE" Records="1" Variable="%Both%"/> <COMMENT Value="String manipulation demonstration for webbhogg"/> <VARIABLE SET INTEGER Option="\x0E" Destination="%N[1]%" Text_Variable="%Both%" Text="," Ignore_Case="FALSE" _COMMENT="Find where the comma occurs"/> <VARIABLE MODIFY INTEGER Option="\x08" Destination="%N[1]%"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%T[1]%" Variable="%Both%" Start="1" Count="%N[1]%" _COMMENT="Get email into T1"/> <VARIABLE MODIFY INTEGER Option="\x00" Destination="%N[1]%" Value1="%N[1]%" Value2="2"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%T[2]%" Variable="%Both%" Start="%N[1]%" Count="25" _COMMENT="Get password into T2"/> <TEXT BOX DISPLAY Title="Result so far" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Both = %Both%\r\n\\par Email = %T[1]%\r\n\\par Password = %T[2]%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="300" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <TEXT FILE END PROCESS/> <MACRO RETURN/> I've assumed that you don't really mean the file is a fixed 7 lines, but is indeterminately long. I've also assumed your email addresses contain no commas. And that your passwords have a max length of 25. Your description about replacing line 1 with line 2 is unclear to me. If it's meant to be repetitive, then it seems you'll end up with just a single line, the last! -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
wtawta Posted February 9, 2009 Report Share Posted February 9, 2009 Your description about replacing line 1 with line 2 is unclear to me. If it's meant to be repetitive, then it seems you'll end up with just a single line, the last! Terry, my partner "webbhogg" is the original poster of the thread. Thanks for you assistance, you answered something we've been trying to wrap our heads around for a while. Let me try to clear up what was meant by replacing line 1 with line 2. We will be processing the file and capturing the email /password one at a time. After we have the first email/pass we would like to remove it from the .txt file and bring the next email/pass up to line value 1. This way whenever the we need to get the next email/pass it will always be located on the first line (line value 1) of the text document. For example the text document may start with this data: name1@email.com:pass1 <--- (Line value = 1 of text doc.) name2@email.com:pass2 name3@email.com:pass3 name4@email.com:pass4 name5@email.com:pass5 Then we will call for the first email/pass leaving the text document like this: name2@email.com:pass2 <--- (Line value = 1 of text doc.) name3@email.com:pass3 name4@email.com:pass4 name5@email.com:pass5 and, so on: name3@email.com:pass3 <--- (Line value = 1 of text doc.) name4@email.com:pass4 name5@email.com:pass5 I hope this is clearer. Please let me know and thanks again for you help! Quote Link to comment Share on other sites More sharing options...
terrypin Posted February 9, 2009 Report Share Posted February 9, 2009 Terry, my partner "webbhogg" is the original poster of the thread. Thanks for you assistance, you answered something we've been trying to wrap our heads around for a while. Let me try to clear up what was meant by replacing line 1 with line 2. We will be processing the file and capturing the email /password one at a time. After we have the first email/pass we would like to remove it from the .txt file and bring the next email/pass up to line value 1. This way whenever the we need to get the next email/pass it will always be located on the first line (line value 1) of the text document. For example the text document may start with this data: name1@email.com:pass1 <--- (Line value = 1 of text doc.) name2@email.com:pass2 name3@email.com:pass3 name4@email.com:pass4 name5@email.com:pass5 Then we will call for the first email/pass leaving the text document like this: name2@email.com:pass2 <--- (Line value = 1 of text doc.) name3@email.com:pass3 name4@email.com:pass4 name5@email.com:pass5 and, so on: name3@email.com:pass3 <--- (Line value = 1 of text doc.) name4@email.com:pass4 name5@email.com:pass5 I hope this is clearer. Please let me know and thanks again for you help! "Then we will call for the first email/pass..." ?? If you mean, "Get and process T1 and T2 for line 1 of the text file", then the macro I posted does that. There's no need to do any 'moving' etc. Whatever it is you want to do with T1 and T2, that is done automatically for each line where I showed the Text Display command. Read Help > Index > Text File Process if you need further clarification. -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
wtawta Posted February 9, 2009 Report Share Posted February 9, 2009 "Then we will call for the first email/pass..." ??If you mean, "Get and process T1 and T2 for line 1 of the text file", then the macro I posted does that. There's no need to do any 'moving' etc. Whatever it is you want to do with T1 and T2, that is done automatically for each line where I showed the Text Display command. Read Help > Index > Text File Process if you need further clarification. -- Terry, East Grinstead, UK It is necessary for this 'moving' to occur if this is to work in my project. I could give a explanation why but it would probably take me a day. lol. "Get and process T1 and T2 for line 1 of the text file" makes sense and works perfectly. I have edited the macro you posted a bit to just get and process T1 and T2 for line 1 of the text file and not to loop and process the rest of the lines. The next time I run this new macro it will process line 1 again and return the same information for T1 and T2 unless I can remove the original data of line 1, in this case T1 and T2 from the original text document. I can't (would rather not) keep track of which lines have been processed before hand, in order to get the next email/pass the next time I run this macro. I guess what I need to know are two things. How to delete the first line of text from a document, in this example an email address and password. I am assuming deleting this email/pass will leave a empty space in line 1 of the text document. If this is the case, the second thing I would need is to move the next email/pass up to the top (line 1) of the text document. Now, the next time the macro is run it will get a and process the T1 an T2 for line 1 and it will return the new values (email/pass) that were not returned the last time I ran the macro. I hope I am making sense. Thanks so much. Quote Link to comment Share on other sites More sharing options...
terrypin Posted February 9, 2009 Report Share Posted February 9, 2009 It is necessary for this 'moving' to occur if this is to work in my project. I could give a explanation why but it would probably take me a day. lol. "Get and process T1 and T2 for line 1 of the text file" makes sense and works perfectly. I have edited the macro you posted a bit to just get and process T1 and T2 for line 1 of the text file and not to loop and process the rest of the lines. The next time I run this new macro it will process line 1 again and return the same information for T1 and T2 unless I can remove the original data of line 1, in this case T1 and T2 from the original text document. I can't (would rather not) keep track of which lines have been processed before hand, in order to get the next email/pass the next time I run this macro. I guess what I need to know are two things. How to delete the first line of text from a document, in this example an email address and password. I am assuming deleting this email/pass will leave a empty space in line 1 of the text document. If this is the case, the second thing I would need is to move the next email/pass up to the top (line 1) of the text document. Now, the next time the macro is run it will get a and process the T1 an T2 for line 1 and it will return the new values (email/pass) that were not returned the last time I ran the macro. I hope I am making sense. Thanks so much. OK, if I now understand you correctly you're processing only one line at a time, but progressing line-by-line down through the file on successive runs of the macro. In that case there's no need to do any deleting. Just use the facility (that you'll find described in the Help topic I pointed you to) which allows you to select which record(s) to process. Here's the revised macro in ME Pro. ME Pro Variable Restore: Restore Integer Variables Variable Modify Integer %N[2]%: Increment Text File Begin Process: C:\Docs\SUNDRY\Macro Express\webbhogg-data.txt // String manipulation demonstration for webbhogg Variable Set Integer %N[1]% to the position of "," in %Both% // Find where the comma occurs Variable Modify Integer %N[1]%: Decrement Variable Modify String: Copy a substring in %Both%, starting at 1 and %N[1]% characters long to %T[1]% // Get email into T1 Variable Modify Integer: %N[1]% = %N[1]% + 2 Variable Modify String: Copy a substring in %Both%, starting at %N[1]% and 25 characters long to %T[2]% // Get password into T2 Text Box Display: Result so far Text File End Process Variable Save: Save Integer Variables Macro Return <VARIABLE RESTORE Option="\x02"/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%N[2]%"/> <TEXT FILE BEGIN PROCESS Filename="C:\\Docs\\SUNDRY\\Macro Express\\webbhogg-data.txt" Start_Record="%N[2]%" Process_All="FALSE" Records="1" Variable="%Both%"/> <COMMENT Value="String manipulation demonstration for webbhogg"/> <VARIABLE SET INTEGER Option="\x0E" Destination="%N[1]%" Text_Variable="%Both%" Text="," Ignore_Case="FALSE" _COMMENT="Find where the comma occurs"/> <VARIABLE MODIFY INTEGER Option="\x08" Destination="%N[1]%"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%T[1]%" Variable="%Both%" Start="1" Count="%N[1]%" _COMMENT="Get email into T1"/> <VARIABLE MODIFY INTEGER Option="\x00" Destination="%N[1]%" Value1="%N[1]%" Value2="2"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%T[2]%" Variable="%Both%" Start="%N[1]%" Count="25" _COMMENT="Get password into T2"/> <TEXT BOX DISPLAY Title="Result so far" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Both = %Both%\r\n\\par Email = %T[1]%\r\n\\par Password = %T[2]%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="300" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <TEXT FILE END PROCESS/> <VARIABLE SAVE Option="\x02"/> <MACRO RETURN/> The ME 3 version will look very similar. File contents (unaltered throughout): name1@email.com,password1 name2@email.com,password2 name3@email.com,password-maxlength-say-25 name4@email.com,15-chars-abcdef name5@email.com,11-chars-xy name6@email.com,10-chars-x name7@email.com,08-chars Text message on 1st run Both = name1@email.com,password1 Email = name1@email.com Password = password1 Text message on 2nd run Both = name2@email.com,password2 Email = name2@email.com Password = password2 Text message on 3rd run Both = name3@email.com,password-maxlength-say-25 Email = name3@email.com Password = password-maxlength-say-25 etc. Obviously you'll need to adapt it a bit to suit, including a reset routine and/or an end-of-file routine. If you do want to physically delete successive lines of the file, then you will need a different approach that opens it first (which I understood you didn't want) and then saves it in its progressively shortened form. -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
kevin Posted February 9, 2009 Report Share Posted February 9, 2009 Here is what I understand about what you are trying to do. 1. Another process creates a file with email addresses and passwords. 2. Perform an action on the first email address/password pair. 3. Remove that email address/password pair from the file. 4. Repeat the same process sometime later. There is an easy way, even in Macro Express 3, to get values from a record that are comma separated using the ASCII Text File Begin/End Process commands. To get only the first record you can break out of the loop. Like this: // Read one line from the input file ASCII File Begin Process: "test.txt" (Comma Delimited Text ) Break ASCII File End Process // Here T1= email address, T2= password The only way to remove something from the top of a file is to read the file and rewrite it. One seeming exception to this is if you are using a database program but in that case the database program leaves a hole in the data and ignores it. A pack or compression routine later rewrites the file or data to remove holes. To remove the first record from a file you read every record from the file, write all but the first record to a temporary output file and then rename the files. Like this: // Delete temporary output file if it exists If File Exists "test.txt" Delete File or Files: "testOUT.txt" End If // Read every record except record 1 from test.txt and write it to testOUT.txt Wait for File Ready: "test.txt" Text File Begin Process: "test.txt" Variable Set Integer %N1% to 1 If Variable %N1% = 1 Variable Modify Integer: Inc (%N1%) Else Variable Modify String: Append %T1% to Text File End If Text File End Process // Delete old backup file if it exists If File Exists "test.txt" Delete File or Files: "testBACK.txt" End If // Rename test.txt to testBACK.txt and testOUT.txt to test.txt Rename File or Files: "test.txt" Rename File or Files: "testOUT.txt" You may need to do something that tells the process that is adding email address/password pairs to the file to pause for a moment. You can add things to your macro that the other process reads to do this. (Since we have no idea what process is adding email address/passwords to the file there is nothing in this sample to accommodate that. Here is the sample macro in a form you can copy and paste into your own macro: <REM2:Read one line from the input file><ADFBEG:F10:001:000001:000000:c:\test.txt><BREAK><ADFEND><REM2:><REM2:Delete temporary output file if it exists><IFOTH:01:2:c:\test.txt><DOFILE:08:NN:testOUT.txt>><ENDIF><REM2:><REM2:Read every record except record 1 from test.txt and write it to testOUT.txt><WFREADY:000001:000000:000002c:\test.txt><BTFBEG:001:000001:000000:c:\test.txt><IVAR2:01:01:1><IFVAR2:2:01:1:1><NMVAR:08:01:0:0000001:0:0000000><ELSE><TMVAR2:20:01:00:000:000:c:\testOUT.txtT><ENDIF><BTFEND><REM2:><REM2:Delete old backup file if it exists><IFOTH:01:2:c:\test.txt><DOFILE:08:NN:testBACK.txt>><ENDIF><REM2:><REM2:Rename test.txt to testBACK.txt and testOUT.txt to test.txt><DOFILE:06:NN:c:\test.txt>c:\testBACK.txt><DOFILE:06:NN:testOUT.txt>test.txt> Quote Link to comment Share on other sites More sharing options...
kevin Posted February 9, 2009 Report Share Posted February 9, 2009 Another approach you might want to try is to leave the email address/passwords in the file and have your macro ignore them. Something like this would work: // Set N1 to the first value you want to read from the file // Read one line from the input file ASCII File Begin Process: "test.txt" (Comma Delimited Text ) Break ASCII File End Process This example does not show how to keep track of the number to use. Look at samples.mex for the macro 'Counter_From_Run_To_Run' for a way to save a counter at the end of the macro and read it at the beginning of the macro. Samples.mex can be found in the folder where your Macro Express Program files are installed. If you decide to use this approach you could write a separate macro based on my other post to delete things from the email address/password file at a later time when it is safe to do so. Quote Link to comment Share on other sites More sharing options...
wtawta Posted February 9, 2009 Report Share Posted February 9, 2009 Another approach you might want to try is to leave the email address/passwords in the file and have your macro ignore them. Something like this would work: // Set N1 to the first value you want to read from the file // Read one line from the input file ASCII File Begin Process: "test.txt" (Comma Delimited Text ) Break ASCII File End Process This example does not show how to keep track of the number to use. Look at samples.mex for the macro 'Counter_From_Run_To_Run' for a way to save a counter at the end of the macro and read it at the beginning of the macro. Samples.mex can be found in the folder where your Macro Express Program files are installed. If you decide to use this approach you could write a separate macro based on my other post to delete things from the email address/password file at a later time when it is safe to do so. Kevin, thanks for taking time to help. This is how we currently keep track of which email/pass pair is next in line to be used. We would like to change this method in order to keep this list clean (free of used pairs). Quote Link to comment Share on other sites More sharing options...
wtawta Posted February 9, 2009 Report Share Posted February 9, 2009 Here is what I understand about what you are trying to do. 1. Another process creates a file with email addresses and passwords. 2. Perform an action on the first email address/password pair. 3. Remove that email address/password pair from the file. 4. Repeat the same process sometime later. There is an easy way, even in Macro Express 3, to get values from a record that are comma separated using the ASCII Text File Begin/End Process commands. To get only the first record you can break out of the loop. Like this: // Read one line from the input file ASCII File Begin Process: "test.txt" (Comma Delimited Text ) Break ASCII File End Process // Here T1= email address, T2= password The only way to remove something from the top of a file is to read the file and rewrite it. One seeming exception to this is if you are using a database program but in that case the database program leaves a hole in the data and ignores it. A pack or compression routine later rewrites the file or data to remove holes. To remove the first record from a file you read every record from the file, write all but the first record to a temporary output file and then rename the files. Like this: // Delete temporary output file if it exists If File Exists "test.txt" Delete File or Files: "testOUT.txt" End If // Read every record except record 1 from test.txt and write it to testOUT.txt Wait for File Ready: "test.txt" Text File Begin Process: "test.txt" Variable Set Integer %N1% to 1 If Variable %N1% = 1 Variable Modify Integer: Inc (%N1%) Else Variable Modify String: Append %T1% to Text File End If Text File End Process // Delete old backup file if it exists If File Exists "test.txt" Delete File or Files: "testBACK.txt" End If // Rename test.txt to testBACK.txt and testOUT.txt to test.txt Rename File or Files: "test.txt" Rename File or Files: "testOUT.txt" You may need to do something that tells the process that is adding email address/password pairs to the file to pause for a moment. You can add things to your macro that the other process reads to do this. (Since we have no idea what process is adding email address/passwords to the file there is nothing in this sample to accommodate that. Here is the sample macro in a form you can copy and paste into your own macro: <REM2:Read one line from the input file><ADFBEG:F10:001:000001:000000:c:\test.txt><BREAK><ADFEND><REM2:><REM2:Delete temporary output file if it exists><IFOTH:01:2:c:\test.txt><DOFILE:08:NN:testOUT.txt>><ENDIF><REM2:><REM2:Read every record except record 1 from test.txt and write it to testOUT.txt><WFREADY:000001:000000:000002c:\test.txt><BTFBEG:001:000001:000000:c:\test.txt><IVAR2:01:01:1><IFVAR2:2:01:1:1><NMVAR:08:01:0:0000001:0:0000000><ELSE><TMVAR2:20:01:00:000:000:c:\testOUT.txtT><ENDIF><BTFEND><REM2:><REM2:Delete old backup file if it exists><IFOTH:01:2:c:\test.txt><DOFILE:08:NN:testBACK.txt>><ENDIF><REM2:><REM2:Rename test.txt to testBACK.txt and testOUT.txt to test.txt><DOFILE:06:NN:c:\test.txt>c:\testBACK.txt><DOFILE:06:NN:testOUT.txt>test.txt> Kevin, I tried to use this sample you provided and failed to get it to work. I was left with the 'testBACK.txt' file in the C drive and not the 'test.txt' file. I took a look into the commands and noticed that there were some file paths missing. For example, in some of the file path fields it reads 'test.txt' instead of 'c:\test.txt'. I am assuming this was an oversight so I added the file path to the appropriate areas of the macro. For some reason I am not ending up with the desired result intended (I think). I believe the desired result of your macro is a 'test.txt' file with all the email/pass pairs minus the first pair in the original list. Instead, I am ending up with a 'testBACK.txt' file with all the original email/pass pairs. Nothing removed from the original document and no 'test.txt' file. Am I missing something? Quote Link to comment Share on other sites More sharing options...
kevin Posted February 10, 2009 Report Share Posted February 10, 2009 This macro was meant as an example of how to accomplish your task. I did not run the macro. It is assumed that you would need to modify it to fit your situation, including the file names and paths that you actually use. 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.