Link to home
Create AccountLog in
Avatar of mvidas
mvidasFlag for United States of America

asked on

AS400 VBScript / memory question

Hi Everyone,

I have a question about the vbscripts for AS400, specifically the memory they use.

I have a script that requests some files from the Real Vision Report Manager, sends them to an outq, copies them to PCDownload, then deletes them from the outq.  It does this for 9 different RVI reports.

This is KILLING my memory.  The swap file keeps getting increased, and I have to close all other applications.  I watch the memory usage in the task manager just increase quickly while using it (when loading as400 it says the mem usage is 147000K / 631484K, within about 30 seconds its at 500000K.

I put in a few msgbox's into my code to see where the main memory killer is, and it seems to be in 2 portions of code that kill it the most, waitforinputready and searchtext.

The first is " auteclsession.autecloia.WaitForInputReady".  I use this a lot, as I have to wait until the system can accept input before I move on to the next.  Each time this is run, it looks like its using about 2mb of memory, and its not clearing out until the script is done running.  Is there a better alternative for this?

The second is SearchText, which I use while the system is pulling the reports from RVI.  This is the main memory hog, as each iteration through the following loop adds about 2mb of memory to the mem usage:

 do until auteclsession.auteclps.searchtext("Image Inquiry Selection Screen")
REM  auteclsession.autecloia.waitforinputready(1)
 loop

I first had the waitforforintputready(1) line in there, but after I realized that it just increased the mem usage that much more, I REM'ed it out. Still uses the memory.

Is there a better alternative for this as well? I tried using waitforappavailable and just waitforinputready, but the loading screen for these reports doesnt make the application busy, so waitforappavailable and waitforinputready won't work.  

As this loop can often take 1-2 minutes to load all the related reports, my virtual memory is just destroyed at the end, until I close out of the emulator.  Then it resets the mem used back to normal.

Any ideas?
Thanks
Matt
Avatar of reginab
reginab

hmmm, I think will dave will have more to say on this than I will, but be sure you are closing any connection and freeing its memory after use for better efficiency. you know as early as you can in your script.  also search text is always going to be exhaustive, is there something more efficient you can search on, something akin to an index value for the record.

ASKER CERTIFIED SOLUTION
Avatar of daveslater
daveslater
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of mvidas

ASKER

That was a good idea, Dave, but unfortunately no change.  The Mem Usage on the pcsws.exe individual line did go down, but the total Mem Usage at the bottom right of the task manager (win2000) stays up at the rediculous level until the emulator is closed.  Even when I stop the macro, the total mem usage in the bottom right stays up (even though the individual pcsws.exe goes back to normal).

I don't actually have any variables opening any connection, as it is used internally in the emulator, but I did set a variable I use for a count to nothing after it is used, still no change.  I'm using the searchtext method as I have to wait until the screen says it is ready for the next step. I'm not manually getting the data from a database, there is an option for our Real Vision Report Manager that loads the report itself, it just says "Please wait while the report is generated", then tells me it is ready so I can send it to the outq.  

It is beginning to sound like an issue with the emulator, that it won't release the virtual memory until the app closes.  If that is the case, I may have to try creating the connection in a .vbs script or in vb code, and just open/close the connection within each iteration through the subs.

This will probably take me a day or two, as I can't dedicate too much time at once to this.  If either of you (or anyone else, for that matter) come up with any other ideas, I'd love to hear them, otherwise I'll get back to you after I complete this.

Thanks again
Matt
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hi
I tend to agrree that is is somthing in VB script. Can we look at other options:

1) does this need to be done in VB or can we try natiev macros?

2) What is the desired end-result? Can it be achieved another way?

Dave
Avatar of mvidas

ASKER

I hate using EE in IE sometimes. I had typed a rather lengthy response, and accidentally went back one page, losing everything.  With my thoughts collected more now, I can probably condense what I was saying anyways.

