Jump to content

trying to get a variable to work in an input field


timmo
 Share

Recommended Posts

hey guys, im trying to get a variable to work in an input field but it doesnt seem to wanna work. is this just me needing a line somewhere or will it just not work.

in a bit more detail here is what i want

i have a script that im creating as my first piece of work with autoit and you select the campus from the drop-down list, then enter the room number. and then you enter the first computer and the last computer number. then once all that is done you type a command into the next field. this command can be any standard dos command like the "copy" or "ping" commands, the user then adds the "$PCNUM" line to the command. for example "ping $PCNUM -l 65500" will ping the computers in the campus in the room specified and from the first number entered till the last one entered.

i have the looping part working. its the using the $PCNUM in a text field that i cant get to work. it just tries to "ping $PCNUM" instead of the computer name.

any ideas? thanks in advance.

Quoted from Micro$ofts development team:Gentlemen, I say rather than fix the 'bugs', we change the documentation and call them 'features'.

Link to comment
Share on other sites

this is the script (im only a newbie and this is my first autoit script so dont laugh)

#include <GuiConstants.au3>

; Create the GUI

GuiCreate("Eastern Launceston Cluster Batch Command Excuter", 550, 300,-1, -1)

GuiCtrlCreateLabel("Select School", 5, 45)

$School = GuiCtrlCreateCombo("", 85, 40, 180, 21)

GuiCtrlSetData($School, "East Launceston Primary|Newstead Heights Primary|Norwood Primary|Queechy High|Northern Support|Punchbowl Primary|Ravenswood Heights Primary|St Leonards Primary|Waverly Primary","East Launceston Primary")

GuiCtrlCreateLabel("Room Number/Name", 280, 45)

$RoomNum = GuiCtrlCreateInput("", 390, 40, 130, 20, $ES_UPPERCASE)

GuiCtrlCreateLabel("First Computer Number", 70, 75)

$PcStart = GuiCtrlCreateInput("1", 100, 90, 40, 20)

GuiCtrlCreateUpDown(-1)

GUICtrlCreateLabel("Last Computer Number", 70, 115)

$PcEnd = GuiCtrlCreateInput("25", 100, 130, 40, 20)

GuiCtrlCreateUpDown(-1)

$CommandLoc = GuiCtrlCreateInput("Use $PCNUM for Computer Name", 40, 180, 260, 20)

$ButtonRunLoc = GuiCtrlCreateButton("Run Command", 300, 180, 150, 20)

$CommandRem = GuiCtrlCreateInput("", 40, 205, 260, 20)

$ButtonRunRem = GuiCtrlCreateButton("Run Remote Command", 300, 205, 150, 20)

$ButtonExit = GuiCtrlCreateButton("Exit", 50, 250, 150, 20)

;When a Button is pressed run the commands

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $ButtonRunLoc

$PcStart2 = GUICtrlRead ($PcStart)

$PcEnd2 = GUICtrlRead ($PcEnd)

$RoomNum2 = GUICtrlRead ($RoomNum)

$School2 = GUICtrlRead ($School)

;$CommandLoc2 = GUICtrlRead ($CommandLoc)

if $RoomNum2 = "" Then

MsgBox (16, "Error", "Please enter a Room Number/Name.", 3)

MsgBox (16, "Error", "Quiting Now! ", 3)

ExitLoop

EndIf

Select

Case $School2 = "East Launceston Primary"

$SchoolPFX = "ELA-"

Case $School2 = "Newstead Heights Primary"

$SchoolPFX = "NEW-"

Case $School2 = "Norwood Primary"

$SchoolPFX = "NOR-"

Case $School2 = "Queechy High"

$SchoolPFX = "QUC-"

Case $School2 = "Northern Support"

$SchoolPFX = "NSS-"

Case $School2 = "Punchbowl Primary"

$SchoolPFX = "PUN-"

Case $School2 = "Ravenswood Heights Primary"

$SchoolPFX = "RAV-"

Case $School2 = "St Leonards Primary"

$SchoolPFX = "STL-"

Case $School2 = "Waverly Primary"

$SchoolPFX = "WAV-"

EndSelect

While $PcStart2 <= 9 and $PcStart2 <= $PcEnd2

