Jump to content
Macro Express Forums

Repeat Loops


Recommended Posts

Hello,

I am trying to get a loop to work inside a loop.  I can't seem to get the script to do what I want.  Basically, I don't need to reenter the first column until all the lines for that mnemonic have been entered.  I then need to file that entry and move to the next mnemonic to input all it's corresponding lines.  I'm pretty close, but no matter what I do I end up getting caught in the lines usually.  Can anyone provide a suggestion for me?

Thanks in advance.

image.png.7ba9bccb96552f60d51e80f04d61fc17.png

 

<ASCII FILE BEGIN PROCESS Filename

Variable="%T%" Start_Index="1" Parse_Blank_Lines="FALSE" Clear_Array="FALSE"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Mnemonic"/>
<TEXT TYPE Action="0" Text="<F8>E<TAB>" _COMMENT="Enter Edit Tab"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[1]%" Value="0"/>
<REPEAT UNTIL Variable="%T[1]%" Condition="\x00" Value="0"/>
<TEXT TYPE Action="0" Text="%T[2]%<ENTER>" _COMMENT="Line#\r\n"/>
<TEXT TYPE Action="0" Text="%T[3]%<ENTER>" _COMMENT="Item Number\r\n"/>
<TEXT TYPE Action="0" Text="<ENTER><ENTER><ENTER><ENTER><ENTER><ENTER><ENTER>"/>
<VARIABLE MODIFY INTEGER Option="\x07" Destination="%N[1]%"/>
<END REPEAT/>
<TEXT TYPE Action="0" Text="<F12>"/>
<ASCII FILE END PROCESS/>

 

Link to comment
Share on other sites

What you are trying to do is kind of tricky.  I don't think the Repeat loop is doing any good, because additional ASCII file records are NOT arriving each time through the Repeat. 

 

The following code is probably closer to what you want.  I haven't tested it, so there may be errors and omissions.  Also depending on timing, you may have to put brief delays between some of the typing, to give the application time to respond. 

<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="1" _COMMENT="first-time-through switch"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[99]%" NoEmbeddedVars="FALSE" _COMMENT="clear save area for last-processed-record's mnemonic"/>
<ASCII FILE BEGIN PROCESS Filename="xxx" Format="CSV" Start_Record="1" Process_All="TRUE" Variable="%T%" Start_Index="1" Parse_Blank_Lines="FALSE" Clear_Array="FALSE"/>
<IF VARIABLE Variable="%N[99]%" Condition="\x00" Value="1" IgnoreCase="FALSE" _COMMENT="First time through, save mnemonic of first record"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="save mnemonic"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Get screen for first mnemonic"/>
<TEXT TYPE Action="0" Text="<F8>E<TAB>" _COMMENT="Enter Edit Tab"/>
<END IF/>
<IF VARIABLE Variable="%T[1]%" Condition="\x01" Value="T[99]" IgnoreCase="FALSE" _COMMENT="Still working on the same mnemonic?"/>
<TEXT TYPE Action="0" Text="<F12>" _COMMENT="close out previous mnemonic"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Get screen for next mnemonic"/>
<TEXT TYPE Action="0" Text="<F8>E<TAB>" _COMMENT="Enter Edit Tab"/>
<END IF/>
<COMMENT Value="Type in details for current mnemonic"/>
<TEXT TYPE Action="0" Text="%T[2]%<ENTER>" _COMMENT="Line#\r\n"/>
<TEXT TYPE Action="0" Text="%T[3]%<ENTER>" _COMMENT="Item Number\r\n"/>
<TEXT TYPE Action="0" Text="<ENTER><ENTER><ENTER><ENTER><ENTER><ENTER><ENTER>"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="0" _COMMENT="clear first-time-through switch"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="save mnemonic"/>
<ASCII FILE END PROCESS/>
<TEXT TYPE Action="0" Text="<F12>" _COMMENT="close out previous (last) mnemonic"/>

 

Link to comment
Share on other sites

Thanks rberq.  I still don't seem to be passing the value of the second row from my ASCII file.  Do I need to increment N?  I had to rearrange your suggestion a bit to get the data to input correctly.  However, when the script gets to the bottom and files the data, it starts over at line one again.  Any other suggestions?  I've deleted my delays to save space in the post.


