Jump to content

Help or Suggestions - External .txt and Variables


Recommended Posts

I am looking for a little help with what I am trying to do.  I have written a little application using snippets of applications I have found and worked them to do what I need them to do but I am trying to simplify and make the application streamlined and have all the "scripts and settings" in an external file.  That way I don't have to change the AutoIT script each time I think of something new or have a new item / deployment each time.

The main issues I have are with the combobox's as each item has to be checked and then a script is pasted into the web ticketing / inventory system (Which I have issues with hence the mouse moves due to frames).

I am not sure how to change the following types of checks to have each written script be able to be checked in the .txt file.  For instance, Laptop I can put in the .text time and have it populate the drop down but how to I have it auto populate below and have the corresponding written script also match up?

The $var matches to the drop down for Pulled / Received and the $ck_loadout checks "Laptop" or the other drop down variables and if it matches makes $script = all the rest of the stuff.

If $ck_loadout = ("Laptop") Then $script = ($var & " the following laptop with the following barcode and serial number information, ready for imaging and deployment.")

Below is the the entire script.txt of which I reference in lines 2, 4, and 6.  I am a little confused by .ini so if someone has some recommendations on organization and implementations that would work better, that would be great.

State:
Pulled|Received
Items:
Laptop|Laptop with Dock|Desktop|Desktop with 17in Monitor KB/Mouse|Desktop with 19in Monitor KB/Mouse|Printer
Assignments:
Yellow Cluster|Purple Cluster|Red Cluster

And below is the entire application in case someone else might like to work something similar or it is helpful in troubleshooting.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>
#include <GUIComboBox.au3>
#include <IE.au3>

;My declired variables for the entire program

    Local $scriptfile = "script.txt"
    Local $state = FileReadLine($scriptfile, 2)
    Local $items = FileReadLine($scriptfile, 4)
    Local $assignment = FileReadLine($scriptfile, 6)
    Const $navOpenInNewTab = 0x0800
    Const $Tab1 = "http://eduphoria.ccisd.net/STSS"
    Const $Tab2 = "http://eduphoria.ccisd.net/facman"
    Const $uname="heyitsmyusernamehidden"  
    Const $pwd="heyitsmypassword#"  

; -- Created with ISN Form Studio 2 for ISN AutoIt Studio -- ;

    $warehouse = GUICreate("Warehouse",218,452,(@DesktopWidth -260), ((@DesktopHeight / 2) - (@DesktopHeight / 2.1)))
    GUICtrlCreateGroup("Type of Items",8,0,200,148,-1,-1)
    GUICtrlSetBkColor(-1,"0xF0F0F0")
    GUICtrlCreateGroup("Assign and Print",8,160,200,96,-1,-1)
    GUICtrlSetBkColor(-1,"0xF0F0F0")
    GUICtrlCreateGroup("Inventory",8,260,200,91,-1,-1)
    GUICtrlSetBkColor(-1,"0xF0F0F0")
    $buttonclose = GUICtrlCreateButton("Close",9,410,200,30,-1,-1)
    $deliverorpull = GUICtrlCreateCombo("",20,30,179,21,-1,-1)
    GUICtrlSetData(-1,$state)
    $itemstypes = GUICtrlCreateCombo("",19,70,179,21,-1,-1)
    GUICtrlSetData(-1,$items)
    $buttonprocessitems = GUICtrlCreateButton("Process Selected Request",19,100,179,30,-1,-1)
    $assignto = GUICtrlCreateCombo("",20,180,176,21,-1,-1)
    GUICtrlSetData(-1,$assignment)
    $buttonassignto = GUICtrlCreateButton("Assign",20,210,178,30,-1,-1)
    $inputbarcodesearch = GUICtrlCreateInput("Barcode",20,280,174,20,-1,512)
    $buttonsearch = GUICtrlCreateButton("Search",20,310,175,30,-1,-1)
    $buttonieopen = GUICtrlCreateButton("Open IE",9,360,200,30,-1,-1)
    GuiCtrlSetState($inputbarcodesearch, $GUI_FOCUS)
    GuiCtrlSetState($buttonsearch, $GUI_DEFBUTTON)
    GUISetState(@SW_SHOW,$warehouse)
    WinSetOnTop($warehouse,"",1)

