Jump to content
Sign in to follow this  
Razormaul

Looping Functions to listview

Recommended Posts

Razormaul

This is a repost, since the thread was deleted due to database issues. - https://www.autoitscript.com/forum/topic/173518-thread-deleted/

 

Hello fellow geeks:)

I am making a small program for work, a tool with shortcuts and host monitoring.

The program has several tab and  I need help with the tab called "Servers/Hosts"

The tab reads hostnames or ip adresses from an ini file and writes them to a listview. You can add or remove hosts, ping, connect with mstsc and delete the whole list. Now...

Im checking for ip adresses on start of the program, or with a refresh button - so far so good.. It´s working.

I also have a function to check if a host is online and write it to the listview, but i cant make it work (im not good enough yet) - (ALMOST SOLVED -  Writing a dummyhost e.g. "test" as hostname, gets the status "Online" - im currently working on that )

This check needs to run every 10 seconds or so, among with the check for ip adresses. But again, (im not good enough yet) - (SOLVED USING AdlibRegister)

I´ve tried to put the functions in a loop in different places in the script. They either "block" the script or hide it.

If i can get the loop to work, there is no need for a refresh button. and i want to put the foldercheck in the VIKING tab in a similar loop, displaying a warning instead of having to click a button. (but thats a different question)

I hope one of you briliant minds can help me along the way:) Thank you for your time.

Tobias

 

 

IT-Tools.V13.au3

Servers.ini

Edited by Razormaul
updated files

Oh, my God. They found me. I don't know how, but they found me. Run for it, Marty!

Share this post


Link to post
Share on other sites
Venix

Are you still struggling with any part of this script? It looks functional to me.

Edit: Other than the fact of it being difficult to close because of the constant refreshing of the ping command.

Edited by Venix

Share this post


Link to post
Share on other sites
Razormaul

OK, this is starting to get annoing:mad: Last 2 replies is now gone!  :'(  (I know your updating)

The issue is getting the corret status from a ping to a listview.

I´ve done many different things with If, If Else statements. I´ve also tried Switch Case:

; GET STATUS OF HOST: OFFLINE / ONLINE AND WRITE TO LISTVIEW ########==>
Func GetStatus()

   Local $iniRead = IniReadSection (@ScriptDir & "\Servers.ini", "Servers")


    For $i = 0 To $iniRead[0][0]
        $Ip = $iniRead[$i][1]
        Local $iPing = Ping($Ip, 2000)


        ;MsgBox(0, "$Ip = ", $Ip)
        ;MsgBox(0, "@error", @Error)

        If $iPing > 0 Then
            _GUICtrlListView_AddSubItem($listview_srv, $i, "Online", 2)
                If @error = 1 Then
                    _GUICtrlListView_AddSubItem($listview_srv, $i, "Offline", 2)
                        If @error = 2 Then
                            _GUICtrlListView_AddSubItem($listview_srv, $i, "Unreachable", 2)
                                If @error = 3 Then
                                    _GUICtrlListView_AddSubItem($listview_srv, $i, "Bad Destination", 2)
                                        If @error = 4 Then
                                            _GUICtrlListView_AddSubItem($listview_srv, $i, "Error", 2)
                                                If $Ip = "" Then
                                                    _GUICtrlListView_AddSubItem($listview_srv, $i, "IP Missing", 2)

                                                EndIf
                                        EndIf
                                EndIf
                        EndIf
                EndIf
        EndIf

    Next

EndFunc

And the Case: 

Switch $iPing

    Case $iPing > 0
        _GUICtrlListView_AddSubItem($listview_srv, $i, "Online", 2)
    Case Else @error = 1
        _GUICtrlListView_AddSubItem($listview_srv, $i, "Offline", 2)
    Case Else @error = 2
        _GUICtrlListView_AddSubItem($listview_srv, $i, "Unreachable", 2)
    Case Else @error = 3
        _GUICtrlListView_AddSubItem($listview_srv, $i, "Bad Destination", 2)
    Case Else @error = 4
        _GUICtrlListView_AddSubItem($listview_srv, $i, "Error", 2)
    Case Else $Ip = ""
        _GUICtrlListView_AddSubItem($listview_srv, $i, "IP Missing", 2)

