Sign in to follow this  
Followers 0
grimmlock

Help with adding array

3 posts in this topic

#1 ·  Posted (edited)

I can get most of this to work, however I am at the last few steps of finalizing my code and need some help. I have a mysql database with tons of data that is refreshed every night. The things I need help with is to get the data from mysql to the list box, seperating each name to a new line. Then what I am trying to accomplish is, I want to be able to highlight the computer name and have the buttons perform their action.

Example: If I choose branch 1 from the drop down list, and it pulls all the computers (8 of them) from mysql and displays them in the list box one pc per line. Then if I click Ping it scrolls through the list and returns the output of the ping into the read-only display boxes. Then if I stop the ping and select computers 2, 4, and 7 from the list box, I want to be able to get the IP addresses of those PC's (using mysql) and send the IP

to a seperate program. Lastly I would like to be able to select computers 1, 3, and 8 (if they are not reponding) and get thier IPs and their MAC addresses (from mysql) and send that data to the Wake On Lan Function.

Here is my code:

#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <GUIComboBox.au3>
#Include <String.au3>
#include <mysql.au3>


; Declare a flag
Global $fPing = False
Global $Input1 = False
Global $Input2 = False


GUICreate("Am I Asleep?", 315, 850)


GUISetState()

;~ IP Addresses
$List1 = FileRead("c:\dhcp2.txt") ; Branch1
$List2 = FileRead("\server.test1.local\Installers\dhcp2.txt") ; Branch2
$List3 = ("") ; Branch3
$List4 = ("") ; Branch4
$List5 = ("") ; Branch5
$List6 = ("") ; Branch6
$List7 = ("") ; Branch7
$List8 = ("") ; Branch8
$List9 = ("") ; Branch9
$List10 = ("") ;Branch10
$List11 = ("") ; Branch11
$List12 = ("") ; Branch12
$List13 = ("") ; Branch13
$List14 = ("") ; Branch14
$List15 = ("") ; Branch15
$List16 = ("") ; Branch16
$List17 = ("") ; Branch17
$List18 = FileRead("C:\SC_PC.txt") ; Branch18
$List19 = ("") Branch Servers
$List20 = ("") ; Core Servers

Local $Combo1 = GUICtrlCreateCombo("", 10, 20, 125, 10)
GUICtrlSetData(-1, "Branch1|Branch2|Branch3|Branch4|Branch5|Branch6|Branch7|Branch8|Branch9|Branch10|Branch11|Branch12|Branch13|Branch14|Branch15|Branch16|Branch17|Branch18|Branch Servers|Core Servers")

; Set Cuebanner rather than add an extra element to the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Get handle of combo edit
$tInfo = $tagCOMBOBOXINFO
_GUICtrlComboBox_GetComboBoxInfo($Combo1, $tInfo)
$hComboEdit = DllStructGetData($tInfo, "hEdit")
; Write CueBanner
$tText = _WinAPI_MultiByteToWideChar("Select one")
_SendMessage($hComboEdit, $EM_SETCUEBANNER, False, $tText, 0, "wparam", "struct*")

Local $Input1 = GUICtrlCreateList("", 150, 20, 150, 815, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
Local $Input2 = GUICtrlCreateList("", 440, 20, 150, 815, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetState(-1, $GUI_HIDE)

;~ Controls
Local $Button_1 = GUICtrlCreateButton("Ping", 10, 340, 115)
Local $Button_2 = GUICtrlCreateButton("Wake On Lan", 10, 380, 115)
Local $Button_3 = GUICtrlCreateButton("Netsupport Manager", 10, 440, 115)
Local $Button_4 = GUICtrlCreateButton("Remote Desktop", 10, 475, 115)
Local $Button_5 = GUICtrlCreateButton("VNC", 10, 510, 115)
Local $Button_6 = GUICtrlCreateButton("Start WHD", 10, 750, 115)
Local $Button_7 = GUICtrlCreateButton("Stop WHD", 10, 780, 115)
Local $Display1 = GUICtrlCreateEdit("", 10, 70, 125, 30, BitOR($ES_READONLY, $ES_CENTER)) ;, 0)
Local $Display2 = GUICtrlCreateEdit("", 10, 110, 125, 30, BitOR($ES_READONLY, $ES_CENTER)) ;, 0)


$iIndex = 0
_GUICtrlListBox_ClickItem($Input1, $iIndex)
$iCount = _GUICtrlListBox_GetCount($Input1)

; _AddHorzSep(10, 40, 290)
_AddHorzSep(10, 325, 125)
_AddHorzSep(10, 420, 125)
;~ _AddHorzSep(10, 690, 125)

; Get a timestamp
$iBegin = TimerInit()

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit


Case $Button_1
Switch GUICtrlRead($Button_1)
; What does the button tell us we are going to do?
Case "Ping"
; We need to ping
$fPing = True
; And set the button text accordingly
GUICtrlSetData($Button_1, "Stop")
; Disable the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetState($Combo1, $GUI_DISABLE)
Case Else
; Now we need to stop pinging
$fPing = False
; And again change the button text
GUICtrlSetData($Button_1, "Ping")
; Enable the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetState($Combo1, $GUI_ENABLE)
EndSwitch


Case $Combo1
Switch GUICtrlRead($Combo1)
Local $ip = mysql("PC1")
Local $mac = mysql("PC1")
Case "Branch1"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch1
GUICtrlSetData($Input1, "|" & $List1)
;~ GUICtrlSetData($Input2, "|" & $List21)
Case "Branch2"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch2
GUICtrlSetData($Input1, "|" & $List2)
;~ GUICtrlSetData($Input2, "|" & $List22)
Case "Branch3"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch3
GUICtrlSetData($Input1, "|" & $List3)
;~ GUICtrlSetData($Input2, "|" & $List23)
Case "Branch4"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch4
GUICtrlSetData($Input1, "|" & $List4)
;~ GUICtrlSetData($Input2, "|" & $List24)
Case "Branch5"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch5
GUICtrlSetData($Input1, "|" & $List5)
;~ GUICtrlSetData($Input2, "|" & $List25)
Case "Branch6"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch6
GUICtrlSetData($Input1, "|" & $List6)
;~ GUICtrlSetData($Input2, "|" & $List26)
Case "Branch7"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch7
GUICtrlSetData($Input1, "|" & $List7)
;~ GUICtrlSetData($Input2, "|" & $List27)
Case "Branch8"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch8
GUICtrlSetData($Input1, "|" & $List8)
;~ GUICtrlSetData($Input2, "|" & $List28)
Case "Branch9"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch9
GUICtrlSetData($Input1, "|" & $List9)
;~ GUICtrlSetData($Input2, "|" & $List29)
Case "Branch10|"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch10
GUICtrlSetData($Input1, "|" & $List10)
;~ GUICtrlSetData($Input2, "|" & $List30)
Case "Branch11"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch11
GUICtrlSetData($Input1, "|" & $List11)
;~ GUICtrlSetData($Input2, "|" & $List31)
Case "Branch12"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch12
GUICtrlSetData($Input1, "|" & $List12)
;~ GUICtrlSetData($Input2, "|" & $List32)
Case "Branch13"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch13
GUICtrlSetData($Input1, "|" & $List13)
;~ GUICtrlSetData($Input2, "|" & $List33)
Case "Branch14"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch14
GUICtrlSetData($Input1, "|" & $List14)
;~ GUICtrlSetData($Input2, "|" & $List34)
Case "Branch15"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch15
GUICtrlSetData($Input1, "|" & $List15)
;~ GUICtrlSetData($Input2, "|" & $List35)
Case "Branch16"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch16
GUICtrlSetData($Input1, "|" & $List16)
;~ GUICtrlSetData($Input2, "|" & $List36)
Case "Branch17"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch17
GUICtrlSetData($Input1, "|" & $List17)
;~ GUICtrlSetData($Input2, "|" & $List37)
Case "Branch18"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch18
GUICtrlSetData($Input1, "|" & $List18)
;~ GUICtrlSetData($Input2, "|" & $List38)
Case "Branch Servers"
;~ ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch Servers
GUICtrlSetData($Input1, "|" & $List19)
Case "Core Servers"
MsgBox(0, "", GuiCtrlRead($ip[1]))

EndSwitch

; Get new count <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$iCount = _GUICtrlListBox_GetCount($Input1)


Case $Button_2
WakeOnLan()


Case $Button_3
If ProcessExists("PCICTLUI.EXE") Then
Netsupport()
Else
Run("C:\Program Files (x86)\NetSupport\NetSupport Manager\PCICTLUI.EXE", "")
Netsupport()
EndIf


Case $Button_4
RDP()


Case $Button_5
VNC()


Case $Button_6
WHD_Start()


Case $Button_7
WHD_Stop()


EndSwitch