<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="1" _COMMENT="First Time Through Switch"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[99]%" NoEmbeddedVars="FALSE" _COMMENT="clear save area for last-processed-record's mnemonic"/>
<ASCII FILE BEGIN PROCESS Filename="C:\\File   IF Statement TEst_2.csv" Format="CSV" Start_Record="1" Process_All="FALSE" Records="1" Variable="%T%" Start_Index="1" Parse_Blank_Lines="FALSE" Clear_Array="FALSE"/>
<IF VARIABLE Variable="%N[99]%" Condition="\x00" Value="1" IgnoreCase="FALSE" _COMMENT="First time through, save mnemonic of first record"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="Save Mnemonic"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Get Screen for Mnemonic"/>
<TEXT TYPE Action="0" Text="<F8>E<TAB>" _COMMENT="Enter Edit Screen"/>
<TEXT TYPE Action="0" Text="%T[2]%<ENTER>" _COMMENT="Line#r n"/>
<TEXT TYPE Action="0" Text="%T[3]%<ENTER>" _COMMENT="Item Number"/>
<TEXT TYPE Action="0" Text="<ENTER><ENTER><ENTER><ENTER><ENTER><ENTER><ENTER>"/>
<END IF/>
<IF VARIABLE Variable="%T[1]%" Condition="\x01" Value="%T[99]%" IgnoreCase="FALSE" _COMMENT="Still working on same mnemonic?"/>
<TEXT TYPE Action="0" Text="<F12>" _COMMENT="Close out previous mnemonic"/>
<END IF/>
<COMMENT Value="Type in details for current mnemonic"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="0" _COMMENT="Clear first time through switch"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="Save Mnemonic"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Get screen for next mnemonic"/>
<ASCII FILE END PROCESS/>
<TEXT TYPE Action="0" Text="<F12>" _ENABLED="FALSE" _COMMENT="Close Previous Mnemonic"/>

 

Link to comment
Share on other sites

Since I can't see the form you are typing into, it's hard for me to debug the overall script.  I notice in your revised script that ASCII FILE BEGIN PROCESS is set to process only 1 record rather than all the records -- maybe that's why you don't get to the second record?  Fix that first.  Also, you are typing T2 and T3 only on the first pass through the script.  Move that first END IF up about three lines??? 

Link to comment
Share on other sites

I understand.  I appreciate the effort.  I chose process 1 record because I thought that is what your script said.  I have fixed that issue.  I also moved the END IF up three lines and now I am getting T[2] & T[3] after every T[1].  How do I get T[1] not to repeat until after all the lines corresponding T[2] & T[3] have been entered? 

This is what it is doing now:

ALS BLS ALIMED

 1
0007806

ALS BLS ALIMED- (This should be ALS BLS ARMSTRNG)
1
0002796

ALS BLS ARMSTRG
2
0002797

ALS BLS ARMSTRG (This should be ALS BLS BTBULBS)
1
0010695

ALS BLS BTBULBS
2
0010696

 

 

What I want it to do is:

ALS BLS ALIMED

1
0007806

ALS BLS ARMSTRNG
1
0002796
2
0002797

ALS BLS BTBULBS
1
0010695
2
0010696

 

Here is the data:

T[1] T[2] T[3]
ALS BLS ALIMED 1 0007806
ALS BLS ARMSTRG 1 0002796
ALS BLS ARMSTRG 2 0002797
ALS BLS BTBULBS 1 0010695
ALS BLS BTBULBS 2 0010696
ALS BLS BTBULBS 3 0010697
ALS BLS BTBULBS 4 0010698
ALS BLS BTBULBS 5 0010699
ALS BLS BNDTREE 1 0001717
ALS BLS BNDTREE 2 0002702
ALS BLS BNDTREE 3 0002703
ALS BLS BNDTREE 4 0002786
ALS BLS BNDTREE 5 0002787
ALS BLS BNDTREE 6 0002800
ALS BLS BNDTREE 7 0002801
ALS BLS BNDTREE 8 0002949
ALS BLS BNDTREE 9 0003967
ALS BLS BNDTREE 10 0007756
ALS BLS BNDTREE 11 0007758
ALS BLS BNDTREE 12 0007759
ALS BLS BNDTREE 13 0007761
ALS BLS BNDTREE 14 0007780
ALS BLS BNDTREE 15 0007852
ALS BLS BNDTREE 16 0007886
ALS BLS BNDTREE 17 0007887
ALS BLS BNDTREE 18 0008516
ALS BLS BNDTREE 19 0008630
ALS BLS BNDTREE 20 0008671

 