;As long as the application is open it is true, aka all the time.

While 1
    
    ;I don't remember what I wrote this for?  Look in older version notes to see if you can find it.
    
    If Not ProcessExists("iexplorer.exe") Then
        If Not ControlCommand($warehouse, "", $buttonieopen, "IsEnabled") Then GUICtrlSetState($buttonieopen, $GUI_ENABLE)
    Else
        If ControlCommand($warehouse, "", $buttonieopen, "IsEnabled") Then GUICtrlSetState($buttonieopen, $GUI_DISABLE)
    EndIf
    
    ;The whole application function for each button and such.
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $buttonclose
            ExitLoop
        Case $buttonprocessitems
            On_Process()
        Case $assignto
            On_Assign()
        Case $buttonsearch
            Search_Edu()
        Case $buttonieopen
            OpenIE()
    EndSwitch
WEnd

;Process the ticket via Pulled or Received and have it paste the commonly used scripts, needs to be edited for the .txt file and somehow add qty options.
Func On_Process()
    $var = GUICtrlRead($deliverorpull)
    $ck_loadout = GUICtrlRead($itemstypes)
    If $ck_loadout = ("Laptop") Then $script = ($var & " the following laptop with the following barcode and serial number information, ready for imaging and deployment.")
    If $ck_loadout = ("Laptop with Dock") Then $script = ($var & " the following laptop and dockingstation with the following barcode and serial number information, ready for imaging and deployment.")
    If $ck_loadout = ("Desktop") Then $script = ($var & " the following desktop with the following barcode and serial number information, ready for imaging and deployment.")
    If $ck_loadout = ("Desktop with 17in Monitor KB/Mouse") Then $script = ($var & " the following desktop, 17in Monitor and KB/Mouse with the following barcode and serial number information, ready for imaging and deployment.")
    If $ck_loadout = ("Desktop with 19in Monitor KB/Mouse") Then $script = ($var & " the following desktop, 19in Monitor and KB/Mouse with the following barcode and serial number information, ready for imaging and deployment.")
    If $ck_loadout = ("Printer") Then $script = ($var & " the following printer with the barcode and serial number listed below, it is ready for delivery.")
    ;If $ck_loadout = ("item 1") Then $script = ()
    ;If $ck_loadout = ("item 1") Then $script = ()
    ;If $ck_loadout = ("item 1") Then $script = ()
    ;If $ck_loadout = ("item 1") Then $script = ()
    ;If $ck_loadout = ("item 1") Then $script = ()
    ;If $ck_loadout = ("item 1") Then $script = ()
    ;If $ck_loadout = ("item 1") Then $script = ()
    AutoItSetOption("MouseCoordMode", 1)
    Opt("WinTitleMatchMode", 2)
    WinActivate("Google Chrome", "")
    WinWaitActive("Google Chrome", "", 10)
    Send("^1")
    WinActivate("Google Chrome", "")
    WinWaitActive("Google Chrome", "", 10)
    MouseClick("left", 1648, 103, 1)
    MouseClick("left", 1653, 257, 1)
    ClipPut($script)
    Send("^v" & "{ENTER}")
    Send("{SHIFTDOWN}b{SHIFTUP}arcode{SHIFTDOWN}:{SHIFTUP}{SPACE}")
    $barcode = InputBox("Barcode", "Scan the barcode:", "Barcode")
    Send($barcode & "{ENTER}")
    Send("{SHIFTDOWN}s{SHIFTUP}erial{SHIFTDOWN}:{SHIFTUP}")
    $serial = InputBox("Serial Number", "Scan the serial:", "Serial Number")
    Send($serial & "{ENTER}")
    EndFunc   ;==>On_Process

