Jump to content
Macro Express Forums
sunilvedula

how do i increment variables in a loop

Recommended Posts

hi all,

 

i am copying data into 4 variables (t1, t2, t3, t4) and the loop continues for around 40 times. now what i want is that every time the loop continues it will copy certain data and store. the data to be copied is 4 fields. First time when it copies it will store as i said above. when it enters the loop next time it has to store in other variables like t5, t6, ..... . how do i increment the variables continously ina loop? pls help me out.

 

Also i would like to know how do i make a control recognize the name of a form or something like that using controls. the window control is recognizing the window but not the forms or similar internal window which opens in the main window. help me out!

Share this post


Link to post
Share on other sites

I'm not quite sure what you're trying to accomplish or if I understand this correctly, but:

 

i am copying data into 4 variables (t1, t2, t3, t4) and the loop continues for around 40 times. now what i want is that every time the loop continues it will copy certain data and store. the data to be copied is 4 fields. First time when it copies it will store as i said above. when it enters the loop next time it has to store in other variables like t5, t6, ..... . how do i increment the variables continously ina loop?

 

40 times * 4 variables=160 and there is only 99 text variables?

Share this post


Link to post
Share on other sites
40 times * 4 variables=160 and there is only 99 text variables?

 

Maybe these text variables (all 160 of them) could be stored using an .ini file, then accessed as needed (??)

Depending on your purpose, this might not be very efficient though...

Also though, depending on your purpose, maybe you can 'reclaim' t1 t2 t3 and t4 and use them over and over (??)

 

 

Can you tell us more about what you'rre trying to do? :huh:

Share this post


Link to post
Share on other sites

i am trying to copy certain data from an application and paste the data into excel. This is what my people where i work do everminute. i automated all the stuff but when it comes to this part where it copies the data from each cell in the application like a complete row and then goes to excel and pastes in a specified row. presently it comes back to the application and does the work over and over again. it will do this until it finds a null in the application where it is copying from.

 

What i want is instead of going to excel afer copying each row if it can copy multiple rows and store in variables (limit 99 vraiables agreed) it would make the macro work fast.

 

this copying part is put in a loop and i want the variable to be incremented automatically when the loop continues. this is what i need.

Share this post


Link to post
Share on other sites

I was just tinkering with MacExp and I also couldn't see how to increment the *receiving* variable. Perhaps our local experts will have some ideas, but I'll bet your best approach will be to just automate the switching back and forth from your starting app and Excel.

 

Set N1 = 1

Loop until N1 = 20

Set T1 from Something

Move to Next Field

Set T2 from Something

Move to Next Field

Set T3 from Something

Move to Next Field

Set T4 from Something

Move to Next Field

Set T5 from Something

Move to Next Field

Set T6 from Something

Move to Next Field

Set T7 from Something

Move to Next Field

Set T8 from Something

Move to Next Field

Activate or focus on Excel

Type out T1

Move to Next Row

Type out T2

Move to Next Row

Type out T3

Move to Next Row

Type out T4

Move to Next Row

Type out T5

Move to Next Row

Type out T6

Move to Next Row

Type out T7

Move to Next Row

Type out T8

Move to Next Row

Activate or focus on the First Application

Increment N1 = n1+1

Repeat Loop

 

This assumes that the applications will remember where the cursor was when it lost focus last time ....

I don't know... What do others think? -steve

Share this post


Link to post
Share on other sites

hi steve,

thanks for the reply but the solution you gave is the programme i wrote and the problem i asked sitll remains. how do we increment the variables in the loop without giving so many times.

 

i would like it be something like this:

Set N1 = 1

Loop until N1 = 20

Set T1 from Something (here when the loop repeats the variable has to increment on its own)

Move to Next Field

Increment N1 = n1+1

Repeat Loop

 

so that when it finishes copying it will go to excel and paste the data at once. This will save time and uncesary swithching betweeen applcations.

 

so how do i increment variables.

Share this post


Link to post
Share on other sites

Hi again Sun,

 

Well it took quite a bit of tinkering, but I've been meaning to learn about .INI files anyway so...

 

Note that I'm far from a computer expert, but I'll explain as best as possible how I got this thing to work, and maybe you or others can built on the info...

 

First you need an .ini file. This is a system file, so none of your text editors will have a "Save As INI" option. Nevertheless, I was able to use Notepad and simply Save As a plain old txt file, but I *named* it "MyINIfile.INI" and Windows XP seems to have excepted the change in extention. By putting my browser on View = Details with the Extention and Name collumns showing, I was able to confirm that it's named "MyINIfile" and is of type ".INI" For simplicity, I saved it at C:\Program Files\Macro Express3\MyINIfile.INI. The next step is to prepare the INI with the appropriate skeleton. For my example, use the following (i.e. everything between, but not including, the double lines)

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