EndSwitch

Im currently working on the updating problem (GUI is unresponsive while the functions are running)

 

Edited by Razormaul

Oh, my God. They found me. I don't know how, but they found me. Run for it, Marty!

Share this post


Link to post
Share on other sites
Venix

@‌Razormaul

Ill take a look at this when I get home tonight, assuming I don't forget. The GUI will be unresponsive whilst functions are running because AutoIT is a single threaded language. Unfortunately as your function takes a while to run this will cause the GUI to hang which is undesirable. Some fellow users might have some suggestions about how you can handle such problems more elegantly. One thing you could do is handle all the pinging with a completely separate script and then that script could output the necessary data to a file. And then every 30 seconds or so your script can pull in the new information from the file.

Edit: I wouldn't necessary say this Is a great solution but you have to work with the boundaries of a single thread.

 

Edited by Venix

Share this post


Link to post
Share on other sites
Venix

Does this work for you?

; GET STATUS OF HOST: OFFLINE / ONLINE AND WRITE TO LISTVIEW ########==>
Func GetStatus()

   Local $iniRead = IniReadSection (@ScriptDir & "\Servers.ini", "Servers")

    For $i = 0 To $iniRead[0][0]
        Local $Ip = $iniRead[$i][1]
        Local $iPing = Ping($Ip, 2000)
        Local $error = @error

        Select
            Case $iPing > 0
                _GUICtrlListView_AddSubItem($listview_srv, $i, "Online", 2)
            Case $error = 1
                _GUICtrlListView_AddSubItem($listview_srv, $i, "Offline", 2)
            Case $error = 2
                _GUICtrlListView_AddSubItem($listview_srv, $i, "Unreachable", 2)
            Case $error = 3
                _GUICtrlListView_AddSubItem($listview_srv, $i, "Bad Destination", 2)
            Case Else
                _GUICtrlListView_AddSubItem($listview_srv, $i, "Other", 2)
        EndSelect
    Next