;Need to change this assign button now that I am making the .txt file a config file.

Func On_Assign()
    $ck_assignment = GUICtrlRead($assignto)
    If $ck_assignment = ("name") Then $name = ("name formatted")
    If $ck_assignment = ("name") Then $name = ("name formatted")
    If $ck_assignment = ("name") Then $name = ("name formatted")
    If $ck_assignment = ("name") Then $name = ("name formatted")
    If $ck_assignment = ("name") Then $name = ("name formatted")
    If $ck_assignment = ("name") Then $name = ("name formatted")
    If $ck_assignment = ("name") Then $name = ("name formatted")
    ;If $ck_assignment = ("name 1") Then $name = ()
    ;If $ck_assignment = ("name 1") Then $name = ()
    ;If $ck_assignment = ("name 1") Then $name = ()
    ;If $ck_assignment = ("name 1") Then $name = ()
    ;If $ck_assignment = ("name 1") Then $name = ()
    ;If $ck_assignment = ("name 1") Then $name = ()
    AutoItSetOption("MouseCoordMode", 1)
    Opt("WinTitleMatchMode", 2)
    WinActivate("Google Chrome", "")
    WinWaitActive("Google Chrome", "", 10)
    Send("^1")
    WinActivate("Google Chrome", "")
    WinWaitActive("Google Chrome", "", 10)
    Dim $Color = 0x44C12D ; Color for the assign button
    Dim $ColorVariation = 2 ; little varriation
    $Coords = PixelSearch(1819, 89, 1995, 112, $Color, $ColorVariation, 1) ; Search the whole screen
    MouseClick("left", $Coords[0], $Coords[1], 1, 0) ; Click on the position found
    Sleep(2000)
    MouseClick("left", $Coords[0], 149, 1)
    WinWaitActive("Google Chrome", "", 10)
    Send($name & "{TAB}")
    WinWaitActive("Google Chrome", "", 10)
    MouseClick("left", $Coords[0], 170, 1)
    ;MouseClick("left", ($Coords[0]-10), 452, 1) ;commented out to make sure it doesn't submit
    EndFunc   ;==>On_Assign

;Searches the eduphoria inventory from the application

Func Search_Edu()
    $searchbox = GUICtrlRead($inputbarcodesearch)
    AutoItSetOption("MouseCoordMode", 1)
    Opt("WinTitleMatchMode", 2)
    WinActivate("Google Chrome", "")
    Send("^2")
    MouseClick("left", 1298, 148, 1)
    WinWaitActive("Google Chrome", "", 10)
    MouseClick("left", 2216, 107, 1)
    Send($searchbox)
    MouseClick("left", 2381, 105, 1)
    WinWaitActive("Google Chrome", "", 10)
EndFunc

;Button function for opening IE

Func OpenIE()
    $oIE = _IECreate($Tab1)
    $hIE = _IEPropertyGet($oIE, "hwnd") 
    WinSetState($hIE, "", @SW_MAXIMIZE) 
    $oForm = _IEFormGetObjByName ($oIE, "Form1")  
    $oQuery1 = _IEFormElementGetObjByName ($oForm, "TextBox1")  
    $oQuery2 = _IEFormElementGetObjByName ($oForm, "TextBox2")  
    _IEFormElementSetValue ($oQuery1,$uname)  
    _IEFormElementSetValue ($oQuery2,$pwd)  
    $oButton=_IEGetObjById($oIE,"Button1")  
    _IEAction ($oButton, "click")  
    _IELoadWait($oIE,600)
EndFunc

Thanks for any input or suggestions or links, sometimes I feel like my eyes dry out trying to learn / build programs.