[MySection]

param1=

param2=

param3=

param4=

param5=

param6=

param7=

param8=

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

Note that the INI should open right up in Notepad. If it doesn't try "open with"(?)

 

Now paste this into a macro with Shortkey activation = ##<MyShortkey>.

 

<IVAR2:01:01:1><REP3:08:000001:000002:0001:0:01:9><REM2:Note:  To repeat 160 times, set this to "Until N1 = 161".><TEXTTYPE:<ARROW UP><HOME><SHIFTD><END><SHIFTU>><REM2:Move to and select line that is right above cursor.><WAITPB><REM2:Wait for the key que.><CLIPT><TVAR2:01:03:><REM2:"Cut" the selected text and save it to T1.><TMVAR2:18:01:00:000:000:C:\Program Files\Macro Express3\MyINIfile.INIMySectionparam%N1%><REM2:First we assume there is an .INI file waiting for us...  See Help section.><REM2:Send the text from T1 to the .INI file.><REM2:It is saved to whatever key number var N1 is durring loop.><NMVAR:01:01:1:0000001:2:0000001><ENDREP><REM2:After looping "Repeat Until" number of times Excel is launched><REM2:Make sure the path is correct.  ><LAUNCHYES3:0:0112Microsoft Excel<LAUNCH:C:\Program Files\Microsoft Office\Office12\EXCEL.EXE><WAITWIN2:000010:000000:Microsoft Excel><REM2:The first loop saved to the .INI file... Now this loop will read from it.><IVAR2:01:01:1><REM2:Reset N1 to 1 so we can increment it again.><REP3:08:000001:000002:0001:0:01:9><TVAR2:01:08:C:\Program Files\Macro Express3\MyINIfile.INIMySectionparam%N1%><TEXTTYPE:Item %N1% is: %T1%.><WAITPB><TEXTTYPE:<ARROW DOWN>><WAITPB><NMVAR:01:01:1:0000001:2:0000001><ENDREP><TBOX4:T:1:CenterCenter000278000200:000:Macro Finished.>

 

Now go to Notepad, Word, etc and type 8 lines (that are separated with carriage return/new line/<ENTER>) and then hit <ENTER> (so that the cursor is below the list) and type your Hotkey. So it looks like this (but without the double lines)

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

This

here

is

my

list

of

8

items

##<MyShortkey>

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

 

The macro has two loops. The first one progresses up the list (and increments N1), saving each line to the INI Key named "param%N1%." The second loop starts at 1 again and *reads* from "param%N1%." Obviously this sample uses 8, but it should work the same with a list of nn items and nn number of Keys.

 

Note: I was hesitant to even try this, because I was afraid that MacExp would have to open the INI file, read/write the variable to the key, then close the file again for each loop. This does not appear to be the case.. The reading and writing apparently are done covertly. *However* The macro does take at least 8 or 10 seconds to execute. I suspect this is because the read and writes don't just happen in RAM, they need to access the Hard drive. This makes it take a long time-especially the 'read' part in the second loop. If your people at work have old computers that haven't been defragged in a while, 160 loops could take quite a long time.

 

I'm not sure, but if you use T1, T2, T3 and T4, like you were originally suggesting, it might help because the hard drive would only have to locate the file once per 4 items (?)

 

The loop would be something like:

=======

Set N1 =1

Loop until N1 = 160

Get and copy data

Save to T1

From T1 to INI key = %N1%

Increment N1 + 1

Get and copy next data

Save to T2

From T2 to INI key = %N1%

Increment N1 + 1

Get and copy next data

Save to T3

From T1 to INI key = %N1%

Increment N3 + 1

Get and copy next data

Save to T4

From T4 to INI key = %N1%

Increment N1 + 1

Repeat loop.

 

 

This still not the solution that I think you were looking for, which was to treat var T1 dynamically like "Save Clipboard to var T%N1%" then increment N1, thus changing the which T var is used ....

 

Note also though, that if you *were* able to do this, you'd still have to swap back and forth between your first application and Excel, which would also be somewhat time consuming...

 

Last note: I had a difficult time getting the macro to correctly "pluck" each line and save them to the INI without skipping lines, so if anyone has the time to just try this, I'd be interested to know if it works on other people's machines....

Thanks.

 

Hope this help :) -steve

 

okay one more note: Google spellcheck isn't working, so apologies for typoes....