$PCNUM=$SchoolPFX&$RoomNum2&"-0"&$PcStart2

$CommandLoc2 = GUICtrlRead ($CommandLoc)

Msgbox(64, "", "Running " & $CommandLoc2, 1)

RunWait(@ComSpec & " /c " & $CommandLoc2)

$PcStart2 = $PcStart2 + 1

WEnd

While $PcStart2 <= $PcEnd2

$PCNUM=$SchoolPFX&$RoomNum2&"-"&$PcStart2

$CommandLoc2 = GUICtrlRead ($CommandLoc)

Msgbox(64, "", "Running " & $CommandLoc2, 1)

RunWait(@ComSpec & " /c " & $CommandLoc2 & " " & $PCNUM)

$PcStart2 = $PcStart2 + 1

WEnd

Case $msg = $ButtonRunRem

ExitLoop

Case $msg = $ButtonExit

ExitLoop

EndSelect

WEnd

Exit

Quoted from Micro$ofts development team:Gentlemen, I say rather than fix the 'bugs', we change the documentation and call them 'features'.

Link to comment
Share on other sites

#include <GuiConstants.au3>

; Create the GUI
GUICreate("Eastern Launceston Cluster Batch Command Excuter", 550, 300, -1, -1)
GUICtrlCreateLabel("Select School", 5, 45)
$School = GUICtrlCreateCombo("", 85, 40, 180, 21)
GUICtrlSetData($School, "East Launceston Primary|Newstead Heights Primary|Norwood Primary|Queechy High|Northern Support|Punchbowl Primary|Ravenswood Heights Primary|St Leonards Primary|Waverly Primary", "East Launceston Primary")

GUICtrlCreateLabel("Room Number/Name", 280, 45)
$RoomNum = GUICtrlCreateInput("", 390, 40, 130, 20, $ES_UPPERCASE)

GUICtrlCreateLabel("First Computer Number", 70, 75)
$PcStart = GUICtrlCreateInput("1", 100, 90, 40, 20)
GUICtrlCreateUpdown(-1)

GUICtrlCreateLabel("Last Computer Number", 70, 115)
$PcEnd = GUICtrlCreateInput("25", 100, 130, 40, 20)
GUICtrlCreateUpdown(-1)

$CommandLoc = GUICtrlCreateInput("", 40, 180, 260, 20)
$ButtonRunLoc = GUICtrlCreateButton("Run Command", 300, 180, 150, 20)

$CommandRem = GUICtrlCreateInput("", 40, 205, 260, 20)
$ButtonRunRem = GUICtrlCreateButton("Run Remote Command", 300, 205, 150, 20)

$ButtonExit = GUICtrlCreateButton("Exit", 50, 250, 150, 20)


;When a Button is pressed run the commands
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $ButtonRunLoc
            ; Verify conditions have been met to run the command. Conditions are a room number and a command to run. 
            If GUICtrlRead($RoomNum) = "" Then
                MsgBox(16, "Error", "Please enter a Room Number/Name.", 3)
            ElseIf GUICtrlRead($CommandLoc) = "" Then
                msgbox(16,"","Please enter a command to run and try again. eg: ping", 3)
            Else
                ExecuteCommand()
            EndIf
        Case $msg = $ButtonRunRem
            ExitLoop

        Case $msg = $ButtonExit
            ExitLoop
    EndSelect
WEnd