Edited by goldstar19
Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("INFO", 264, 145, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 0, 249, 137)
$Label1 = GUICtrlCreateLabel("My Name:", 24, 24, 52, 17)
$Label2 = GUICtrlCreateLabel("My Paypal ID:", 24, 48, 73, 17)
$Label3 = GUICtrlCreateLabel("My Paypal Password:", 24, 72, 105, 17)
$Input1 = GUICtrlCreateInput("", 80, 24, 169, 21)
$Input2 = GUICtrlCreateInput("", 104, 48, 145, 21)
$Input3 = GUICtrlCreateInput("", 136, 72, 113, 21)
$Button1 = GUICtrlCreateButton("Save to .ini", 24, 104, 225, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;READ CONFIG
GUICtrlSetData($Input1,IniRead("MyConfig.cfg","General", "MyName", "ERROR WHEN READ THE INI FILE"))
GUICtrlSetData($Input2,IniRead("MyConfig.cfg","General", "MyPaypalID", "ERROR WHEN READ THE INI FILE"))
GUICtrlSetData($Input3,IniRead("MyConfig.cfg","General", "MyPaypalPassword", "ERROR WHEN READ THE INI FILE"))

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ;SAVE CONFIG
            IniWrite("MyConfig.cfg","General", "MyName", GUICtrlRead($Input1))
            IniWrite("MyConfig.cfg","General", "MyPaypalID", GUICtrlRead($Input2))
            IniWrite("MyConfig.cfg","General", "MyPaypalPassword", GUICtrlRead($Input3))
            ;RE-READCONFIG
            GUICtrlSetData($Input1,IniRead("MyConfig.cfg","General", "MyName", "ERROR WHEN READ THE INI FILE"))
            GUICtrlSetData($Input2,IniRead("MyConfig.cfg","General", "MyPaypalID", "ERROR WHEN READ THE INI FILE"))
            GUICtrlSetData($Input3,IniRead("MyConfig.cfg","General", "MyPaypalPassword", "ERROR WHEN READ THE INI FILE"))

    EndSwitch
WEnd

MyConfig.zip

Edited by GordonFreeman
Link to comment
Share on other sites

Great, thank you, this has been most helpful as I have changed the .txt into a .ini and changed it to read after the GUI elements are declared.

This is my current .ini using your example to get it working properly but is there a better way to store, lets use Items as an example, the data so instead of using the "|" to make that data get its own line in the combobox? 

[General]
Assignments=Yellow Cluster|Purple Cluster|Red Cluster
State=Pulled|Received
Items=Laptop|Laptop with Dock|Desktop|Desktop with 17in Monitor KB/Mouse|Desktop with 19in Monitor KB/Mouse|Printer

The reason I ask is that I am also trying to figure a way to get my "script of text" also externalized into that .ini file.  I have all the "If's" going down the line until it finds the correct "Item" and uses the corresponding "script of text" to paste into the ticketing system.

If $ck_loadout = ("Laptop") Then $script = ($var & " the following laptop with the following barcode and serial number information, ready for imaging and deployment.")

Is there a way to make "Laptop" not hard coded and then have the then pulled from the .ini?

If $ck_loadout = $thethingIselected Then $script = ($var & $thetextforthethingiselected)

Sorry, I struggle with this, I have the basic idea of how to make it work but I just lack that little understanding to get it to work properly.

Link to comment
Share on other sites

Something like? (I used the text method but note who you can put the extension you want in ini Method or txt Method, in case of this example ".cfg")

#include <File.au3>

$sCfgFile = "MyConfig.cfg"

If FileExists($sCfgFile) = 0 Then
    FileWrite($sCfgFile,"")
EndIf

$iLines = _FileCountLines($sCfgFile)

Local $aInfo[2][$iLines]

For $i = 1 to $iLines

$aTemp = StringSplit(FileReadLine($sCfgFile,$i), "|")

$aInfo[0][$i-1] = $aTemp[1]
$aInfo[1][$i-1] = $aTemp[2]

Next

_ArrayDisplay($aInfo)

MyConfig.zip

Edited by GordonFreeman
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...