Share this post


Link to post
Share on other sites

h steve,

that is a quite a effort. Thanks. Let me try and see and how it works. But if it is going to take time i doubt!!!!! still we use p4 machines with 1gb ram so it should not be a problem . let me check and get back to you.

 

Also i think if we could increment the variable (t1, t2... automatically) when the loop repeats then many problesm would be resolved.

 

If anyone else has a solution pls help us out!

Share this post


Link to post
Share on other sites

QUOTE

Also i think if we could increment the variable (t1, t2... automatically) when the loop repeats then many problesm would be resolved

 

As I see it SteveK presented a solution to what you're trying to accomplish with:

 

QUOTE

which was to treat var T1 dynamically like "Save Clipboard to var T%N1%" then increment N1, thus changing the which T var is used ....

 

Oopps! Sorry I was sure that it was possible to do, I will be more careful before saying things in the future.

I'll try to look into it and see if I can help you.

Share this post


Link to post
Share on other sites
which was to treat var T1 dynamically like "Save Clipboard to var T%N1%" then increment N1, thus changing the which T var is used ....
This has been discussed many times in this forum, was included in the Macro Express News newsletter and is included on the Sample Macros web page. I know that it is sometimes difficult to come up with the correct search terms but one should try.

 

The feature that allows you to use variables like %T%N1%% is disabled by default. The 'Variables Evaluation Level' option enables this feature. In Macro Express v 3.7 and later click Options, Preferences, Miscellaneous. Click the Advanced button and enter something greater than 0 in the 'Variables Evaluation Level' field.

 

Here are some relevant links:

Share this post


Link to post
Share on other sites

Thanks kevin. you are the master. i have been using this macro only for a few month maybe 6months. i have been using it extensively for my dept. but i have no help other than you people on the forum. i also ordered the book which takes me atleast 1month to reach me since i stay in india. so the only source of help is this forum. i miight not have realized abt the newsletter or that the topic has been discussed earlier. so many thanks for ur reply and i will check them and see if i am able to use them and get my problem resolved. thanks a lot!

 

Also let me know if i have older version like 3.2 then what needs to be done to upgrade this one(which is licesnced).

Share this post


Link to post
Share on other sites
i have no help other than you people on the forum. ... so the only source of help is this forum.
Forum members are willing, able and happy to help. But we all have different schedules that vary from day to day. You will get an answer sooner if you take the time to search the forum to see if your question has already been asked and answered. To search the forum click on the word 'Search' in the upper right side of the forum screens.

 

i also ordered the book which takes me atleast 1month to reach me since i stay in india.
The book is very good. It should help a lot.

 

i miight not have realized abt the newsletter or that the topic has been discussed earlier.
A few minutes looking at the resources on the website will save you a lot of time. I would start with our Support Page. From there you can access resources like the Macro Express help system, the Macro Express Knowledgebase, and every issue of the Macro Express News email newsletter. Many times you will find an example macro that does exactly or nearly what you need on our Shared Macros page. There are even Tutorials and Video Tutorials. If you click on the Search link on our website you can search for answers on any of these pages.

 

All of this information is free and you do not have to wait a month for shipping to India. ;)

 

Also let me know if i have older version like 3.2 then what needs to be done to upgrade this one(which is licesnced).
Changing the subject in the middle of a thread is called 'Thread Hijacking' and is discouraged, whether it is done by the original author or not. If you want to discuss a new topic, you should post a new topic.

 

After reading this post it occurs to me that I too hijacked this thread. :o This discussion about searching should have been posted in a new and separate topic. I'm sorry. I'll try to do better. :rolleyes:

 

To answer your question about upgrading please read our Upgrade Information web page. You could have answered this question yourself by entering the word 'upgrade' in the search box on the Macro Express web site. <_<

Edited by kevin

Share this post


Link to post
Share on other sites

You can also download Joe's book as a PDF which beats waiting for a month...

Share this post


Link to post
Share on other sites

Changing the subject in the middle of a thread is called 'Thread Hijacking' and is discouraged, whether it is done by the original author or not. If you want to discuss a new topic, you should post a new topic.

 

HI and sorry as i never knew anything like thread hijacking. Now i understand and realize the importance. :(

 

Thanks a lot for all the help and valuable inputs. u all have been wonderful. :P

 

Just wantd to let u know all that because of this macro express my career has been boosted and i have been offered a promotion. Thanks guys. :lol:

 

my project one of them is near completion, with all the help and inputs of you all. thanks guys. will meet all again a new topic. ;)

Share this post


Link to post
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...