Jump to content

Need to send data from List


grimmlock
 Share

Recommended Posts

Hello again

Here are my problems

1) When I click on the drop down box and select branch1 it shows the items in list 1, however I only want it to show the name of the pc (testpc.testnet.local) that way When I hit the ping button it only pings the name of the PC.

Because there are spaces in the list items (just like my text files) it is displaying all the information and not just the name, which when I run the Netsupport button (opening notepad) it does remove the last 12 characters but the rest of the information is still there which will not work when I ping it.

2) When I hit the Netsupport button I would like the item (in List1) that is selected to send its IP address instead of the name

Right now it is doing what the code is asking, however all I want it to do is send just the IP address of the List line, instead of the whole line.

3) The Wake on Lan button it requires the IP and the Mac address of the computer is sending the "magic packet", so what I am trying to do is take the ip address and the mac from the selected computer in $List1 and send it to the Wake On Lan code so that it will wake up the selected computers in the list.

4) When I stop the ping and move to a new branch, is there a way to get the pings to start back at the top of the list?

Right now it is starting where it left off, could be the top, bottom or somewhere in the middle

I hope that this helps explain what I am trying to do.

#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 = ("Testingpc.testnet.local 192.168.2.1 00-00-00-00-00|Testing2pc.testnet.local 192.168.2.2 00-00-00-00-00-00") ; Branch1
$List2 = ("Testpc.testnet.local 192.168.1.1 00-00-00-00-00|Test2pc.testnet.local 192.168.1.2 00-00-00-00-00-00") ; 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 = ("") ; 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)
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
Run("notepad")
_local()


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

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()
WinActivate("NetSupport : ")
Send("!C{Down}")
Send("Q")
Sleep(1000)
Send("^A")
Sleep(1000)
_local()
Send("{ENTER}")
Sleep(1000)
If WinActive("Security") Then
Send("{Tab}")
Sleep(1000)
Send("password")
Sleep(2000)
Send("{Enter}")
Sleep(1000)
Else
Send("!C{Down}")
Send("w{Enter}")

EndIf

EndFunc

Func _local()
Local $Input3 = GUICtrlRead($Input1)
Local $Input4 = StringTrimRight(GUICtrlRead($Input1), 12) ; << Remove everything from the first .
If StringInStr(GuiCtrlRead($Input1), ".local") Then
Send($Input4)
Sleep(1000)
Else
Send($Input3)
Sleep(1000)
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

:)

Thanks

Grimm

Link to comment
Share on other sites

You're going to need to split the information read from the control yourself, there's no built-in function to do that. Seeing as how there's a space in between the name and the IP address, you could use StringSplit to do that with the space as the character to split on.

Also, why are you using the cmd console to run the programs you're running, why not just use the Run command and save yourself the heartache of Send commands to the console?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BrewManNH,

Thank you for the quick reply, I figured I would have to use a stringsplit, I am just not sure where it goes in order to do what I am trying to accomplish. Would creating a new function be the best way to accomplish the springsplit?

To answer your second question about Run and send, it is because I am still learning and for me it is easier to use Send.

Thanks :)

Thanks

Grimm

Link to comment
Share on other sites

You would stringsplit the string you get from GUICtrlRead($Input1), just remember StringSplit returns an array so you'd have to take that into account.

Send will not be easier if someone moves the mouse, hits a key on the keyboard, or changes which window is focused. Learning to do it the best way, not the "easiest" way, is always going to be a winner.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

So I stripped a lot out of the script so that I could focus on just 1 item at a time. When I push the Wake On Lan button it displays a list view however it only shows a 0 in the list2, any ideas?

#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>
#include <guilistview.au3>


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


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


GUISetState()

;~ IP Addresses
$List1 = ("Testingpc.testnet.local 192.168.2.1 00-00-00-00-00|Testing2pc.testnet.local 192.168.2.2 00-00-00-00-00-01") ; Branch1
$List2 = ("Testpc.testnet.local 192.168.1.1 00-00-00-00-02|Test2pc.testnet.local 192.168.1.2 00-00-00-00-00-03") ; Branch2



Local $Combo1 = GUICtrlCreateCombo("", 10, 20, 125, 10)
GUICtrlSetData(-1, "Branch1|Branch2|")