Here is the latest code:

<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="1" _COMMENT="First Time Through Switch"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[99]%" NoEmbeddedVars="FALSE" _COMMENT="clear save area for last-processed-record's mnemonic"/>
<ASCII FILE BEGIN PROCESS Filename="C:\\Users\\kpb44\\Dropbox\\Hospitals\\Lawrence\\IF Statement TEst_2.csv" Format="CSV" Start_Record="1" Process_All="TRUE" Variable="%T%" Start_Index="1" Parse_Blank_Lines="FALSE" Clear_Array="FALSE"/>
<IF VARIABLE Variable="%N[99]%" Condition="\x00" Value="1" IgnoreCase="FALSE" _COMMENT="First time through, save mnemonic of first record"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="Save Mnemonic"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Get Screen for Mnemonic"/>
<TEXT TYPE Action="0" Text="<F8>E<TAB>" _COMMENT="Enter Edit Screen"/>
<END IF/>
<TEXT TYPE Action="0" Text="%T[2]%<ENTER>" _COMMENT="Line#r n"/>
<TEXT TYPE Action="0" Text="%T[3]%<ENTER>" _COMMENT="Item Number"/>
<TEXT TYPE Action="0" Text="<ENTER><ENTER><ENTER><ENTER><ENTER><ENTER><ENTER>"/>
<IF VARIABLE Variable="%T[1]%" Condition="\x01" Value="%T[99]%" IgnoreCase="FALSE" _COMMENT="Still working on same mnemonic?"/>
<TEXT TYPE Action="0" Text="<F12>" _COMMENT="Close out previous mnemonic"/>
<END IF/>
<COMMENT Value="Type in details for current mnemonic"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="0" _COMMENT="Clear first time through switch"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="Save Mnemonic"/>
<WINDOW ACTIVATE Title="Variable TEst - Notepad" Exact_Match="FALSE" Wildcards="FALSE"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Get screen for next mnemonic"/>
<ASCII FILE END PROCESS/>
<TEXT TYPE Action="0" Text="<F12>" _COMMENT="Close Previous Mnemonic"/>
 

Thanks again

Link to comment
Share on other sites

OK, here’s the macro I originally suggested to you.  I added a TRIM statement for the T1 variable, because in copying your test data I accidentally added some trailing blanks in the CSV file.  Also I corrected one line where I had put “T99” instead of %T[99]% - but I think you had already caught that error.  Since I was testing with output to Notepad, I have inactivated a few lines where you get to the data entry screen and tab.  You will have to activate those lines, to test whether I have them in the right place.  When I run your test data typing into Notepad, it does this.  The macro code is at the end, after the Notepad sample.   Give it a try and see what happens. 
ALS BLS ALIMED
1
7806
ALS BLS ARMSTRG
1
2796
2
2797
ALS BLS BTBULBS
1
10695
2
10696
3
10697
4
10698
5
10699
ALS BLS BNDTREE
1
1717
2
2702
3
2703
4
2786
5
2787
6
2800
7
2801
8
2949
9
3967
10
7756
11
7758
12
7759
13
7761
14
7780
15
7852
16
7886
17
7887
18
8516
19
8630
20
8671

 