If $fPing Then
; Have we waited long enough since the last ping?
If TimerDiff($iBegin) > 1000 Then ; 1 sec delay
; Click the current item
_GUICtrlListBox_ClickItem($Input1, $iIndex)
; Read the current item
$sItem = GUICtrlRead($Input1)
$var = Ping(GUICtrlRead($Input1), 999)
If $var <> 0 Then
GUICtrlSetData($Display1, $sItem) ; & " - " & $var & " ms")
GUICtrlSetBkColor($Display1, 0x00FF00)
GUICtrlSetColor($Display1, 0x000000)
GUICtrlSetData($Display2, " " & $var & " ms")
GUICtrlSetBkColor($Display2, 0x00FF00)
GUICtrlSetColor($Display2, 0x000000)
Else
GUICtrlSetData($Display1, $sItem)
GUICtrlSetBkColor($Display1, 0)
GUICtrlSetColor($Display1, 0xFFFFFF)
GUICtrlSetData($Display2, "Request Timed Out ")
GUICtrlSetBkColor($Display2, 0)
GUICtrlSetColor($Display2, 0xFFFFFF)
EndIf
; Reset the timestamp for the next ping
$iBegin = TimerInit()
; Increase the index to select the next item
$iIndex = Mod($iIndex + 1, $iCount)
EndIf
EndIf

WEnd

Func _AddHorzSep($iX, $iY, $iW)

GUICtrlCreateLabel("", $iX, $iY, $iW, 1)
GUICtrlSetBkColor(-1, 0x000000)

EndFunc ;==>_AddHorzSep

; MySQL Function
Func sql($branch)
; establish an array with too many elements
Local $output[80]

; establish a counter starting at zero
$count = 0


; put query together
$sql = _MySQLConnect("DHCP","Yvl1234","test","192.168.26.18")
$var = _Query($sql,"SELECT * FROM Leases WHERE Branch='" & $branch & "'")

With $var


;loop through the query result
While NOT .EOF

;put data into array
$output[$count]=.Fields("IP").value


;increment the counter
$count += 1

; end of the loop
wend

; resize the array to the number of elements
ReDim $output[$count]
EndWith
; return the proper sized array
return $output
EndFunc