I do have a native macro language equivalent of this macro (about 2300 lines) which I used for over a year.  This is only about 200 lines in vbscript, and is much easier to maintain (as I have 3 main subroutines for the different sections of the macro I need to call for each of the 9 reports I'm copying from RVI).
I do truly feel that this is an emulator issue, as the amount of virtual memory it is using at the time is not unrealistic.  It just doesn't re-use the same memory, and doesn't clear out what it has used until the emulator is closed.

I think I am going to close out this question, as there is no point to keeping it open anymore.  Your thoughts and suggestions, and just discussing the question, got me to understand what the issue is.  I will just have to modify the script to be standalone so it logs in to the server without the emulator.  I may have some problems with it, but the website I posted to the other question has some help with that, and I know I can always open another question here as well.

I know it doesnt necessarily seem as though my initial problem for this question was solved, but understanding the issue is usually the hardest part, and I have this question to thank for me to get there.
I am going to split these points evenly between the two of you; should I ask another question about this I'll gladly let you know!
Thanks
Matt
Hi
Do you have time to try this.

Sub zzwait()

Dim objWait

objWait.SetConnectionByName("A")
Set objWait = CreateObject("PCOMM.autECLOIA")

objWait.WaitForInputRead

Set objWait = Nothing

end sub
Hi try this for the strting wait

sub srText

Dim zzText
dim bln
Set zztext = CreateObject("PCOMM.autECLPS")
zztext.SetConnectionByName("A")
bln = zztext.WaitForString(("Image Inquiry Selection Screen",,,500)
Set zztext = Nothing

end sub
Avatar of mvidas

ASKER

I tried that, and added other subs for zzwaitapp, etc. While it did keep the individal process Mem Usage down, the overall still added up as usual :(
I also tried to create a .vbs file to create a connection, but I can't seem to get it working.  Do you happen to have an example of the code to create a connection to the server, or start an emulator instance?
Avatar of mvidas

ASKER

Hi, didn't refresh before posting that. I don't really want a timeout on the waitfor string, as sometimes it will wait 2-3 minutes before seeing that.   What I had made instead was

Sub looktext(inptText)
 Dim objLook
 Set objLook = CreateObject("PCOMM.autECLPS")
 objLook.SetConnectionByName("A")
 do until objLook.searchtext(inptText)
  zzwaitinput5000
 loop
 set objLook = nothing
 set inptText = nothing
end sub

I just noticed you used waitforstring, and I have searchtext.  I dont think I realized that waitforstring existed, I wouldn't have to use the do loop like I have, so I'll change that portion as well. Sorry about that, got the two confused
Avatar of mvidas

ASKER

Hi Dave,
Now that I have a couple minutes I am making my rounds on the site here, and noticed your question in vb.  Want me to post my code in your other question, post it here?
Hi
I have posted some code in the new thread.
Post it here & I will forward it (one thing I have is free unlimited points).

I have been doing a bit more reading - It may just be the way we are coding it!

Dave
ps  the
bln = zztext.WaitForString(("Image Inquiry Selection Screen",,,500)
waut 500 mili-seconds

bln = zztext.WaitForString(("Image Inquiry Selection Screen",row,col,500)
is more efficient and will look for a spacific screen location - this may save memory

I am nore sure what you have and have not tried now.

Have you used both the new subs?

Dave
pps
the
zztext.SetConnectionByName("A")
uses the first session that was opend to look for the stuf on the screen etc....


Dave
Avatar of mvidas

ASKER

I used both "A" and ThisConnectionName, both did the same thing luckily.  I also have unlimited question points (I've been slacking this month so far!), so it really wouldnt matter if that Q came from you or I.

Here is the code from my .mac file


[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=Sample file
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)

REM This line calls the macro subroutine
 dim vcount, i, aa, bb, outq, date1, date2, date3
 outq = "nyrofcp203"
 date1="2005/02/*"
 date2="2005/02/02"
 date3="2005/03/02"
 reqrvi date1,"","qsysprt","bl4028","","","az",""
 zzwaitapp
 zzwaitinput1000
 reqrvi date1,"","qsysprt","bl4028","","","ca",""
 zzwaitapp
 zzwaitinput1000
 reqrvi date1,"","qsysprt","bl4028","","","us",""
 zzwaitapp
 zzwaitinput1000
 reqrvi date1,"","qsysprt","bl4028","","","ea",""
 zzwaitapp
 zzwaitinput1000
 copytopcd "v4028"
 zzwaitapp
 zzwaitinput1000
 delfromoutq
 vcount=0
 zzwaitapp
 zzwaitinput1000
 reqrvi date1,"","qsysprt1","bl4031","","azblbeg140","az",""
 zzwaitapp
 zzwaitinput1000
 reqrvi date1,"","qsysprt1","bl4031","","cablbeg140","ca",""
 zzwaitapp
 zzwaitinput1000
 reqrvi date1,"","qsysprt1","bl4031","","usblbeg140","us",""
 zzwaitapp
 zzwaitinput1000
 reqrvi date1,"","qsysprt1","bl4031","","eablbeg140","ea",""
 zzwaitapp
 zzwaitinput1000
 copytopcd "v4031"
 zzwaitapp
 zzwaitinput1000
 delfromoutq
 vcount=0
 zzwaitapp
 zzwaitinput1000
 reqrvi date2,date3,"","bl2670","","","ca",""
 zzwaitapp
 zzwaitinput1000
 copytopcd "v2670ca"
 zzwaitapp
 zzwaitinput1000
 delfromoutq
 set outq=nothing
 set date1=nothing
 set date2=nothing
 set date3=nothing
 set vcount=nothing
 set i=nothing
 set aa=nothing
 set bb=nothing

Sub DelFromOutQ()
 if not auteclsession.auteclps.searchtext("95] Master Printing") then msgbox "95 not found": exit sub
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "95[enter]"
 puttext 24,58,"1[enter]"
 puttext 5,37,outq&"[enter]"
 zzwaitapp
 zzwaitinput1000
 for i = 1 to int(vcount/9)
  puttext 10,3,"444444444"
  if not i = int(vcount/9) or not vcount mod 9 = 0 then auteclsession.auteclps.sendkeys "[pagedn]"
  zzwaitapp
  zzwaitinput1000
 next
 auteclsession.auteclps.sendkeys string(vcount mod 9,"4")
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "[enter]"
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "[enter]"
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "[pf3]"
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "98[enter]"
End Sub

sub CopyToPCD(pcdname)
 if not auteclsession.auteclps.searchtext("95] Master Printing") then msgbox "95 not found": exit sub
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "95[enter]"
 puttext 24,58,"8[enter]"
 puttext 5,37,outq&"[enter]"
 zzwaitapp
 zzwaitinput1000
 for i = 1 to int(vcount/13)
  puttext 8,2,"1111111111111"
  if not i = int(vcount/9) or not vcount mod 13 = 0 then auteclsession.auteclps.sendkeys "[pagedn]"
  zzwaitapp
  zzwaitinput1000
 next
 auteclsession.auteclps.sendkeys string(vcount mod 13,"1")
 auteclsession.auteclps.sendkeys "[enter]"
 zzwaitapp
 zzwaitinput1000
 aa=1
 if len(pcdname)>7 then pcdname=left(pcdname,7)
 do until gety(3,2,13)="Output queue:"
  zzwaitinput1000
  zzwaitapp
  if auteclsession.auteclps.searchtext ("Name of PCPRINT file on host") then
   auteclsession.auteclps.setcursorpos 5,37
   auteclsession.auteclps.sendkeys pcdname&string(3-len(aa),"0")&aa&string(7-len(pcdname)," ")&"pcdownload"
   auteclsession.auteclps.sendkeys "[enter]"
   aa=aa+1
  end if
 loop
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "[PF3]"
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "98[enter]"
end sub

sub reqrvi(fdate,tdate,fname,udata,uname,job,env,fprofile)
 if not auteclsession.auteclps.searchtext("95] Master Printing") then msgbox "95 not found": exit sub
 zzwaitapp
REM zzwaitinput1000
 auteclsession.auteclps.sendkeys "95[enter]"
 zzwaitapp
REM zzwaitinput(2000)
 auteclsession.auteclps.sendkeys "10[enter]"
 puttext 6,27,fdate
 puttext 6,51,tdate
 puttext 7,27,fname
 puttext 8,27,udata
 puttext 9,27,uname
 puttext 10,27,job
 puttext 11,27,env
 puttext 12,27,fprofile
REM zzwaitinput1000
 auteclsession.auteclps.sendkeys "[enter]"
 zzwaitapp
 zzwaitinput
 bb=cint(gety(7,3,5))
 vcount=vcount+bb
 for i = 1 to int(bb/12)
  puttext 9,2,"pppppppppppp"
  if not i = int(bb/9) or not bb mod 12 = 0 then auteclsession.auteclps.sendkeys "[pagedn]"
  zzwaitapp
REM  zzwaitinput1000
 next
 auteclsession.auteclps.sendkeys string(bb mod 12,"p")
 auteclsession.auteclps.sendkeys "[enter]"
 looktext("Printer Or Out Queue")
 set bb=nothing
 puttext 10,25,outq
 auteclsession.auteclps.sendkeys "[enter]"
 zzwaitapp
 zzwaitinput1000
 looktext("Image Inquiry Selection Screen")
 auteclsession.auteclps.sendkeys "[PF3]"
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "[PF3]"
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.sendkeys "98[enter]"
end sub

sub puttext(rw,cl,txt)
 zzwaitapp
 zzwaitinput1000
 auteclsession.auteclps.setcursorpos rw,cl
 auteclsession.auteclps.sendkeys "[eraseeof]"
 auteclsession.auteclps.sendkeys txt
end sub
Sub zzwaitinput()
 Dim objWait
 Set objWait = CreateObject("PCOMM.autECLOIA")
 objWait.SetConnectionByName("A")
 objWait.WaitForInputReady
 Set objWait = Nothing
end sub
Sub zzwaitinput1000()
 Dim objWait
 Set objWait = CreateObject("PCOMM.autECLOIA")
 objWait.SetConnectionByName("A")
 objWait.WaitForInputReady(1000)
 Set objWait = Nothing
end sub
Sub zzwaitinput5000()
 Dim objWait
 Set objWait = CreateObject("PCOMM.autECLOIA")
 objWait.SetConnectionByName("A")
 objWait.WaitForInputReady(5000)
 Set objWait = Nothing
end sub
Sub zzwaitApp()
 Dim objWait
 Set objWait = CreateObject("PCOMM.autECLOIA")
 objWait.SetConnectionByName("A")
 objWait.WaitForAppAvailable
 Set objWait = Nothing
end sub
sub lookText(inptText)
 Dim zzText
 dim bln
 Set zztext = CreateObject("PCOMM.autECLPS")
 zztext.SetConnectionByName("A")
 bln = zztext.WaitForString((inptText)
 Set zztext = Nothing
end sub
function gety(x,y,z)
 Dim objWait
 Set objWait = CreateObject("PCOMM.autECLPS")
 objWait.SetConnectionByName("A")
 gety=objwait.GetText(x,y,z)
 set objwait = nothing
 set x = nothing
 set y = nothing
 set z = nothing
end function
Hi

using the same logic as in Gety create a function to process the
 .searchtext

looking at the question this is adding 2mb per itteration, putting in the function should stop this.

Dave

Hi
I am now on holiday till the 18th
let me know if you still want to bounce ideas - even though it is closed it is intresting.

Dave
Avatar of mvidas

ASKER

I can wait until the 18th (or after, I'm sure you'll need a bit of catch up time), and I'm always up for discussion.  Discussion = more knowledge, always something I want.  :)
I didn't get to create a search function, too busy this afternoon.  I had added a searchy function this morning, I'm not sure why it isn't in the above code.  I can just add it tomorrow anyways.
I got the data I needed for this month, so there is no hurry on this.  I'm just testing it in some extra time I have, so it'll be better for next month (the macro is only run monthly, as may have been able to tell from the variables at the top).  I dont have access to emails while at work, I just check the recent commented/answered questions regularly, so when you are ready I may not get back to you right away.  At that point I'll check this Q again though.

Sounds like a nice long vacation, going anywhere?
Hi
it is a warm weather traing in Portugual - London Marathon and Nice Ironman coming up :-)

Dave
Avatar of mvidas

ASKER

Hi Dave,

I hope you had a fun vacation! Not necessarily my idea of fun to run while on vacation, but I haven't ran a race in a long time and never anything close to a marathon or ironman, actually never more than 5k!  Just wanted to give you a little closure on this, I decided that waiting to load the files in real vision / RVI is what truly killed the memory issue, so I decided to just use a native macro to loop through and load all the reports I need and then run the vbscript one for the work that needs variables.  Not my first choice to use 2 macros but after a lot of playing around a while, that really was the best way to go about it.  I really do appreciate the thought and work you put into this!

Thanks again
Matt
Avatar of mvidas

ASKER

I'm sure you two will see it anyways, but I've posted a new (somewhat related) question at http:Q_21381526.html