Jump to content

AS400 Emulator Manipulation


Blue_Drache
 Share

Recommended Posts

:D:idiot::D:D:idea::lol:

Ok, basically it reads in the screen to the clipboard, then it figures out where to put an X on the screen based on a fixed ammount of tab spaces within the emulator. Code isn't as optimized as it probably should be, but it works well enough for what I need it to do. I know this may be considered a "niche" snippet, but I hope someone finds it useful. I'll be maintaining this thread and posting a library of code snippets as I develop them. Nothing exciting or ground breaking..... but they help with making "simulated human" scripts.

Dim $marker = "CHX/D" ; <=== Variable.  Could be used with an inputbox.
Dim $divisor = "_"    ; <=== Change this too if your division is different.
Dim $bailout = 0, $q = 2, $tabs = -1
Dim $tmp2[$extents[0]]
Dim $eff[$extents[0]]
Dim $cxd[$extents[0]]
$e = "E - [ 24 x 80 ]"; variable window name.  Set to whatever yours is named.


; read the contents of the "E" Emulator into the clipboard.
GetScreen($e)

$screen = StringStripWS(ClipGet(), 8)
$tmp = StringInStr($screen, $marker)
$extents = StringSplit(StringMid($screen, $tmp, 285), $divisor)

; Here's the fun part!  Let's figure out where we need to tab to
; and then place an "X" in the proper spot!
; I honestly don't know if I can explain the math.

; In the While loop, we're looking for an extent that has an effective date
; of less than the date of service and a cancel of 6 zeros.  We'll keep looking
; until we hit the maximum number in our array, or we get a null string.

; luckily the format of our screen shows each line is separated by an "_" until
; there are no more extents.  At that point all lines are then filled in with an
; underscore, thus returning our null string.

While 1
   If $q > $extents[0] Or $extents[$q] = "" Then
     ; If unable to find an active extent that matches our criteria.
     ; set the bailout value (or use @error if you'd like)
      $bailout = 1
      ExitLoop
   EndIf
   $cxd[$q] = StringTrimRight(StringRight($extents[$q], 7), 1)
   $eff[$q] = StringLeft(StringRight($extents[$q], 13), 6)
   If $eff[$q] < $from[1] & $from[2] & StringRight($from[3], 2) And $cxd[$q] = "000000" _
         And StringRight($extents[$q], 1) = "H" Then
      Dim $tabs = $q - 2
      ExitLoop
   EndIf
   $q = $q + 1
WEnd


; If we didn't bail, we can tab and mark.

If $bailout = 0 Then
   Send("{tab " & $tabs & "}X{numpadenter}")

  ; After selecting correct extent, continue on and get the benefits.

   Send("{numpadenter}+{tab}i{numpadenter}")

  ; PhysMedE is a UDF for finding the phrase "physical medicine benefits"
  ; on the "E" emulator in HBSS.  The script stops once it finds what it's
  ; looking for, allowing the user to continue.

   While PhysMedE() = 0
      Sleep(10)
      Send("{f8}")
   WEnd
Else
   MsgBox(0, "Extent", "Unable to select extent" & @LF & "Please continue manually.")
EndIf


; start functions

Func GetScreen($screen)
   WinActivate($screen)
   Send("{ctrldown}{insert 2}{ctrlup}")
EndFunc  ;==>GetScreen


Func PhysMedE()
   GetScreen($e)
   Local $screen = StringStripWS(ClipGet(), 8)
   Local $tmp = StringInStr($screen, "PHYSICALMEDICINESERVICES")
   Local $nomore = StringMid($screen, $tmp, 24)
   If $nomore = "PHYSICALMEDICINESERVICES" Then
      Return 1
   Else
      Return 0
   EndIf
EndFunc  ;==>PhysMedE

All functions are included in a separate file from the main programs. I don't know why, I just code that way. ;)

Ah well, enjoy and let me know if you find this useful. Feel free to comment, and debug if you can!

... Dave.... My mind is going..... I can feel it..... Stop Dave...... - HAL 9000

EDIT: Forgot to define $e. It's a window name for the AS400 emulator. Ours are lettered A, B, C, D, E, and F, so I kept the same naming convention in the variable. Meh...had to fix the code. Larry did something to it!!! *shakes fist* :D

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Im pretty sure text dosent copy and paste properly from the codebox with slider option on this forum.

Well at least it never worked for me.

Can you repost ur script inĀ 

this kinda codebox ?

<{POST_SNAPBACK}>

It's always perfectly for me.... I just use [c.odebox] because it doesn't eat up as much vertical space as [c.ode] does. Heh, was trying to be considerate.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

;===============================================================================
; Function Name:    WaitScreen
; 
; Description:    Screen Scraper for an AS400 Emulator.  Locates
;                  specific text and will pause a script until text
;                  is on screen, or times out.
; 
; Parameter(s):  $hWindowName - Name of window to scrape
;                  $sScrenText - Text to wait for
;                  $iMaxIterations - Maximum times to loop. (optional)
; 
; Requirement(s):   Control-Insert must be able to copy all screen text
;                  into the clipboard.  This is usually the default on the
;                  standard keyboard setup.
; 
; Return Value(s):  On Success - Returns 1 and continues script
;                  On Failure - Returns 0 and continues script
; 
; Author(s):        Shawn Spino
;===============================================================================
Func WaitScreen($hWindowName, $sScreenText, $iMaxIterations = 30) 
; 30 iterations is approximately 1.5 to 3 seconds on a 2.5 GHz machine
   Local $sText, $sScreen, $iLocation, $iCounter = 0
   Local $iTextLength = StringLen(StringStripWS($sScreenText, 8))
   Local $sScreenTextStripped = StringStripWS($sScreenText,8)
   Do
      Sleep(50)
      WinActivate($hWindowName)
      Send("{ctrldown}{insert 2}{ctrlup}")
      $sScreen = StringStripWS(ClipGet(), 8)
      $iLocation = StringInStr($sScreen, $sScreenTextStripped)
      $sText = StringMid($sScreen, $iLocation, $iTextLength)
      $iCounter = $iCounter + 1
      If $sText = $sScreenTextStripped then 
         Return 1
         ExitLoop
      EndIf
   Until $iCounter >= $iMaxIterations
   If $iCounter >= $iMaxIterations Then Return 0
EndFunc;==>WaitScreen

Edit:Fixed small error that would always return zero. Oops.

Edit:Removed a non-essential line. Oops.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...