Func ExecuteCommand()
    Local $PcStart2 = GUICtrlRead($PcStart)
    Local $PcEnd2 = GUICtrlRead($PcEnd)
    Local $RoomNum2 = GUICtrlRead($RoomNum)
    Local $School2 = GUICtrlRead($School)
    Local $CommandLoc2 = GUICtrlRead ($CommandLoc)
    Local $SchoolPFX

    Select
        Case $School2 = "East Launceston Primary"
            $SchoolPFX = "ELA-"

        Case $School2 = "Newstead Heights Primary"
            $SchoolPFX = "NEW-"

        Case $School2 = "Norwood Primary"
            $SchoolPFX = "NOR-"

        Case $School2 = "Queechy High"
            $SchoolPFX = "QUC-"

        Case $School2 = "Northern Support"
            $SchoolPFX = "NSS-"

        Case $School2 = "Punchbowl Primary"
            $SchoolPFX = "PUN-"

        Case $School2 = "Ravenswood Heights Primary"
            $SchoolPFX = "RAV-"

        Case $School2 = "St Leonards Primary"
            $SchoolPFX = "STL-"

        Case $School2 = "Waverly Primary"
            $SchoolPFX = "WAV-"
    EndSelect
    
    While $PcStart2 <= 9 And $PcStart2 <= $PcEnd2
        $PCNUM = $SchoolPFX & $RoomNum2 & "-0" & $PcStart2
        MsgBox(64, "", "Running " & $CommandLoc2 & " " & $PCNUM, 1)
        RunWait(@ComSpec & " /c " & $CommandLoc2 & " " & $PCNUM)
        $PcStart2 = $PcStart2 + 1
    WEnd

    While $PcStart2 <= $PcEnd2
        $PCNUM = $SchoolPFX & $RoomNum2 & "-" & $PcStart2
        MsgBox(64, "", "Running " & $CommandLoc2 & " " & $PCNUM, 1)
        RunWait(@ComSpec & " /c " & $CommandLoc2 & " " & $PCNUM)
        $PcStart2 = $PcStart2 + 1
    WEnd

EndFunc

p.s. use code, autoit, or codebox to paste in your code. read the BB code help HERE :-)

Link to comment
Share on other sites

sorry about that.

but i think u missunderstood. i want the user to type in the variable $PCNUM into where they want it in the input box "CommandLoc"

While $PcStart2 <= 9 And $PcStart2 <= $PcEnd2
        $PCNUM = $SchoolPFX & $RoomNum2 & "-0" & $PcStart2
        MsgBox(64, "", "Running " & $CommandLoc2, 1)
        RunWait(@ComSpec & " /c " & $CommandLoc2)
        $PcStart2 = $PcStart2 + 1
    WEnd

    While $PcStart2 <= $PcEnd2
        $PCNUM = $SchoolPFX & $RoomNum2 & "-" & $PcStart2
        MsgBox(64, "", "Running " & $CommandLoc2)
        RunWait(@ComSpec & " /c " & $CommandLoc2)
        $PcStart2 = $PcStart2 + 1
    WEndoÝ÷ Úz-jëh×6    While $PcStart2 <= 9 And $PcStart2 <= $PcEnd2
        $PCNUM = $SchoolPFX & $RoomNum2 & "-0" & $PcStart2
        MsgBox(64, "", "Running " & $CommandLoc2 & " " & $PCNUM, 1)
        RunWait(@ComSpec & " /c " & $CommandLoc2 & " " & $PCNUM)
        $PcStart2 = $PcStart2 + 1
    WEnd

    While $PcStart2 <= $PcEnd2
        $PCNUM = $SchoolPFX & $RoomNum2 & "-" & $PcStart2
        MsgBox(64, "", "Running " & $CommandLoc2 & " " & $PCNUM, 1)
        RunWait(@ComSpec & " /c " & $CommandLoc2 & " " & $PCNUM)
        $PcStart2 = $PcStart2 + 1
    WEnd

this is so different commands can be used.

for example: someone might just want to ping the computers to see if they are switched on my entering the command "ping $PCNUM"

and then copy files with this command "copy \\RemotePC\share\file.lnk \\$PCNUM\C$\"

the commands are run locally and the only thing that changes is $PCNUM

Quoted from Micro$ofts development team:Gentlemen, I say rather than fix the 'bugs', we change the documentation and call them 'features'.

Link to comment
Share on other sites

I see, sorry about that. I believe I understand now. Try this:

#include <GuiConstants.au3>

; Create the GUI
GUICreate("Eastern Launceston Cluster Batch Command Excuter", 550, 300, -1, -1)
GUICtrlCreateLabel("Select School", 5, 45)
$School = GUICtrlCreateCombo("", 85, 40, 180, 21)
GUICtrlSetData($School, "East Launceston Primary|Newstead Heights Primary|Norwood Primary|Queechy High|Northern Support|Punchbowl Primary|Ravenswood Heights Primary|St Leonards Primary|Waverly Primary", "East Launceston Primary")

GUICtrlCreateLabel("Room Number/Name", 280, 45)
$RoomNum = GUICtrlCreateInput("", 390, 40, 130, 20, $ES_UPPERCASE)

