Jump to content

Change Number


Recommended Posts

Hi. This is my First post on the forum.

First I must apologize if my english is not correct, it's my second language. This beeing said, I can continue with my question. :think:

I would like to know if it is possible to make a variable $Number changes in a loop. Right now i have put the functions i thought would be usefull. But what I would like to do is something like this : Do write() until you get the letter "W". And since it is writing each letter it gets in excel, i would like to write it in another cell than the previous one without using ExcelCom. ( For simplicity, I guess and I am not familiar with it)

Thanks a lot

Here's the code this is just a basic test, but the general idea will help me in further tests. :

Global $Letter= Chr(Random(Asc("a"), Asc("z"), 1))

;--------------------------Functions-------------------------------

Func OpenExcel()
    Run("C:\Program Files\Microsoft Office\OFFICE11\Excel.exe")
    WinActivate("Microsoft-Excel")
    WinWaitActive("Microsoft Excel")
EndFunc


Func SendDownRight($Number,$Number1); I use down right to allow me to write in different cell in Excel ( ex. J 8 )
    For $i=1 to $Number
        Send("{ENTER}")
        
    Next
    
    For $i=1 to $Number1
    Send("{RIGHT}")
        
    Next
    
EndFunc


Func SendUpLeft($Number2,$Number3); When I used this in excel, the numbers entered will give me the first cell in Excel (A 1)
    For $i=1 to $Number2
        Send("{UP}")
    Next
    
    For $i=1 to $Number3
        Send("{LEFT}")
    Next
    
EndFunc


Func Write($Number2,$Number3,$Number,$Number1,$Letter)
    WinActivate("Microsoft-Excel")
    SendUpLeft($Number2,$Number3)
    SendDownRight($Number,$Number1)
    Send($Letter)
EndFunc
Link to comment
Share on other sites

Using the BETA AutoIT and the various COM functions, you can directly interface with Excel and not have to worry about guessing where the cursor is going to be.

Excel is notoriously picky when it comes to third party automation, so it's best to use the BETA when dealing with that headache of a program.

I've included an example that will work with Excel using the COM style interface.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Version History :
 ;
; Version 2.7.1 - Added ability to read from an open Excel document.  Removed Y/N from end.  Inserted some sleeps.
 ; Version 2.6a  - Added an IF for optional DDR functionality
 ; Version 2.5a  - Added OINQ functionality.
 ; Version 2.4a  - changed method of obtaining screen to clipboard - no more menu flashes.
 ; Version 2.3a  - Claims Processor version.  Will attempt to retrieve the DCN as stated.
; Version 2.3        - Added automatic retrieval of DCN from A, and ask user for DCN if unable to retrieve.
 ; Version 1.2       - Added print (Y/N) selection and close (Y/N) selection