; 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_2 = GUICtrlCreateButton("Wake On Lan", 10, 380, 115)
Local $Button_3 = GUICtrlCreateButton("Netsupport Manager", 10, 440, 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)


; Get a timestamp
$iBegin = TimerInit()

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit



Case $Combo1
Switch GUICtrlRead($Combo1)
Case "Branch1"
;~ ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch1
GUICtrlSetData($Input1, "|" & $List1)


Case "Branch2"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch2
GUICtrlSetData($Input1, "|" & $List2)

Case "Branch3"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch3
GUICtrlSetData($Input1, "|" & $List3)

Case "Branch4"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch4
GUICtrlSetData($Input1, "|" & $List4)



EndSwitch

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

; <<<Added

Case $Button_2
GuiCtrlSetData($Input2, GuiCtrlRead(Test()))

Case $Button_3
Run("notepad")
_local()

EndSwitch
WEnd

Func Test()

Local $listview = GUICtrlCreateListView("Test", 600, 20, 200, 100)
Local $string = GuiCtrlRead($Input1)
Local $splited = StringSplit($string, " ")
For $i = 3 To $splited[0]
$test = GUICtrlCreateListViewItem($splited[$i], $listview)
Next
Sleep(2000)
_GUICtrlListView_DeleteAllItems("Test")
EndFunc

Func _local()
Local $Input3 = GUICtrlRead($Input1)
Local $Input4 = StringTrimRight(GUICtrlRead($Input1), 12) ; << Remove everything from the first .
If StringInStr(GuiCtrlRead($Input1), ".local") Then
Send($Input4)
Sleep(1000)
Else
Send($Input3)
Sleep(1000)
EndIf
EndFunc

Thanks!!

Edited by grimmlock

Thanks

Grimm

Link to comment
Share on other sites

Completely re-did my code, and everything works with the exception of this.

When I select branch 1 from the drop down the desired result is to populate $Input1 with the just the name of the PC (1Testingpc.testnet.local)

My code is setup to show a message box with the results instead of putting them into the input box so that i can get a better result. Any help would be greatly appreciated

#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>
#include <guilistview.au3>


; Declare a flag

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

GUISetState()

;~ IP Addresses
$List1 = ("1Testingpc.testnet.local 192.168.2.1 D0-67-E5-39-E9-85|2Testing2pc.testnet.local 192.168.2.2 00-00-00-00-00-01") ; Branch1
$List2 = ("3Testpc.testnet.local 192.168.1.1 00-00-00-00-02|4Test2pc.testnet.local 192.168.1.2 00-00-00-00-00-03") ; Branch2

Local $Combo1 = GUICtrlCreateCombo("", 10, 20, 125, 10)
GUICtrlSetData(-1, "Branch1|Branch2")

; 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, 300, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling


;~ Controls

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit



Case $Combo1
Switch GUICtrlRead($Combo1)
Case "Branch1"
Global $Menu1 = $List1
_local()


Case "Branch2"
;~ ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch2
Global $Menu2 = $List2
_local()

EndSwitch


EndSwitch
WEnd

Func _local()
Local $string = $Menu1
Local $splited = StringSplit($string, " ")
$i = 1
MsgBox(0, "", $string & $splited[$i])

Sleep(2000)
EndFunc

Thanks in advance :)

Grimm

Thanks

Grimm

Link to comment
Share on other sites

  • Moderators

grimmlock,

I think this does what you want: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <WinAPI.au3>
#include <EditConstants.au3>
#include <Array.au3>

;~ IP Addresses
$List1 = ("1Testingpc.testnet.local 192.168.2.1 D0-67-E5-39-E9-85|2Testing2pc.testnet.local 192.168.2.2 00-00-00-00-00-01") ; Branch1
$List2 = ("3Testpc.testnet.local 192.168.1.1 00-00-00-00-02|4Test2pc.testnet.local 192.168.1.2 00-00-00-00-00-03") ; Branch2

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

GUISetState()

Local $Combo1 = GUICtrlCreateCombo("", 10, 20, 125, 10)
GUICtrlSetData(-1, "Branch1|Branch2")

