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

    • Skeletor
      By Skeletor
      Hi All,
      I want to make my progress bar progress with the amount of File lines read. 
      How would I do this correctly. So far the code below can sometimes run in the middle of the progress bar and state completed.. and other times it can run into the 200%. 
       
      ;======================================================================== ProgressOn("TITLE", "ACTION") ;======================================================================== For $count = 1 To _FileCountLines($FileRead) Step 1 $string = FileReadLine($FileRead, $count) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] $TM = FileWrite("C:\temp\test.txt", $value1 & " " & $value2 & " " & $value3 & " " & $value4 & @CRLF) ProgressSet($count, $count & "%") Next ;======================================================================== ; PROGRESS BAR OFF ;======================================================================== ProgressSet(_FileCountLines($FileRead), "Completed!") Sleep(750) ProgressOff() ;========================================================================  
    • Emmhor1
      By Emmhor1
      Hi All,

      MAIN QUESTION:
      Is it possible to Call specific function within a GUI

      So I have a script with multiple functions although I don't want to use every function every time.
      My Idea is to create a simple GUI which allows me to select what functions I want to use then run the funtions by clicking a button.
      I have already made a GUI which allows me to select specific .exe's I would like to run after selection it runs the .exe one by one.
      This script is on my work laptops and cannot access it right now.
       
      Who can help me with this?
      GUIcreate
      Func1 
      Func2
      Func3
      Then have a boxes which allows me to select the specif Func.(I used GUIChecked and Unchecked in my other script)
      Then a button which executes/calls the selected functions
    • TheGreatMomo
      By TheGreatMomo
      Here is the script for the variable I want to find:
      Local $oSunHrsTD = _IETagNameGetCollection($oFrameobj, "span").item(138)
      The Item(138) for the span elemets is a dynamic number based on the index of all span objects on the webpage I am trying to send inputs to. 
      Based on the span.item(#) the corresponding InnerText for that element is the value that I want to get. Which I use the following script:
      Local $oSunHrs = $oSunHrsTD.InnerText
      Global $otime = _IECreate ("https://somewebsite.banana") _IELoadWait($otime) Local $oFrameobj = _IEFrameGetObjByName($otime, "gsft_main") Local $oLinks = _IETagNameGetCollection($oFrameobj, "a") For $oLink In $oLinks If $oLink.ClassName = "linked formlink" Then _IEAction($oLink, "click") ExitLoop EndIf Next _IEloadWait($oFrameobj) Local $oMonHrsTD = _IETagNameGetCollection($oFrameobj, "span").item(139) Local $oMonHrs = $oMonHrsTD.InnerText _IELoadWait($oFrameobj) Local $oFrameobj = _IEFrameGetObjByName($otime, "gsft_main") Local $oMonHrs = _IETagNameGetCollection($oFrameobj, "SPAN") For $oMonHr In $oMonHrs If $oMonHr.ClassName = "aggregate_value" Then If $oMonHr.innertext >= "8" Then Local $oMonAdjHr = (8 - $oMonHR.Innertext) ConsoleWrite( $oMonHrs &@CRLF ) MsgBox (0, "Adjusted Value", $oMonAdjHr) ExitLoop EndIf EndIf Next  
      Where I get confused is how I find Item(#) if all I have is the InnerText. Since the InnerText is static and the Item# is dynamic:
      $oSunHrsTD = _IETagNameGetCollection($oFrameobj, "span").item( "x").InnerText = ("sometext")
      How can i get the X value??
       
    • Vikramjeet
      By Vikramjeet
      $oExcel = ObjCreate("Excel.Application") $oExcel.Visible = 0 #include <MsgBoxConstants.au3> #Include <File.au3> Global $arlines WinActivate("MyApplication") ;Activate My Application Local $hWnd = WinWaitActive("MyApplication", "", 5) ;Wait for My Application for 5 seconds $oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\Data.xlsx") ;Open Excel file 'Data.xlsx' local $iCell = $oExcel.Application.Cells(31,1).Value ;Read the value from cell A31 $file = @ScriptDir & "\Capture.log" If $hWnd Then For $a = 1 to $iCell ;STEP 1 Send("G*L") Send($oExcel.Application.Cells($a,1).Value) Send("/XUSR") Sleep(1000) Send("{ENTER}") Sleep(2000) ;===> Once the script has sent the above formats to 'MyApplication, A log file (Capture.log) is generated. What do I add as a link so the script moves to ;the following steps _FileReadToArray ($file, $arlines) For $i = $arlines [0] To 1 Step - 1 ; Script starts reading the log file from bottom up If $arlines [$i] = "‡NOT VALID" Then ;===> If I find the word '‡NOT VALID', then I want the script to go to STEP 1 in loop Else ;====> Else I want the script to do the following steps Send("MB") ; Continue sending formats to 'MyApplication' Send("{ENTER}") Sleep(2000) $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0] ; Read number at a certain location in Capture.log file ConsoleWrite($iNum & @CRLF) EndIf ;====> Use the captured $iNum in the loop below. What do I add to proceed to the following steps For $i = 1 To $iNum Send("SET"& $i &"/USR") Sleep(500) Send("{ENTER}") Sleep(1000) ;====> Go back to STEP 1 $oExcel.Application.Quit I am a beginner and need help with If, then, else jump to specific loop in the script. Can I please get help with my script where I have multiple loops. I need to link the steps and also break the sequence and jump to specific loop if a certain condition is found in one loop. 
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
×