Jump to content

Need to send data from List


grimmlock
 Share

Recommended Posts

  • Moderators

grimmlock,

coding is very new to me

As it was to all of us at one stage. And there is no need to apologise - as you can see you will get lots of help here (if you explain the problem clearly!). But we want to know that you understand what we are telling you - repeating ourselves over and over again is not that much fun. ;)

So that is why I asked - do you really follow what is happening in that script? :huh:

If not, ask! :D

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

Quick question

I have tried to look online for the answer but I have had no luck, Maybe I am just not typing in the correct search items.

I have a ping command setup so that when I select an item from a combo box and click on the button to ping, it starts at the top of the list, however when I stop the ping and select a second item from the combo list and click on ping, it starts off where it left off. Is there a way to get the ping to start from the top every time I stop the ping? I am getting an error which I have not been able to fix as well as I cannot seem to find out how to get the ping to stop and start at the top

The error I get is Variable used with being declared, $ibegin

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

Global $fPing = False

GUICreate("Ping", 315, 310)

GUISetState()

$List1 = ("www.google.com|www.bing.com|www.dell.com")
$List2 = ("www.yahoo.com")

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)
Local $Button_1 = GUICtrlCreateButton("PING", 10, 35, 115)
Local $Combo1 = GUICtrlCreateCombo("", 10, 10, 125, 10)
GuiCtrlSetData(-1, "Website1|Website2|")

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

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

$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 "Website1"
GuiCtrlSetData($Input1, "|" & $List1)

Case "Website2"
GuiCtrlSetData($Input1, "|" & $List2)

EndSwitch
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

Thanks :)

Grimm

Edit missed this:

$iBegin = TimerInit() silly me

Edited by grimmlock

Thanks

Grimm

Link to comment
Share on other sites

  • Moderators

grimmlock,

2 points I noticed in the code:

- 1. You were never reading the number of items in the list after you had filled it, which meant that the coutn was always set at 0. This in turn meant that you never advanced the selection in the list with the Mod line when Pinging.

- 2. To start from the top of the list each time, just reset the index to 0 whenever you stop Pinging. Then when you start again you select the top item.

Look for the <<<<<<<<<<<<<< lines in this modified script:

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

Global $fPing = False

GUICreate("Ping", 315, 310)

GUISetState()

$List1 = ("www.google.com|www.bing.com|www.dell.com")
$List2 = ("www.yahoo.com")

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)
Local $Button_1 = GUICtrlCreateButton("PING", 10, 35, 115)
Local $Combo1 = GUICtrlCreateCombo("", 10, 10, 125, 10)
GUICtrlSetData(-1, "Website1|Website2|")

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


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

$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)
                    ; And reset the index to 0
                    $iIndex = 0 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Point 2
                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 "Website1"
                    GUICtrlSetData($Input1, "|" & $List1)

                Case "Website2"
                    GUICtrlSetData($Input1, "|" & $List2)

            EndSwitch
            $iCount = _GUICtrlListBox_GetCount($Input1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Point 1
    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
            ConsoleWrite($iIndex & @CRLF)
            $iIndex = Mod($iIndex + 1, $iCount)
            ConsoleWrite($iIndex & @CRLF)
        EndIf
    EndIf

WEnd

All clear? :)

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

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