; Set Cuebanner rather than add an extra element to the combo
$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, 300, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1
            Switch GUICtrlRead($Combo1)
                Case "Branch1"
                    ; Pass the required data as a parameter
                    _local($List1)
                Case "Branch2"
                    _local($List2)
            EndSwitch
    EndSwitch
WEnd

Func _local($Menu1)
    ; Now $Menu1 is always the correct list ;)
    ; Firstly split the list into the separate items
    Local $aSplit_1 = StringSplit($Menu1, "|")
    ; Now we extract the info you want from each element
    For $i = 1 To $aSplit_1[0]
        Local $aSplit_2 = StringSplit($aSplit_1[$i], " ")
        ; And just store that bit
        $aSplit_1[$i] = $aSplit_2[1]
    Next
    ; Now recreate the string to add to the list control
    $sList = "|" & _ArrayToString($aSplit_1, "|", 1)
    ; And then add it
    GUICtrlSetData($Input1, $sList)
EndFunc   ;==>_local

Questions? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Dumb question, what happens to the data after the spaces (the IP and MAC) once $list1 is populated?

The reason I ask is because I have another function that needs to call the same data only use the IP and/or the Mac. If you would like I can post the code for the func I was working on for sending the IP to notepad.

Thanks

Grimm

Link to comment
Share on other sites

  • Moderators

grimmlock,

The data in $List1 and $List2 remains intact - you are only modifying the array returned by StringSplit within the function. So you can do the same sort of thing again to extract different parts of the data just by changing the delimiter character. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Can you copy the same function to a new function just label it differently? like copy _local() to _local(2) and simply change this line $aSplit_1[$i] = $aSplit_2[2]?

The reason I ask is I tried that and I get the error: Incorrect number of parameters in function call :(

Thanks

Grimm

Thanks

Grimm

Link to comment
Share on other sites

  • Moderators

grimmlock,

You need to change the name only - the items in the brackets are the parameters. So _local_2($Menu1) should work. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Nope still getting the crazy error grrrr

Here is the code I am using

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <WinAPI.au3>
#include <EditConstants.au3>
#include <Array.au3>

;~ IP Addresses
$List1 = ("1Testingpc.testnet.local 192.168.2.1 D0-67-E5-39-E9-85|2Testing2pc.testnet.local 192.168.2.2 00-00-00-00-00-01") ; Branch1
$List2 = ("3Testpc.testnet.local 192.168.1.1 00-00-00-00-02|4Test2pc.testnet.local 192.168.1.2 00-00-00-00-00-03") ; Branch2

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

Local $Combo1 = GUICtrlCreateCombo("", 10, 20, 125, 10)
GUICtrlSetData(-1, "Branch1|Branch2")

; Set Cuebanner rather than add an extra element to the combo
$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, 300, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling

$button1 = GuiCtrlCreateButton("Test", 10, 50, 125)
GuiCtrlSetState(-1, $GUI_DISABLE)

GUISetState()

While 1

Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $Combo1
GuiCtrlSetState($button1, $GUI_ENABLE)
Switch GUICtrlRead($Combo1)
;~ GUICtrlSetState($button1, @SW_ENABLE)
Case "Branch1"
; Pass the required data as a parameter
_local($List1)
Case "Branch2"
_local($List2)
EndSwitch

Case $button1
_local_2($Menu1)

EndSwitch
WEnd

Func _local_2($Menu1)
; Now $Menu1 is always the correct list ;)
; Firstly split the list into the separate items
Local $aSplit_1 = StringSplit($Menu1, "|")
; Now we extract the info you want from each element
For $i = 1 To $aSplit_1[0]
Local $aSplit_2 = StringSplit($aSplit_1[$i], " ")
; And just store that bit
$aSplit_1[$i] = $aSplit_2[2]
Next
; Now recreate the string to add to the list control
$sList = _ArrayToString($aSplit_1, "|", 1)
; And then add it
Msgbox(0, "", $sList)
EndFunc

Func _local($Menu1)
; Now $Menu1 is always the correct list ;)
; Firstly split the list into the separate items
Local $aSplit_1 = StringSplit($Menu1, "|")
; Now we extract the info you want from each element
For $i = 1 To $aSplit_1[0]
Local $aSplit_2 = StringSplit($aSplit_1[$i], " ")
; And just store that bit
$aSplit_1[$i] = $aSplit_2[1]
Next
; Now recreate the string to add to the list control
$sList = "|" & _ArrayToString($aSplit_1, "|", 1)
; And then add it
GUICtrlSetData($Input1, $sList)
EndFunc ;==>_local