Func WHD_Start()
Run("cmd.exe")
Sleep(1000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd pstools{Enter}")
Sleep(1000)
Send("psexec \\192.168.26.17\cmd.exe{Enter}")
Sleep(5000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd Program Files\WebHelpDesk{Enter}")
Sleep(1000)
Send("whd_start.bat{Enter}")
EndFunc

Func WHD_Stop()
Run("cmd.exe")
Sleep(1000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd pstools{Enter}")
Sleep(1000)
Send("psexec \\192.168.26.17\ cmd.exe{Enter}")
Sleep(5000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd Program Files\WebHelpDesk{Enter}")
Sleep(1000)
Send("whd_stop.bat{Enter}")
EndFunc

Func VNC()
Run("C:\Program Files\RealVNC\VNC Viewer\vncviewer.exe")
WinWaitActive("VNC Viewer")
Send(GUICtrlRead($Input1))
Sleep(1000)
Send("{ENTER}")
EndFunc

Func RDP()
Run("mstsc.exe /console")
WinWaitActive("Remote Desktop Connection")
Send(GUICtrlRead($Input1))
Sleep(1000)
Send("{ENTER}")
EndFunc

Func Netsupport()
Local $Input3 = GUICtrlRead($Input1)
Local $Input4 = StringTrimRight(GUICtrlRead($Input1), 12)
WinActivate("NetSupport : ")
Send("!C{Down}")
Send("Q")
Sleep(1000)
Send("^A")
Sleep(1000)
;~ sql()
;~ Send(GuiCtrlRead($fields2))
Send("{ENTER}")
Sleep(1000)
If WinActive("Security") Then
Send("{Tab}")
Sleep(1000)
Send("ceeWee6o")
Sleep(2000)
Send("{Enter}")
Sleep(1000)
Else
Send("!C{Down}")
Send("w{Enter}")

EndIf

EndFunc

Func WakeOnLan() ; need to fix this so that it removes all that funky stuff I need it to
$IPAddress = GuiCtrlRead() ; I want to be able to have this use the IP address associated with the computer name in $Input1
$MACAddress = GUICtrlRead() ; I want to be able to have this use the MAC address associated with the computer name in $Input1


UDPStartUp()

$connexion = UDPOpen($IPAddress, 7)
$res = UDPSend($connexion, GenerateMagicPacket($MACAddress))
MsgBox(0, "", $res)

UDPCloseSocket($connexion)
UDPShutdown()

EndFunc

; ===================================================================
; Functions
; ===================================================================


; This function convert a MAC Address Byte (e.g. "1f") to a char
Func HexToChar($strHex)

Return Chr(Dec($strHex))

EndFunc

; This function generate the "Magic Packet"
Func GenerateMagicPacket($strMACAddress)

$MagicPacket = ""
$MACData = ""

For $p = 1 To 11 Step 2
$MACData = $MACData & HexToChar(StringMid($strMACAddress, $p, 2))
Next

For $p = 1 To 6
$MagicPacket = HexToChar("ff") & $MagicPacket
Next

For $p = 1 To 16
$MagicPacket = $MagicPacket & $MACData
Next

Return $MagicPacket

EndFunc
Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

grimmlock,

Two things:

1 - You've defined what you want to do but not what is failing

2 - Your code cannot be run as posted to duplicate the error, if any.

If you are seeking advice on technique (as you seem to be doing) then post a small, runnable reproducer.

kylomas

edit: Is this question related to thread?

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Sorry but I no longer want to pursue this route.

Thanks!


Thanks

Grimm

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Dimmae
      By Dimmae
      Hello,
      at first: i'm new here, so please forgive me my mistakes, and show them to me, just that i can learn to do better in the future.
      Now to my Problem: i have an excel sheet, where i just need some columns for further actions, but i have no idea how to add single columns to a new array.
      I found the following code(the one i just added as a file) from 'water' in this forum, but i wont get how i could add multiple columns into a new array.
      The biggest problem in my situation is that i dont know the count of the rows i need for the array, i just got a fix number of rows, which is 4.
       
      Hope you can help me, and sry again for this 'unlucky illustration'.
       
      btw: how can i add code shown as code here, instead of posting it as a attached file?.
       
       
       
      autoit-select-column.au3
      defects.xlsx
    • IAMK
      By IAMK
      Hello,
       
      I have a script which uses a GUI with two buttons. It gets shown and hidden., and pressing the buttons (including their hotkeys) highlights the button, making you able to press enter the next time.
      However, I don't want that.
       
      I've tried using WinActivate() to make enter do things on another program, but the enter is still tied to the AutoIT GUI (which still has the button highlighted).
       
      Here's the important part of my code:
      $MY_GUI = GUICreate("Check.exe", 400, 300, ((@DesktopWidth / 2) - 200), -500) WinSetOnTop($MY_GUI, "", 1) ;Keeps the window on the top. $Button1 = GUICtrlCreateButton("Pass (Ctrl+P)", 40, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("Fail (Ctrl+F)", 240, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $GUIText = GUICtrlCreateLabel("", 20, 10, 360, 230) GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif") GUICtrlSetData($GUIText, Execute($stepMessage[$step])) $showGUI = "True" GUISetState(@SW_SHOW) While($showGUI = "True") $buttonPressed = GUIGetMsg() Switch $buttonPressed Case $Button1 ;Pass $pass = "True" $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) Case $Button2 ;Fail $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) While($message = "") $message = InputBox("Check.exe", "Please enter the reason the step failed." & @CRLF, "", "", 300, 200, ((@DesktopWidth / 2) - 150), -400) WEnd Return $message EndSwitch WEnd Local $pass = "False" ;Whether "Pass" or "Fail" was pressed. Local $failLog = xxxfunc($pass) ;Returns a message to log if the step failed. ##THIS CALLS THE CODE SNIPPET ABOVE## FileWrite($file, _Now() & ": Step " & $step & getStatus($pass) & "and took " & Ceiling(TimerDiff($timer) / 1000) & " seconds." & @CRLF) If($failLog <> "") Then FileWrite($file, "Logged comment: " & $failLog & @CRLF) EndIf WinActivate("[TITLE:ProgramName]") ;Hotkeys: HotKeySet("^{p}", "pressPass") HotKeySet("^{f}", "pressFail") Func pressPass() $buttonPressed = $Button1 EndFunc Func pressFail() $buttonPressed = $Button2 EndFunc  
      The GUI's button/hotkey pressing works correctly.
      The same WinActivate code works in another script of mine.
      Together, WinActivate is not take "Active" away from the GUI's last-pressed button. How do I fix this?
       
      Thank you in advance.
    • fatpig
      By fatpig
      Dear AutoIT Community.
      I am currently working on a program that will display lots of images in a scroll down GUI.
      I create the GUI based on the number of images, which works fine.
      But all images I place using GuiCtrlCreatePic above a threshold of around 32000 pixels (cant say exactly) are placed at negative locations and finally will reach 0 again
      and will then populate on top of the images placed there before.
      For $i = 1 To $Images[0] ; Get picture dimensions $hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i]) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) ; Resize & place images in GUI $Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, Round($yPos, 0), $MaxImgWidth, $MaxImgWidth * ($iY / $iX)) $yPos = $yPos + $MaxImgWidth * ($iY / $iX) + $Spacer $log = $log & "|" & $yPos $currentlut = $Images[1] Next I have found a limit at 32767 pixels for some GUI elements when googling around.
      Can someone tell me how to circumvent that?
      thanks!
      cheers
      Felix
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3

    • Neonovaz
      By Neonovaz
      Hello
       
      Is there anyway to store word documents in Autoit GUI? For example I have a instruction sheet that I want to bundle up with the exe.

      So a user simply clicks the icon and the stored document will launch  (Something like how you can add objects like excel sheets in word documents )

      (I Know we can launch word files from script directory)