ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How can I auto repeat a sequence of green screen operations for each item in a list?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Jon suggested using Albert's TNAPI. Is there some reason that wouldn't work?! Seems like a free, easy and powerful way. I don't understand why you're trying to do strange things like macros... and I really don't understand how QShell or Python, etc would help. Just use TNAPI, it's designed for this sort of thing and will work fine. The only reason I could see using a different solution is if you're not comfortalble with RPG programming.

    Comment


    • #17
      Peder, yes, I was working on using Vectorspace's idea. I can do that myself on my PC without any additional programs or approvals.

      Scott, I looked and you are correct that Albert's TNAPI has nothing VBA in it. It looks pretty neat, not that I understand it all. It does present the age old "not authorized by us, fails naming conventions, who will support, etc, etc, etc" problems, but history says that when they want all those invoices resent, they will probably become more flexible as to what is acceptable.

      Thanks everyone... And if anyone finds a better way to do it with the ACS HOD macros, please post it

      Comment


      • #18
        I've been working with iseries/Personal Communications. I do activate my AS400 entry macro from MS Excel and operate in a controlled loop environment which accounts for multiple fields. So you are talking one macro from MS Excel VBA from your .csv file and the main execution macro in AS400.

        So it would start with something like this from MS Excel VBA in a .csv file where your data is storied and you want to designate your file in AS400 and state your arrays from 0 to x where array 0 would be your Column A in MS Excel. Here is something to get you started:

        Sub A()
        '
        ' A Macro
        '

        '

        Dim I
        For I = 1 To 500
        Range("A1").Select
        Range("A:A").Find("").Select
        Range("A1:A" & ActiveCell.Row).EntireRow.Delete
        ActiveWorkbook.Save
        AppActivate ("Session A - [24 x 80]")
        Application.SendKeys ("%a")
        Application.SendKeys ("f")
        Application.SendKeys ("{ENTER}")
        Application.Wait (Now + TimeValue("0:00:02"))
        Application.SendKeys ("{ENTER}")
        Application.Wait (Now + TimeValue("0:00:02"))
        Application.SendKeys ("{ENTER}")
        AppActivate ("Microsoft Excel")
        e = MsgBox("Continue?", 4 Or 16)
        If e <> 6 Then Exit Sub
        AppActivate ("Session A - [24 x 80]")
        Application.SendKeys ("{F12}")
        Application.SendKeys ("~")
        Next I
        Exit Sub
        End Sub

        Comment


        • #19
          I also wanted to add that I've had no issues using iseries/Personal Communications on a Windows 10 micro desktop. My IT tried to insist that I utilize AS400/ACS which is Java based meaning the code I posted would not work well. I'm looking to find how to integrate javascript commands into the body of the VBA code to send from MS Excel to AS400 and have advised my company that the work that I do is VBA based for high volume data entry of debits and credits. So while it is somewhat inspiring to record in Javascript, I don't know if what I'm doing now is as easily transferable to a javascript environment. I can use a few leads myself if anyone knows how to integrate javacommands that can be sent to AS400 from MS Excel VBA. Thanks.

          Comment


          • #20
            Erran, Yes, that would have worked great if I was allowed to use VBA.

            Comment


            • #21
              In the past when I was confronted with stuff like this I either wrote an AHK script, pretty plain and simple, or I would write a "bot" in java that just does the input and keypresses for me. Nice thing is that you can put in some additional logic, say in some cases a field may be empty but it doesn't occur a lot and may require some additional manual input or operation, I'd just include that in the program.

              Anekdote: In college I botted a class where the teacher had us make online exercises and stated 'You are required to make every exercise, your minimum score must be at least 65% for every single exercise. If you score lower you have to re-do it untill you score above 65%. Your global average will count towards your final grade on this class.' So I got roughly 65% on everything and then just scripted one exercise and got 100% every 3.5 s and ran it 24/7, getting me a 99%. This was done using the Robot class in java

              Comment


              • #22
                Do you have a java "bot" that watches the screen and does key presses into the ACS HOD 5250 screen that you could post? I'm not a java pro, but if I had something to start from, I could give it a try.

                Comment


                • #23
                  Originally posted by bobc_00001 View Post
                  Do you have a java "bot" that watches the screen and does key presses into the ACS HOD 5250 screen that you could post? I'm not a java pro, but if I had something to start from, I could give it a try.
                  Dear bobc,

                  You could use the mouse movement and click to get to the different fields you need to fill in, but you could easily use tab keypress events as well. To make java type text in the fields I suggest writing a method that interprets a String, splits it up into characters and simulates a key press event for every character. You can use variables inside of the Robot's class methods so you can write very advanced scripts for automating processes. To simplify the use, after your java is written, compile it as .JAR and run it whenever you need to start. If you're going to solve it using mouse movement I suggest getting your screen width and height first, then asking java for the current cursor position (X, Y-coords) and relatively changing the mouse movement X, Y-coords. I've done something like this before. You can also use tabs, you'll find a way to simulate a tab key press in my example code. Best of luck!

                  INFO: I have tested this on ACS HOD 5250 screens and it works perfectly, my script looped 10 times over a TAB event and then used Thread.sleep(1000) in between key presses to keep the actions from happening instantly. You could however make the script super fast.

                  EXAMPLE JAVA CODE:
                  import java.awt.AWTException;
                  import java.awt.Robot;
                  import java.awt.event.*;

                  public class RunBot {
                  public static void main(String [] args){
                  try {
                  Robot robot = new Robot();
                  // Simulate a mouse regular click
                  robot.mousePress(InputEvent.BUTTON1_MASK);
                  robot.mouseRelease(InputEvent.BUTTON1_MASK);

                  // Simulate mouse movement
                  robot.mouseMove(500, 500);

                  // Simulate a 'TAB' key press
                  robot.keyPress(KeyEvent.VK_TAB);
                  robot.keyRelease(KeyEvent.VK_TAB);


                  } catch (AWTException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                  }


                  }
                  }

                  kind regards,

                  Lorenz

                  Comment


                  • #24
                    Looks like I have lots to learn... Thanks for posting some code that provides some of the answers. I guess I need to try it, then tweak it, and tweak it a bunch more...

                    Comment


                    • #25
                      Originally posted by bobc_00001 View Post
                      Looks like I have lots to learn... Thanks for posting some code that provides some of the answers. I guess I need to try it, then tweak it, and tweak it a bunch more...
                      Hey bobc, if you're struggling I'll send u something you can view as a basic template to achieve your java code, this is a single class with the main method inside of it so it can run, outside the scope of the main method are severall static methods you can use to write keys or tab a certain amt of time or pause the program in sec / ms. I'll share it here, there's a few comments to give you an idea what stuff does. I simply use it to type a search in a list and put option 12 before all the items I need it. The program can do it in 0.05 s whilst it takes me a minute doing it manualy. I'm still working on it to make it compile everything etc. But I only spend a few minutes on it so far.

                      EXPLANATION CODE:
                      Use: sleepS(seconds) to pause the program for a few seconds eg: sleepS(3) //will pause the thread for 3s
                      Use: sleepMs(milliseconds) to pause the program in milliseconds eg: sleepMs(500) //will pause the thread for 0.5s
                      Use: writeKeyboard("MyStringHere") to make the program type that string! To type a String using simulated keypresses we need to interpret our String and write key events for each character. This logic is already there.
                      HOWEVER I did not include space bar or other special characters. I'll expand in the future, if you need them just write them yourself, google will be helpfull here if you don't know what the VK_ is.
                      Use: tab(nrOfTabs) to press tab a few times, eg: tab(3) //Presses tab 3 times.
                      You can write many other methods (for enter, ...) to make this program more modular and cleaner. Important is that both when running from a compiled .JAR client or when executing the code from your IDE with the build & run option you still have to alt tab to your green screens (5250 emulation) so I personally like to pause the Thread 3s before executing my logic. Gives me time to navigate to the right interface on the 5250 emulation. However you can make java tab itself out of your IDE and navigate the greenscreens by itself as well. This is a bit more complex, if you need additional help, feel free to write me a message and I will get back to you when I can.

                      My last tip then: It's possible that your script in java runs faster than the 5250 emulation can accept input and navigation, etc... In this case when you test your code and you see it skips a field or something.. Try putting a few sleeps in between actions. This way you slow down your java program a bit and this should allow the 5250 to catch up. (This is needed when using java code to compile a list of programs for example) You don't want to F12 before the program is compiled.
                      Best of luck!

                      CODE:

                      import java.awt.AWTException;
                      import java.awt.Robot;
                      import java.awt.event.*;



                      public class RunBot {
                      public static void main(String [] args){
                      try {
                      Robot robot = new Robot();
                      //sleep in seconds, for duration: 3s (start time pgm)
                      sleepS(3);
                      //type WS1*:
                      writeKeyboard("WS1");
                      //press enter:
                      robot.keyPress(KeyEvent.VK_ENTER);
                      robot.keyRelease(KeyEvent.VK_ENTER);
                      //tab twice:
                      tab(3);
                      //type 12:
                      writeKeyboard("12");
                      //type 12 before every pgm to compile:
                      for (int i = 0;i < 8;i++){
                      writeKeyboard("12");
                      }
                      //TODO (compiling logic):
                      //LOOP
                      //press enter
                      //type 36
                      //press enter
                      //press f11
                      //press enter
                      //press enter
                      //press enter
                      //press f12
                      //ENDLOOP



                      } catch (AWTException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      }


                      }

                      public static void writeKeyboard(String s){
                      try {
                      s.toUpperCase();
                      Robot robot = new Robot();
                      char sArr[] = s.toCharArray();
                      robot.keyPress(KeyEvent.VK_SHIFT);
                      for(int i = 0; i < sArr.length; i++){
                      switch(sArr[i]){
                      //special:
                      //case '*': robot.keyPress(KeyEvent.VK_ASTERISK); robot.keyRelease(KeyEvent.VK_ASTERISK); break;
                      //integers:
                      case '0': robot.keyPress(KeyEvent.VK_0); robot.keyRelease(KeyEvent.VK_0); break;
                      case '1': robot.keyPress(KeyEvent.VK_1); robot.keyRelease(KeyEvent.VK_1); break;
                      case '2': robot.keyPress(KeyEvent.VK_2); robot.keyRelease(KeyEvent.VK_2); break;
                      case '3': robot.keyPress(KeyEvent.VK_3); robot.keyRelease(KeyEvent.VK_3); break;
                      case '4': robot.keyPress(KeyEvent.VK_4); robot.keyRelease(KeyEvent.VK_4); break;
                      case '5': robot.keyPress(KeyEvent.VK_5); robot.keyRelease(KeyEvent.VK_5); break;
                      case '6': robot.keyPress(KeyEvent.VK_6); robot.keyRelease(KeyEvent.VK_6); break;
                      case '7': robot.keyPress(KeyEvent.VK_7); robot.keyRelease(KeyEvent.VK_7); break;
                      case '8': robot.keyPress(KeyEvent.VK_8); robot.keyRelease(KeyEvent.VK_8); break;
                      case '9': robot.keyPress(KeyEvent.VK_9); robot.keyRelease(KeyEvent.VK_9); break;
                      //characters:
                      case 'A': robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A); break;
                      case 'B': robot.keyPress(KeyEvent.VK_B); robot.keyRelease(KeyEvent.VK_B); break;
                      case 'C': robot.keyPress(KeyEvent.VK_C); robot.keyRelease(KeyEvent.VK_C); break;
                      case 'D': robot.keyPress(KeyEvent.VK_D); robot.keyRelease(KeyEvent.VK_D); break;
                      case 'E': robot.keyPress(KeyEvent.VK_E); robot.keyRelease(KeyEvent.VK_E); break;
                      case 'F': robot.keyPress(KeyEvent.VK_F); robot.keyRelease(KeyEvent.VK_F); break;
                      case 'G': robot.keyPress(KeyEvent.VK_G); robot.keyRelease(KeyEvent.VK_G); break;
                      case 'H': robot.keyPress(KeyEvent.VK_H); robot.keyRelease(KeyEvent.VK_H); break;
                      case 'I': robot.keyPress(KeyEvent.VK_I); robot.keyRelease(KeyEvent.VK_I); break;
                      case 'J': robot.keyPress(KeyEvent.VK_J); robot.keyRelease(KeyEvent.VK_J); break;
                      case 'K': robot.keyPress(KeyEvent.VK_K); robot.keyRelease(KeyEvent.VK_K); break;
                      case 'L': robot.keyPress(KeyEvent.VK_L); robot.keyRelease(KeyEvent.VK_L); break;
                      case 'M': robot.keyPress(KeyEvent.VK_M); robot.keyRelease(KeyEvent.VK_M); break;
                      case 'N': robot.keyPress(KeyEvent.VK_N); robot.keyRelease(KeyEvent.VK_N); break;
                      case 'O': robot.keyPress(KeyEvent.VK_O); robot.keyRelease(KeyEvent.VK_O); break;
                      case 'P': robot.keyPress(KeyEvent.VK_P); robot.keyRelease(KeyEvent.VK_P); break;
                      case 'Q': robot.keyPress(KeyEvent.VK_Q); robot.keyRelease(KeyEvent.VK_Q); break;
                      case 'R': robot.keyPress(KeyEvent.VK_R); robot.keyRelease(KeyEvent.VK_R); break;
                      case 'S': robot.keyPress(KeyEvent.VK_S); robot.keyRelease(KeyEvent.VK_S); break;
                      case 'T': robot.keyPress(KeyEvent.VK_T); robot.keyRelease(KeyEvent.VK_T); break;
                      case 'U': robot.keyPress(KeyEvent.VK_U); robot.keyRelease(KeyEvent.VK_U); break;
                      case 'V': robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); break;
                      case 'W': robot.keyPress(KeyEvent.VK_W); robot.keyRelease(KeyEvent.VK_W); break;
                      case 'X': robot.keyPress(KeyEvent.VK_X); robot.keyRelease(KeyEvent.VK_X); break;
                      case 'Y': robot.keyPress(KeyEvent.VK_Y); robot.keyRelease(KeyEvent.VK_Y); break;
                      case 'Z': robot.keyPress(KeyEvent.VK_Z); robot.keyRelease(KeyEvent.VK_Z); break;
                      }

                      }
                      robot.keyRelease(KeyEvent.VK_SHIFT);
                      } catch (AWTException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      }
                      }
                      public static void sleepMs(int ms){
                      try {
                      Thread.sleep(ms);
                      } catch (InterruptedException e){
                      e.printStackTrace();
                      }

                      }
                      public static void sleepS(int seconds){
                      int mSec = seconds * 1000;
                      try {
                      Thread.sleep(mSec);
                      } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      }
                      }
                      public static void tab(int amt){
                      try {
                      Robot robot = new Robot();

                      for(int i = 0; i < amt; i++){
                      robot.keyPress(KeyEvent.VK_TAB);
                      robot.keyRelease(KeyEvent.VK_TAB);
                      }
                      } catch (AWTException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      }

                      }
                      }



                      Comment


                      • #26
                        Lorenz, I appreciate the help and effort. I can see that the java is possible, but my knowledge level is too low to be able to solve the problem reasonably quickly with it. If you ever see a complete working program that even does a few keys and a couple screens that could be compiled, tested and changed , please post it or a link to it.

                        The AHK is something that I wasn't aware existed, and I downloaded it to my home PC (open source sites are all blocked on work PC) and moved it via flash drive to the work machine and installed it, and it looks like it has the capability I need.

                        Comment


                        • #27
                          PS: On the Java subject, I have a book which I bought a long time ago called "iSeries and AS/400 Java at Work" by Don Denoncourt, but the downloadable code is no longer available. If anyone has that it would be greatly appreciated. Message me or post a link to it if you know where it can be found on the web, please.

                          Thanks

                          Comment


                          • #28
                            I got the invoices all changed and resent today from a list of invoice numbers with Autohotkey. I managed to get around the security blockade and write a script to process a simple .txt file. I do want to learn new things. I am tired of needing to use stones and clubs to bludgeon the problems away.

                            Comment

                            Working...
                            X