Thank you, Thank you, Thank you :)

Edited by grimmlock

Thanks

Grimm

Link to comment
Share on other sites

  • Moderators

grimmlock,

So what is supposed to happen when you press the button? We have spoken of this before - we cannot read your mind! ;)

From our previous threads I assume you want to extract the IP related to the PC selected in the list. If that is the case then, as I have already shown you, you need to look for that PC in the data and then work on that element alone. So you need a different function - perhaps something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <WinAPI.au3>
#include <EditConstants.au3>
#include <Array.au3>

;~ IP Addresses
$List1 = ("1Testingpc.testnet.local 192.168.2.1 D0-67-E5-39-E9-85|2Testing2pc.testnet.local 192.168.2.2 00-00-00-00-00-01") ; Branch1
$List2 = ("3Testpc.testnet.local 192.168.1.1 00-00-00-00-02|4Test2pc.testnet.local 192.168.1.2 00-00-00-00-00-03") ; Branch2

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

Local $Combo1 = GUICtrlCreateCombo("", 10, 20, 125, 10)
GUICtrlSetData(-1, "Branch1|Branch2")

; Set Cuebanner rather than add an extra element to the combo
$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, 300, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling

$button1 = GUICtrlCreateButton("Test", 10, 50, 125)
GUICtrlSetState(-1, $GUI_DISABLE)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1
            GUICtrlSetState($button1, $GUI_ENABLE)
            Switch GUICtrlRead($Combo1)
;~ GUICtrlSetState($button1, @SW_ENABLE)
                Case "Branch1"
                    ; Pass the required data as a parameter
                    _local($List1)
                Case "Branch2"
                    _local($List2)
            EndSwitch

        Case $button1
            _local_2()

    EndSwitch
WEnd

Func _local_2()

    Local $Menu1

    ; Which PC in the list has been selected:
    $sSelection = GUICtrlRead($Input1)
    ; Has a selecting been made?
    If $sSelection <> "" Then
        ; Now we need to know which list we must use
        Switch GUICtrlRead($Combo1)
            Case "Branch1"
                $Menu1 = $List1
            Case "Branch2"
                $Menu1 = $List2
        EndSwitch
        ; Now we split the list into elements
        Local $aSplit_1 = StringSplit($Menu1, "|")
        ; Now we split each of these elements
        For $i = 1 To $aSplit_1[0]
            Local $aSplit_2 = StringSplit($aSplit_1[$i], " ")
            ; Have we found the PC name?
            If $aSplit_2[1] = $sSelection Then
                ; The IP should be the [2] element
                MsgBox(0, $sSelection, $aSplit_2[2])

                ; And here you put the code you need to use it

                ; No point in looking any further
                ExitLoop
            EndIf
        Next
    EndIf

EndFunc   ;==>_local_2

Func _local($Menu1)
    ; Now $Menu1 is always the correct list ;)
    ; Firstly split the list into the separate items
    Local $aSplit_1 = StringSplit($Menu1, "|")
    ; Now we extract the info you want from each element
    For $i = 1 To $aSplit_1[0]
        Local $aSplit_2 = StringSplit($aSplit_1[$i], " ")
        ; And just store that bit
        $aSplit_1[$i] = $aSplit_2[1]
    Next
    ; Now recreate the string to add to the list control
    $sList = "|" & _ArrayToString($aSplit_1, "|", 1)
    ; And then add it
    GUICtrlSetData($Input1, $sList)
EndFunc   ;==>_local

This is a virtual repeat of what we went through in your last thread - I get the impression that none of this is really sinking in - am I correct? :huh:

If that is indeed the case, then please start asking basic questions about the various functions and code structures we are using because if you do not understand the principles behind the code I post there is very little point in you trying to use these snippets to create more elaborate scripts. All you will do is keep coming back askign the same old questions. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Developers

You are not initialising/setting any value for $Menu1.

Use the Full version of SciTE4AutoIt3 which runs au3check for you and tells you about these issues.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

×
×
  • Create New...