; Version 1.1        - Changed the string manipulation from array to direct string editing.  Works faster.
 ; Version 0.1       - Works pretty much as advertised, just a little slow.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Set Options, Functions, Variables and Includes
  Opt("MustDeclareVars", 1)
  Opt("PixelCoordMode", 0)
  #include <SupportFunctions.au3>
  Dim $prevclip = ClipGet(), $dcn, $test1, $test2, $ans, $previousDCN = "123456789012x", $pass = 0, $oExcel, $Paused = 0
  Dim $pxlChkSum, $temp, $counter = 0
  SetVersion ("Mobius Loop 1.0")
  HotKeySet("!{pause}", "TogglePause")
  #region Primary Data Loop
  While 1
     ; Get the DCN from the user
      $dcn = ""
      Do
          $pass = 0
          If WinExists("Microsoft Excel") Then
             $oExcel = ObjGet("", "Excel.Application"); sets the current Excel window as an object.
             $dcn = $oExcel.ActiveCell.Value; grab the data from the current active cell.
             ; mark what's been done
              Select
                 Case StringRight($dcn, 1) = "C"; colour C claim cells Aqua
                      With $oExcel.selection.interior
                         .colorindex = 8
                          .pattern = 1
                      EndWith
                 Case StringRight($dcn, 1) = "H"; colour H claim cells Red
                      With $oExcel.selection.interior
                         .colorindex = 3
                          .pattern = 1
                      EndWith
                  Case Else; colour everything else Bright Yellow
                      With $oExcel.selection.interior
                         .colorindex = 6
                          .pattern = 1
                      EndWith
              EndSelect
              ControlSend("Microsoft Excel", "", "XLDESK1", "{down}")
             ; save the worksheet
              $oExcel.activeworkbook.save
          EndIf
          If $dcn = "" Then
             $dcn = InputBox("RETRO DDR PRINTER", "Please enter the 12 digit or 12 digit + 1 alpha DCN.", $dcn, "", -1, -1, 460, 200)
              If @error = 1 Then
                  If WinExists("Locate") Then
                      WinActivate("Locate")
                      WinWaitActive("Locate")
                     AutoItSetOption("SendKeyDelay", 5)
                      Send("!{space}C")
                  EndIf
                  MyExit (1)
              EndIf
          EndIf
          $test1 = StringLen($dcn)
          Select
             Case ($test1 = 12 And StringIsDigit($dcn) = 1) or ($test1 = 13 And StringIsAlpha(StringRight($dcn, 1)) = 1 And _
                     (StringRight($dcn, 1) = "X" Or StringRight($dcn, 1) = "T"))
                  $pass = 1
              Case StringRight($dcn, 1) = "C"
                  WinActivate($iwpm)
                  WinWaitActive($iwpm)
                 Send("{altdown}ea{altup}"); clear the window of all data
                  WinActivate($b)
                  WinWaitActive($b)
                 _cs ($b, "{F3 3}{pause 3}FLDR " & StringTrimRight($dcn, 1) & "{numpadenter}"); enter dcn into B emulatr
                  Sleep(250)
                  Do
                      Sleep(10)
                      getscreen2 ($s_clip, $b)
                 Until StringInStr($s_clip, "Folder Contents") > 0; a wait until the proper screen shows.
                 _cs ($b, "3{numpadenter}"); display in IWPM window
                  Do
                      Sleep(10)
                      WinActivate($iwpm)
                      WinWaitActive($iwpm)
                 Until PixelChecksum(50, 50, 250, 175, 2) <> 3105508038 And _
                         StringInStr(ControlGetText($iwpm, "", "ComboBox1"), "DISPLAY command is complete.") > 0; a wait for claim to display
                  Send("{F8}"); print everything
                 Sleep(5000); necessary sleep, otherwise computer gets bogged down by a poorly written graphics display program (IWPM)
                 Send("{altdown}ea{altup}"); clear the window of all data
                  Do
                      Sleep(10)
                      WinActivate($iwpm)
                      WinWaitActive($iwpm)
                 Until PixelChecksum(50, 50, 250, 175, 2) = 3105508038; wait for pure white in the bounding box.
                  $counter = $counter + 1
                 ConsoleWrite($counter & ": " & @HOUR & ":" & @MIN & ":" & @SEC & " - DCN: " & $dcn & @LF)
                  $previousDCN = $dcn
                  $dcn = ""
                  $pass = 0
              Case StringRight($dcn, 1) = "H"
                ; do nothing, we just want to increment the line Excel is on.
              Case $dcn = $previousDCN
                 MsgBox(48, "ERROR", "Please input a 12 digit DCN that does not match prior DCN.")
                  $dcn = ""
              Case Else
                 MsgBox(48, "ERROR", "Please input a 12 digit or 12 digit + alpha DCN.")
                  $dcn = ""
          EndSelect
      Until $pass = 1 And $dcn <> $previousDCN
      $previousDCN = $dcn
     ; Trim the DCN down to a 10 digit "Mobius" number.
      Select
          Case $test1 = 12 And StringIsDigit($dcn)
             ; This is the formula that bred the entire program.
             $mobius = StringTrimRight(StringLeft("0" & StringTrimLeft($dcn, 1), 4) & StringRight($dcn, 7), 1)
          Case $test1 = 13
             $mobius = "0" & StringTrimLeft(StringLeft($dcn, 4), 1) & StringTrimRight(StringRight($dcn, 8), 2)
      EndSelect
      Select
          Case WinExists($ddr)
             ; Activate Document Direct
              WinActivate($ddr)
              WinSetState($ddr, "", @SW_RESTORE)
              If WinWaitActive($ddr, "", 30) Then
                 ; Need window "Document Explorer" active.
                 ; 99.9% of the time, it is window #1
                ; re-activating window 1 if only one window active won't hurt anything
                  $pxlChkSum = PixelChecksum(10, 950, 350, 1000, 2)
                  Send("{ALTDOWN}W1{altup}")
                  Sleep(750)
                 ; Activate the search menu
                  AutoItSetOption("SendKeyDelay", 300)
                  Send("{altdown}FL{ALTUP}")
                  WinWaitActive("Locate")
                  Send("{altdown}M{ALTUP}")
                  AutoItSetOption("SendKeyDelay", 10)
                  Sleep(250)
                ; Type the Mobius number into the Proper Locate field on DDR
                  WinActivate("Locate")
                  Send("{backspace}", 0)
                  Send($mobius, 1)
                  WinActivate("Locate")
                  Send("!O")
                 ; Printing question
                  $ans = $no
                 For $x = 1 To 512; waits about 2 minutes, not including pixelcheck time.
                     If PixelChecksum(10, 950, 350, 1000, 2) <> $pxlChkSum Then
                          $ans = $yes
                          ExitLoop
                      EndIf
                      Sleep(250)
                  Next
                  If $ans = $no Then
                     $temp = MsgBox(36, "UB-92: " & $dcn, "Is the claim a UB-92?", 20)
                      Select
                         Case $temp = $yes Or $temp = -1
                             WinActivate($ddr)
                             WinWaitActive($ddr)
                             Send("{altdown}V2{altup}")
                             Send("{backspace}")
                             $ans = $yes
                      EndSelect
                  EndIf
                  Select
                     Case $ans = $yes; do print functions
                          Sleep(1000)
                         WinActivate($ddr)
                         Send("{altdown}FP{altup}")
                         WinActivate("Print")
                         WinWaitActive("Print")
                         ControlClick("Print", "Cu&rrent Page", "Button3", $primary)
                         ControlClick("Print", "Cu&rrent Page", "Button9", $primary)
                         ControlClick("Print", "Cu&rrent Page", "Button12", $primary)
                         WinWaitClose("Print", "Include A&nnotations")
                      Case $ans = $no
                         ControlSend("Microsoft Excel", "", "XLDESK1", "{up}")
                         $oExcel.selection.interior.colorindex = -4142
                         $oExcel.activeworkbook.save
                         $previousDCN = ""
                         If MsgBox(0x24, "Question", "Continue the program?") = 7 Then MyExit ()
                  EndSelect
                  Sleep(2500)
                  If WinExists("Print", "Printing") Then
                     WinWaitClose("Print", "Printing")
                      Sleep(1500)
                  EndIf
                  WinActivate($ddr)
                  Send("^{F4}")
              Else
                 MsgBox(0, "Error", "Unable to display in Document Direct.  Please use OINQ", 30)
              EndIf
          Case Not WinExists($ddr)
             MsgBox(0x10, "Error!", "Unable to continue without Document Direct running!!!!")
              MyExit ()
      EndSelect
      $counter = $counter + 1
     ConsoleWrite($counter & ": " & @HOUR & ":" & @MIN & ":" & @SEC & " - DCN: " & $dcn & @LF)
  WEnd
  #endregion
  #region Function List
  Func TogglePause()
      $Paused = Not $Paused
      While $Paused
          Sleep(100)
          ToolTip('Script is "Paused"', 0, 0)
      WEnd
      ToolTip("")
  EndFunc  ;==>TogglePause
  #endregion

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...