EndFunc

 

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  

  • Similar Content

    • AndreasNWWWWW
      By AndreasNWWWWW
      I got a question:  i am trying to run different functions based upon what i select in these radio buttons.(code below)
      it needs to check server 1. then run function 1 or function 2 after what i selected in the checkbox.
      once that function is done it moves to the next one, until it has been trough all 5 
       
      iv'e tried using while loops with different while $i equals to something but then i manualy need to go in and edit the script every time.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) $Server2 = GUICtrlCreateLabel("Server2", 216, 95, 41, 17) $server1 = GUICtrlCreateLabel("Server1", 216, 72, 41, 17) $server4 = GUICtrlCreateLabel("Server4", 216, 144, 41, 17) $server3 = GUICtrlCreateLabel("Server3", 216, 119, 41, 17) $server5 = GUICtrlCreateLabel("Server5", 216, 170, 41, 17) $Start = GUICtrlCreateButton("Start", 240, 248, 147, 25) $Checkbox1 = GUICtrlCreateCheckbox("function1", 288, 72, 97, 17) $Checkbox2 = GUICtrlCreateCheckbox("function2", 392, 72, 97, 17) $Checkbox3 = GUICtrlCreateCheckbox("function1", 288, 96, 97, 17) $Checkbox4 = GUICtrlCreateCheckbox("function2", 392, 96, 97, 17) $Checkbox5 = GUICtrlCreateCheckbox("function1", 288, 120, 97, 17) $Checkbox6 = GUICtrlCreateCheckbox("function2", 392, 120, 97, 17) $Checkbox7 = GUICtrlCreateCheckbox("function1", 288, 144, 97, 17) $Checkbox8 = GUICtrlCreateCheckbox("function2", 392, 144, 97, 17) $Checkbox9 = GUICtrlCreateCheckbox("function1", 288, 170, 97, 17) $Checkbox10 = GUICtrlCreateCheckbox("function2", 392, 170, 97, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
    • MrCheese
      By MrCheese
      hi all,
      Dumb question, but say I have a loop:
      dim $i Do     sleep(1000)          if $i = ; how do i do a function that enters this IF statement every 10 loops?         ; do stuff every 10     EndIf      Until $i = 100  
      - what commands in the if statement do I need to use to make it pass, and on every 10th loop, it enters the if statement. ?
       
      Thanks
    • wsc77320
      By wsc77320
      Maybe I am trying this all wrong, but hope someone can help. I have a GUI and want to click a button which will start a function to get a folder location. Then I need to pass that location to a variable to use outside the function. Here is a sample of the code;It prompts to choose a file location and the message box displays the choice but that is all inside the function. I need to pass the path selected outside the function. OR need a different way of doing this, maybe my approach is wrong.
      $Label_Drive=GUICtrlCreateLabel("Use the select button and choose where profiles will be stored.", 15, 120, 240, 25)
      $BTN_Set_BKP_Path = GUICtrlCreateButton("Select Location", 250, 120, 90, 30) ;left,top,width,heigth
      GUICtrlSetOnEvent($BTN_Set_BKP_Path, "Location")
       
      Func Location()
      $BKP_Path = FileSelectFolder("Select a folder where profiles will be stored.", "c:\")
      MsgBox(0,"Select Path", "You set the path as " & $BKP_Path)
      EndFunc
       
      $Label_BKP_Path=GUICtrlCreateLabel("Current path is " & $BKP_Path & ".", 15, 150, 300, 25)
       
       
    • kklee69
      By kklee69
      When LISTVIEW loses focus,the selected item will turn gray.
      How can I change It . Let it continue to stay blue
      Do not gray

       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $listview, $button, $item1, $item2, $item3, $msg GUICreate("LISTVIEW", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("NO1 |NO2|NO3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING) $button = GUICtrlCreateButton("BUTTON", 75, 170, 70, 20) $item1 = GUICtrlCreateListViewItem ("A1|A2|A3", $listview) $item2 = GUICtrlCreateListViewItem ("B1|B2|B3", $listview) $item3 = GUICtrlCreateListViewItem ("C1|C2|C3", $listview) $item4 = GUICtrlCreateListViewItem ("D1|D2|D3", $listview) $item5 = GUICtrlCreateListViewItem ("E1|E2|E3", $listview) GUICtrlCreateInput("", 20, 200, 150) GUISetState() Do $msg = GUIGetMsg() Select Case $msg = $button MsgBox(0, "", GUICtrlRead(GUICtrlRead($listview)), 2) Case $msg = $listview MsgBox(0, "", "" & GUICtrlGetState($listview), 2) EndSelect Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example  
    • Karnalsyn
      By Karnalsyn
      As with a lot of programming, the less manual repetition done to achieve the same outcome...the better.
      I package programs for network deployment at the organization I work for. Sometimes these applications require verbose messaging to the user, and sometimes by special request we have to turn that off and deploy silently.
      The way I currently handle these 2 scenarios is this.
      I have a function that builds the splashwin display screen to variable size depending on message length, and displays the desired message to the end user.
      Then at each point throughout my script as I need to make the user aware of what is currently happening, I inject a splashwin function call with the unique message pertaining to that specific event. ie. "Installing Microsoft Office, please wait..."
      In effort to build a more universal script to handle any type of request submitted. I've incorporated a switch command of '/silent'
      If cmdlineraw detects the usage of that switch when the script is triggered it sets a variable flag, ie. $silent = "on"
      Then at every splashwin call I make, I'm prefixing it with an IF statement that checks for the flag, and then does NOT display the message if that flag is "on". Or does display it if its not. Has worked for me just fine. But while I grow my programming skills and look for more streamlined ways of handling areas I find myself creating repetition. I'm curious if I can relocate that flag check. Taking it out of every single splashwin call, and injecting it into the function itself.
      Example of how I currently display or hide the splashwin based on command line...
      If StringInStr($cmdlineraw, "/silent", 0) Then
          $SilentSwitch = "ON"
      EndIf
      If $SilentSwitch = "OFF" Then SplashWin($Uninstalling & $ProductInfo[1][0])
      Some scripts have dozens of those splashwin calls littered throughout, so Is this the best approach I can take already? Or as stated earlier, can I pull the IF statement away from the splashwin call. And left the function as a whole either activate or deactivate as a result of the command line check.
×