Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AS/400 Macro Date input

Status
Not open for further replies.

mikecoemd

IS-IT--Management
Nov 7, 2013
12
US
Forgive my newbieness, but I am trying to make my workday more efficient and am pretty new to scripting macros!

Here is my goal: to have a macro that prompts me for input once for a value that can be recalled and re-used. (I wish I knew the terminology, but don't - so bear with me!). Below is an example of my macro. Where it says "110513" I simply want YESTERDAYS date in MMDDYY format... but sometimes I need to input a range, which is why I would like it to prompt me for input rather than simply SendKey yesterdays date.

Here is the actual code that only sends the pre-set date/value (110513):

sub subSub1_()
autECLSession.autECLOIA.WaitForAppAvailable

autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "110513"
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[tab]"
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "110513"
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[enter]"
end sub


Logically what I would like:

OPENS with a Message box prompt, asking for a value. That value is stored as USER_VALUE.

sub subSub1_()
autECLSession.autECLOIA.WaitForAppAvailable

autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "USER_VALUE"
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[tab]"
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "USER_VALUE"
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[enter]"
end sub


 
This is within an AS400 program. I can't seem to make that function as it's purely VBSCRIPT. No HTML!

Any ideas how to just add yesterday's date in MMDDYY format as a SendKeys "DATEHERE"?
 
I will try...

Date() will give you today's date, and below will give you yesterday's date
Code:
dteYesterday = DateAdd("d", -1, Date())

The Month() Day() And Year() functions will give the numeric value for each... you just have to make sure month and day are padded with leading 0s, and that you get a 2-digit year
Code:
sYesterday = _
   Right("0" & Month(dteYesterday), 2) & _
   Right("0" & Day(dteYesterday), 2) & _
   Right(Year(dteYesterday), 2)
 
mikecoemd said:
This is within an AS400 program. I can't seem to make that function as it's purely VBSCRIPT.
No, if you mean macros for AS/400 Green Screen Emulator, then they are not AS/400 programs. They are programs which runs on the client PC where your Green Screen Emulator runs, i.e. for example on Windows.

Maybe this example with AS/400 PCOMM macro could help you a little:
It uses File Open Dialog to read data from Excel CSV-file and MessageBox to display messages. You can similarly use InputBox to read some values.
 
Mikron, you've nailed it! It is definitely NOT an AS/400 program, but rather a macro!

That link you posted was helpful, but I still can't make much sense of it...I will try to play with InputBox and see if I can make it do what I want!

Also, are there any resources for what some of these lines mean, for example, it would be helpful to know what these mean:
1. "autECLSession.autECLOIA.WaitForInputReady"
2. "autECLSession.autECLOIA.WaitForAppAvailable"
3. "autECLSession.autECLPS.WaitForAttrib 9,2,"10","3c",3,10000"
4. "autECLSession.autECLPS.WaitForCursor 9,3,10000
 
As I wrote in the thread linked above - do the following:

1. Record a green screen macro.
You go to your green scrreen application, start macro recording in your emulator and enter the constant value of the datum in your desired format MMDDYY - for example: 110713.
Wait until your green screen gives a result and then stop the macro recording.

2. Then go to the directory where your macro is saved and open your file *.mac with an appropriate editor. You will see here an subroutine without parameters which contains a line with your literal input - for example:
Code:
[highlight]sub subSub1_[/highlight]
...
   autECLSession.autECLPS.SendKeys [highlight]110713[/highlight]
...

3. Then change your subroutine so it takes an parameter - so:
Code:
[highlight]sub subSub1_(date_mmddyy)[/highlight]
...
   autECLSession.autECLPS.SendKeys [highlight]date_mmddyy[/highlight]
...

4. And now you can add in the *.mac file your own VBscript code which opens InputBox, then reads the value of the date into a variable my_date_mmddyy and then calls he sbroutine like:
Code:
call subSub1_(my_date_mmddyyy)

Start with a very simplest example. You have to little bit experiment with it to understand how it works.
 
It keeps throwing an error and I don't really know how to get an InputBox into this because I can't find any resources or parameters for using an InputBox, do you know how to craft the macro below into prompting me for my input?

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

REM This line calls the macro subroutine
subSub1_

sub subSub1_(date_mmddyy)
   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "date_mmddyy"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"

end sub
 
Here is an simplest InputBox example Save it in a file *.vbs, (for example input_box_example.vbs) and run it by double clicking ot see how it works:
Code:
[COLOR=#0000ff]'Option Explicit[/color]

[COLOR=#804040][b]Dim[/b][/color] result[COLOR=#804040][b],[/b][/color] message[COLOR=#804040][b],[/b][/color] title[COLOR=#804040][b],[/b][/color] default_value

message[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]"Enter a value of the variable"[/color]
title[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]"Variable Value"[/color]
default_value[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]"xxxxx"[/color]

result[COLOR=#804040][b]=[/b][/color][COLOR=#008080]InputBox[/color][COLOR=#804040][b]([/b][/color]message[COLOR=#804040][b],[/b][/color]title[COLOR=#804040][b],[/b][/color]default_value[COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]100[/color][COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]100[/color][COLOR=#804040][b])[/b][/color]

[COLOR=#804040][b]if[/b][/color] result [COLOR=#804040][b]<>[/b][/color] [COLOR=#ff00ff]" "[/color] [COLOR=#804040][b]then[/b][/color] 
  WScript[COLOR=#804040][b].[/b][/color]Echo [COLOR=#ff00ff]"You entered: '"[/color] [COLOR=#804040][b]&[/b][/color] result [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]"'"[/color]
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]if[/b][/color]
WScript[COLOR=#804040][b].[/b][/color]Echo [COLOR=#ff00ff]"End"[/color]
 
Thanks, I've got your example working pretty well, but I can't figure our how to take the messagebox INPUT and have it used later in the subs!

I will look at your 2nd example here and see how it works.

I'm sorry if I'm overlooking your answers, but I am very new to this. Thanks for your help so far, it's been great.
 
Okay here is a simple way to pick your brain and get to the solution. I know there are easier examples to use, but I understand this one (and I'm very tired):

Question: If I ran this and put in a "1" to activate Macro1, what additional code would need to be inserted or changed to make the output for Macro1 be autECLSession.autECLPS.SendKeys "1"? If I can use the InputBox's value to alter the Subs below it -- I will be able to finish my work!!!! if you could alter the code for me to make sense, I would appreciate it!!
Code:
Sub Macro_Master()

 Dim strPrompt

 strPrompt = InputBox("Does 2-1 equal 2 or 1? Please Enter "2" or "1" to answer")
 If strPrompt = "N" Or strPrompt = "n" Or strPrompt = "" Then
 Exit Sub
 End If

 If strPrompt < "1" Then
 Macro1
 End If

 If strPrompt = "2" Then
 Macro2
 End If

 End Sub



Sub Macro1()
   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "Correct!"
   
Sub Macro2()
   autECLSession.autECLOIA.WaitForAppAvailable 
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "Wrong!"
 
To call the subroutine, you shoud add something like this
Code:
[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)

REM This line calls the macro subroutine
[highlight]
dim my_date
my_date = InputBox("Enter Date:","Date Input","MMDDYY",100,100)

if my_date <> " " then 
  call subSub1_(my_date)
end if
[/highlight]
sub subSub1_(date_mmddyy)
   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "date_mmddyy"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "    "
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"

end sub
 
That is a great example, but it keeps returning an error on line 19, which is "sub subSub1_(date_mmddyy)"!
 
To your other question:
You can use PCOMM-macros only if you have iSeries Navigator (aka Client Access) installed. I don't have it now on my home computer, so I transformed your code in a VBScript so I could try it.
Code:
[COLOR=#0000ff]'-------- main program -------------[/color]
[COLOR=#804040][b]call[/b][/color] Macro_Master
[COLOR=#0000ff]'-------- Subroutines --------------[/color]
[COLOR=#804040][b]Sub[/b][/color] Macro_Master 
  [COLOR=#804040][b]Dim[/b][/color] strPrompt
  strPrompt[COLOR=#804040][b]=[/b][/color][COLOR=#008080]InputBox[/color][COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"Does 2-1 equal 2 or 1? Please Enter 2 or 1 to answer"[/color][COLOR=#804040][b])[/b][/color]
  [COLOR=#804040][b]If[/b][/color] strPrompt [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"N"[/color] [COLOR=#804040][b]Or[/b][/color] strPrompt [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"n"[/color] [COLOR=#804040][b]Or[/b][/color] strPrompt [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color] [COLOR=#804040][b]Then[/b][/color]
    [COLOR=#804040][b]Exit[/b][/color] [COLOR=#804040][b]Sub[/b][/color]
  [COLOR=#804040][b]End[/b][/color] [COLOR=#804040][b]If[/b][/color]

  [COLOR=#804040][b]If[/b][/color] strPrompt [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"1"[/color] [COLOR=#804040][b]Then[/b][/color]
    [COLOR=#804040][b]call[/b][/color] Macro1
  [COLOR=#804040][b]End[/b][/color] [COLOR=#804040][b]If[/b][/color]

  [COLOR=#804040][b]If[/b][/color] strPrompt [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"2"[/color] [COLOR=#804040][b]Then[/b][/color]
    [COLOR=#804040][b]call[/b][/color] Macro2
  [COLOR=#804040][b]End[/b][/color] [COLOR=#804040][b]If[/b][/color]
[COLOR=#804040][b]End[/b][/color] [COLOR=#804040][b]Sub[/b][/color]

[COLOR=#804040][b]Sub[/b][/color] Macro1
   Wscript[COLOR=#804040][b].[/b][/color]Echo [COLOR=#ff00ff]"Correct !"[/color]
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]sub[/b][/color]

[COLOR=#804040][b]Sub[/b][/color] Macro2
   Wscript[COLOR=#804040][b].[/b][/color]Echo [COLOR=#ff00ff]"Wrong!"[/color]
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]sub[/b][/color]
 
but it keeps returning an error on line 19, which is "sub subSub1_(date_mmddyy)"!
I's strange, becaus ewhen I transform it in Vbscript it seems to be OK
Code:
[COLOR=#804040][b]OPTION[/b][/color] [COLOR=#804040][b]EXPLICIT[/b][/color]

[COLOR=#804040][b]REM[/b][/color] This [COLOR=#a020f0]line[/color] calls the macro subroutine

[COLOR=#804040][b]dim[/b][/color] my_date
my_date [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]InputBox[/color][COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"Enter Date:"[/color][COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]"Date Input"[/color][COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]"MMDDYY"[/color][COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]100[/color][COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]100[/color][COLOR=#804040][b])[/b][/color]

[COLOR=#804040][b]if[/b][/color] my_date [COLOR=#804040][b]<>[/b][/color] [COLOR=#ff00ff]" "[/color] [COLOR=#804040][b]then[/b][/color] 
  [COLOR=#804040][b]call[/b][/color] subSub1_[COLOR=#804040][b]([/b][/color]my_date[COLOR=#804040][b])[/b][/color]
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]if[/b][/color]

[COLOR=#804040][b]sub[/b][/color] subSub1_[COLOR=#804040][b]([/b][/color]date_mmddyy[COLOR=#804040][b])[/b][/color]
   Wscript[COLOR=#804040][b].[/b][/color]Echo [COLOR=#ff00ff]"You entered: "[/color] [COLOR=#804040][b]&[/b][/color] date_mmddyy 
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]sub[/b][/color]

Have you adapted the recorded subroutine properly?

 
I the subroutine subSub1_ try to change the line
autECLSession.autECLPS.SendKeys "date_mmddyy"
in
autECLSession.autECLPS.SendKeys date_mmddyy
Mavbe it helps ...
 
Thanks, I was able to get it working with your help! Thank-you VERY much!

One more quick question: How would I make my macro pause, and have a pop-up box appear that says, "Do xxxx now, then press okay to continue" and then continue the macro after "Ok" is pressed?
 
microm,

The following macro works perfectly, but there's a little left to be desired. For instance: there are multiple times within one macro that I will need to recall the data for 'my_date' and 'my_date2'... is there any way I can do this without creating a prompt for each instance? I don't know enough of this language to be able to manipulate this in the proper way and it's frustrating. Ultimately, I want to have the user prompted for the two dates only once and then be able to use those dates multiple times throughout the macro. How can I do this without executing a new sub for each input?

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

REM This line calls the macro subroutine

'CREATES MY_DATE STRING
dim my_date
my_date = InputBox("Start Date:","Date Input","MMDDYY",100,100)

'CREATES MY_DATE2 STRING
dim my_date2
my_date2 = InputBox("End Date:","Date Input","MMDDYY",100,100)


if my_date <> " " then 
  call subSub1_(my_date)
end if

if my_date2 <> " " then 
  call subSub2_(my_date2)
end if

'SUBSUB1 DEMONSTRATES INPUT FROM THE DIM MY_DATE TEXTBOX BEING UTILIZED
sub subSub1_(date_mmddyy)
   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys date_mmddyy
      autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
end sub

'SUBSUB2 DEMONSTRATES INPUT FROM THE DIM MY_DATE2 TEXTBOX BEING UTILIZED
sub subSub2_(date_mmddyy)
   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys date_mmddyy
      autECLSession.autECLPS.SendKeys "[enter]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top