<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="1" _COMMENT="first-time-through switch"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[99]%" NoEmbeddedVars="FALSE" _COMMENT="clear save area for last-processed-record's mnemonic"/>
<ASCII FILE BEGIN PROCESS Filename="C:\\Temp\\testfile.csv" Format="CSV" Start_Record="1" Process_All="TRUE" Variable="%T%" Start_Index="1" Parse_Blank_Lines="FALSE" Clear_Array="TRUE"/>
<VARIABLE MODIFY STRING Option="\x00" Destination="%T[1]%"/>
<IF VARIABLE Variable="%N[99]%" Condition="\x00" Value="1" IgnoreCase="FALSE" _COMMENT="First time through, save mnemonic of first record"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="save mnemonic"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Get screen for first mnemonic"/>
<TEXT TYPE Action="0" Text="<F8>E<TAB>" _ENABLED="FALSE" _COMMENT="Enter Edit Tab"/>
<END IF/>
<IF VARIABLE Variable="%T[1]%" Condition="\x01" Value="%T[99]%" IgnoreCase="FALSE" _COMMENT="Still working on the same mnemonic?"/>
<TEXT TYPE Action="0" Text="<F12>" _ENABLED="FALSE" _COMMENT="close out previous mnemonic"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Get screen for next mnemonic"/>
<TEXT TYPE Action="0" Text="<F8>E<TAB>" _ENABLED="FALSE" _COMMENT="Enter Edit Tab"/>
<END IF/>
<COMMENT Value="Type in details for current mnemonic"/>
<TEXT TYPE Action="0" Text="%T[2]%<ENTER>" _COMMENT="Line#\r\n"/>
<TEXT TYPE Action="0" Text="%T[3]%<ENTER>" _COMMENT="Item Number\r\n"/>
<TEXT TYPE Action="0" Text="<ENTER><ENTER><ENTER><ENTER><ENTER><ENTER><ENTER>" _ENABLED="FALSE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="0" _COMMENT="clear first-time-through switch"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="save mnemonic"/>
<ASCII FILE END PROCESS/>
<TEXT TYPE Action="0" Text="<F12>" _ENABLED="FALSE" _COMMENT="close out previous (last) mnemonic"/>
<MACRO RETURN/>
<COMMENT Value="  "/>
<COMMENT Value="  "/>
<COMMENT Value="  "/>

 

Link to comment
Share on other sites

  • 2 weeks later...

Hi Rberq,

Thanks again for your help.  Sorry I got pulled onto another project that needed a fire put out.  Now, I am back to this issue and need to figure it out worse than ever.  I tried your latest code with no luck.  I seem to get to line 20 and it goes haywire.  The line is: If variable %T[1]% Does Not Equal %T[99]%.  I'm not real clear what this piece of code is trying to do honestly.  Everything works good until this step.  At this point I need it to evaluate T[1] and if the next row is the same mnemonic, I need it to repeat T[2] & T[3].  If the next row of T[1] is not the same mnemonic then I need it to file [F12] and start over again with the new T[1] mnemonic.  I feel like a small piece is still missing, but I am not really sure. 

Here is the latest code:

<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="1" _COMMENT="first-time-through switch"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[99]%" NoEmbeddedVars="FALSE" _COMMENT="clear save area for last-processed-record's mnemonic"/>
<ASCII FILE BEGIN PROCESS Filename="C:\\Users\\kpb44\\Dropbox\\Hospitals\\Lawrence\\IF Statement TEst_3.csv" Format="CSV" Start_Record="1" Process_All="TRUE" Variable="%T%" Start_Index="1" Parse_Blank_Lines="FALSE" Clear_Array="TRUE"/>
<IF VARIABLE Variable="%N[99]%" Condition="\x00" Value="1" IgnoreCase="FALSE" _COMMENT="First time through, save mnemonic of first record"/>
<VARIABLE MODIFY STRING Option="\x00" Destination="%T[1]%"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="save mnemonic"/>
<TEXT TYPE Action="0" Text="%T[1]%<ENTER>" _COMMENT="Get screen for first mnemonic"/>
<END IF/>
<TEXT TYPE Action="0" Text="<F8>E<TAB>" _COMMENT="Enter Edit Tab"/>
<COMMENT Value="Type in details for current mnemonic"/>
<TEXT TYPE Action="0" Text="%T[2]%<ENTER>" _COMMENT="Line#\r\n"/>
<TEXT TYPE Action="0" Text="%T[3]%<ENTER>" _COMMENT="Item Number\r\n"/>
<TEXT TYPE Action="0" Text="<ENTER><ENTER><ENTER><ENTER><ENTER><ENTER><ENTER>"/>
<IF VARIABLE Variable="%T[1]%" Condition="\x01" Value="%T[99]%" IgnoreCase="FALSE" _COMMENT="Still working on the same mnemonic?"/>
<TEXT TYPE Action="0" Text="<F12>" _COMMENT="close out previous mnemonic"/>
<END IF/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="0" _COMMENT="clear first-time-through switch"/>
<VARIABLE MODIFY STRING Option="\x08" Destination="%T[99]%" Variable="%T[1]%" NoEmbeddedVars="FALSE" _COMMENT="save mnemonic"/>
<ASCII FILE END PROCESS/>
<TEXT TYPE Action="0" Text="<F12>" _ENABLED="FALSE" _COMMENT="close out previous (last) mnemonic"/>
<MACRO RETURN/>
<COMMENT Value="  "/>
<COMMENT Value="  "/>
<COMMENT Value="  "/>
 

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