GUICtrlCreateLabel("First Computer Number", 70, 75)
$PcStart = GUICtrlCreateInput("1", 100, 90, 40, 20)
GUICtrlCreateUpdown(-1)

GUICtrlCreateLabel("Last Computer Number", 70, 115)
$PcEnd = GUICtrlCreateInput("25", 100, 130, 40, 20)
GUICtrlCreateUpdown(-1)

$CommandLoc = GUICtrlCreateInput("", 40, 180, 260, 20)
$ButtonRunLoc = GUICtrlCreateButton("Run Command", 300, 180, 150, 20)

$CommandRem = GUICtrlCreateInput("", 40, 205, 260, 20)
$ButtonRunRem = GUICtrlCreateButton("Run Remote Command", 300, 205, 150, 20)

$ButtonExit = GUICtrlCreateButton("Exit", 50, 250, 150, 20)


;When a Button is pressed run the commands
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $ButtonRunLoc
            ; Verify conditions have been met to run the command. Conditions are a room number and a command to run.
            If GUICtrlRead($RoomNum) = "" Then
                MsgBox(16, "Error", "Please enter a Room Number/Name.", 3)
            ElseIf GUICtrlRead($CommandLoc) = "" Then
                msgbox(16,"","Please enter a command to run and try again. eg: ping", 3)
            ElseIf StringInStr(GUICtrlRead($CommandLoc),"$PCNUM") = 0 Then
                msgbox(16,"","Please enter $PCNUM variable into commandline")
            Else
                ExecuteCommand()
            EndIf
        Case $msg = $ButtonRunRem
            ExitLoop

        Case $msg = $ButtonExit
            ExitLoop
    EndSelect
WEnd


Func ExecuteCommand()
    Local $PcStart2 = GUICtrlRead($PcStart)
    Local $PcEnd2 = GUICtrlRead($PcEnd)
    Local $RoomNum2 = GUICtrlRead($RoomNum)
    Local $School2 = GUICtrlRead($School)
    Local $CommandLoc2 = GUICtrlRead ($CommandLoc)
    Local $SchoolPFX

    Select
        Case $School2 = "East Launceston Primary"
            $SchoolPFX = "ELA-"

        Case $School2 = "Newstead Heights Primary"
            $SchoolPFX = "NEW-"

        Case $School2 = "Norwood Primary"
            $SchoolPFX = "NOR-"

        Case $School2 = "Queechy High"
            $SchoolPFX = "QUC-"

        Case $School2 = "Northern Support"
            $SchoolPFX = "NSS-"

        Case $School2 = "Punchbowl Primary"
            $SchoolPFX = "PUN-"

        Case $School2 = "Ravenswood Heights Primary"
            $SchoolPFX = "RAV-"

        Case $School2 = "St Leonards Primary"
            $SchoolPFX = "STL-"

        Case $School2 = "Waverly Primary"
            $SchoolPFX = "WAV-"
    EndSelect
   
    While $PcStart2 <= 9 And $PcStart2 <= $PcEnd2
        $PCNUM = $SchoolPFX & $RoomNum2 & "-0" & $PcStart2
    $CommandLoc2 = StringReplace(GuiCtrlRead($CommandLoc),"$PCNUM",$PCNUM)
        MsgBox(64, "", "Running " & $CommandLoc2, 1)
        RunWait(@ComSpec & " /c " & $CommandLoc2 & " " & $PCNUM)
        $PcStart2 = $PcStart2 + 1
    WEnd

    While $PcStart2 <= $PcEnd2
        $PCNUM = $SchoolPFX & $RoomNum2 & "-" & $PcStart2
    $CommandLoc2 = StringReplace(GuiCtrlRead($CommandLoc),"$PCNUM",$PCNUM)
        MsgBox(64, "", "Running " & $CommandLoc2, 1)
        RunWait(@ComSpec & " /c " & $CommandLoc2 & " " & $PCNUM)
        $PcStart2 = $PcStart2 + 1
    WEnd

EndFunc
Link to comment
Share on other sites

thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you . thank you very much it works very well now

Quoted from Micro$ofts development team:Gentlemen, I say rather than fix the 'bugs', we change the documentation and call them 'features'.

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