KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Code for an automatic check of server ping responses

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Tue Jan 20, 2004 11:53 pm    Post subject: Code for an automatic check of server ping responses Reply with quote

I hope that this is usefull to others out there.

Code:
; Written By Wayne A Kimball  MCNS II
; State of Alaska / DHSS / OCS
; kimballw@health.state.ak.us
; ====================================
;
; This file is used to automatically check if a server
; responds to a ping command
;
; Lets start by building the 2 forms that we use
; ====================================

Break On
SetConsole (hide)
;********* FORM CREATE BEGIN **********
$Form = CreateObject('Kixtart.Form')
$Form.BackColor = 212,208,200
$Form.ControlBox = "True"
$Form.DrawGrid = "True"
$Form.FontBold = "False"
$Form.FontItalic = "False"
$Form.FontName = "Microsoft Sans Serif"
$Form.FontSize = 8.25
$Form.FontUnderline = "False"
$Form.ForeColor = 0,0,0
$Form.FormBorderStyle = 4
$Form.Height = 150
$Form.Left = 0
$Form.MaximizeBox = "False"
$Form.MinimizeBox = "False"
$Form.SizeGripStyle = 0
$Form.StartPosition = 4
$Form.Tag = ""
$Form.Text = "Server Monitor"
$Form.Top = 0
$Form.ToolTipText = ""
$Form.TopMost = "False"
$Form.Width = 464
$Form.WindowState = 0
;********* FORM CREATE END **********

; The following checkbox's are used to
; specify what area (region) we want to
; monitor.
;========================
;==                    ==
;== Change the name to ==
;== what works in your ==
;== enviroment         ==
;==                    ==
;========================

;************* CHECKBOX1 **************
$CheckBox1 = $Form.Controls.CheckBox
$CheckBox1.Anchor = 5
$CheckBox1.Appearance = 0
$CheckBox1.BackColor = 212,208,200
$CheckBox1.Checked = "False"
$CheckBox1.CheckState = 0
$CheckBox1.Enabled = "True"
$CheckBox1.FlatStyle = 2
$CheckBox1.FontBold = "False"
$CheckBox1.FontItalic = "False"
$CheckBox1.FontName = "Microsoft Sans Serif"
$CheckBox1.FontSize = 8.25
$CheckBox1.FontUnderline = "False"
$CheckBox1.ForeColor = 0,0,0
$CheckBox1.Height = 24
$CheckBox1.Left = 345
$CheckBox1.TabStop = "True"
$CheckBox1.Tag = ""
$CheckBox1.Text = "Anchorage"
$CheckBox1.ThreeState = "False"
$CheckBox1.ToolTipText = ""
$CheckBox1.Top = 30
$CheckBox1.Visible = "True"
$CheckBox1.Width = 104
$CheckBox1.Onclick = 'On_Click()'
;*************************************

;************* CHECKBOX2 **************
$CheckBox2 = $Form.Controls.CheckBox
$CheckBox2.Anchor = 5
$CheckBox2.Appearance = 0
$CheckBox2.BackColor = 212,208,200
$CheckBox2.Checked = "False"
$CheckBox2.CheckState = 0
$CheckBox2.Enabled = "True"
$CheckBox2.FlatStyle = 2
$CheckBox2.FontBold = "False"
$CheckBox2.FontItalic = "False"
$CheckBox2.FontName = "Microsoft Sans Serif"
$CheckBox2.FontSize = 8.25
$CheckBox2.FontUnderline = "False"
$CheckBox2.ForeColor = 0,0,0
$CheckBox2.Height = 24
$CheckBox2.Left = 240
$CheckBox2.TabStop = "True"
$CheckBox2.Tag = ""
$CheckBox2.Text = "SouthEast"
$CheckBox2.ThreeState = "False"
$CheckBox2.ToolTipText = ""
$CheckBox2.Top = 30
$CheckBox2.Visible = "True"
$CheckBox2.Width = 104
$CheckBox2.Onclick = 'On_Click()'
;*************************************

;************* CHECKBOX3 **************
$CheckBox3 = $Form.Controls.CheckBox
$CheckBox3.Anchor = 5
$CheckBox3.Appearance = 0
$CheckBox3.BackColor = 212,208,200
$CheckBox3.Checked = "False"
$CheckBox3.CheckState = 0
$CheckBox3.Enabled = "True"
$CheckBox3.FlatStyle = 2
$CheckBox3.FontBold = "False"
$CheckBox3.FontItalic = "False"
$CheckBox3.FontName = "Microsoft Sans Serif"
$CheckBox3.FontSize = 8.25
$CheckBox3.FontUnderline = "False"
$CheckBox3.ForeColor = 0,0,0
$CheckBox3.Height = 24
$CheckBox3.Left = 135
$CheckBox3.TabStop = "True"
$CheckBox3.Tag = ""
$CheckBox3.Text = "SouthCentral"
$CheckBox3.ThreeState = "False"
$CheckBox3.ToolTipText = ""
$CheckBox3.Top = 30
$CheckBox3.Visible = "True"
$CheckBox3.Width = 104
$CheckBox3.Onclick = 'On_Click()'
;*************************************

;************* CHECKBOX4 **************
$CheckBox4 = $Form.Controls.CheckBox
$CheckBox4.Anchor = 5
$CheckBox4.Appearance = 0
$CheckBox4.BackColor = 212,208,200
$CheckBox4.Checked = "False"
$CheckBox4.CheckState = 0
$CheckBox4.Enabled = "True"
$CheckBox4.FlatStyle = 2
$CheckBox4.FontBold = "False"
$CheckBox4.FontItalic = "False"
$CheckBox4.FontName = "Microsoft Sans Serif"
$CheckBox4.FontSize = 8.25
$CheckBox4.FontUnderline = "False"
$CheckBox4.ForeColor = 0,0,0
$CheckBox4.Height = 24
$CheckBox4.Left = 30
$CheckBox4.TabStop = "True"
$CheckBox4.Tag = ""
$CheckBox4.Text = "Northern"
$CheckBox4.ThreeState = "False"
$CheckBox4.ToolTipText = ""
$CheckBox4.Top = 30
$CheckBox4.Visible = "True"
$CheckBox4.Width = 104
$CheckBox4.Onclick = 'On_Click()'
;*************************************

;************* CHECKBOX5 **************
$CheckBox5 = $Form.Controls.CheckBox
$CheckBox5.Anchor = 5
$CheckBox5.Appearance = 0
$CheckBox5.BackColor = 212,208,200
$CheckBox5.Checked = "False"
$CheckBox5.CheckState = 0
$CheckBox5.Enabled = "True"
$CheckBox5.FlatStyle = 2
$CheckBox5.FontBold = "False"
$CheckBox5.FontItalic = "False"
$CheckBox5.FontName = "Microsoft Sans Serif"
$CheckBox5.FontSize = 8.25
$CheckBox5.FontUnderline = "False"
$CheckBox5.ForeColor = 0,0,0
$CheckBox5.Height = 24
$CheckBox5.Left = 345
$CheckBox5.TabStop = "True"
$CheckBox5.Tag = ""
$CheckBox5.Text = "Central Office"
$CheckBox5.ThreeState = "False"
$CheckBox5.ToolTipText = ""
$CheckBox5.Top = 0
$CheckBox5.Visible = "True"
$CheckBox5.Width = 104
$CheckBox5.Onclick = 'On_Click()'
;*************************************

;************* CHECKBOX6 **************
$CheckBox6 = $Form.Controls.CheckBox
$CheckBox6.Anchor = 5
$CheckBox6.Appearance = 0
$CheckBox6.BackColor = 212,208,200
$CheckBox6.Checked = "False"
$CheckBox6.CheckState = 0
$CheckBox6.Enabled = "True"
$CheckBox6.FlatStyle = 2
$CheckBox6.FontBold = "False"
$CheckBox6.FontItalic = "False"
$CheckBox6.FontName = "Microsoft Sans Serif"
$CheckBox6.FontSize = 8.25
$CheckBox6.FontUnderline = "False"
$CheckBox6.ForeColor = 0,0,0
$CheckBox6.Height = 24
$CheckBox6.Left = 240
$CheckBox6.TabStop = "True"
$CheckBox6.Tag = ""
$CheckBox6.Text = "All Sites"
$CheckBox6.ThreeState = "False"
$CheckBox6.ToolTipText = ""
$CheckBox6.Top = 0
$CheckBox6.Visible = "True"
$CheckBox6.Width = 104
$CheckBox6.Onclick = 'On_Click()'
;*************************************

;************* LABEL1 **************
$Label1 = $Form.Controls.Label
$Label1.Anchor = 5
$Label1.BackColor = 212,208,200
$Label1.BorderStyle = 0
$Label1.Enabled = "True"
$Label1.FlatStyle = 2
$Label1.FontBold = "False"
$Label1.FontItalic = "False"
$Label1.FontName = "Microsoft Sans Serif"
$Label1.FontSize = 8.25
$Label1.FontUnderline = "False"
$Label1.ForeColor = 0,0,0
$Label1.Height = 22
$Label1.Left = 30
$Label1.Tag = ""
$Label1.Text = "Please select the area to monitor"
$Label1.ToolTipText = ""
$Label1.Top = 0
$Label1.Visible = "True"
$Label1.Width = 189
;*************************************

;************* BUTTON1 **************
$Button1 = $Form.Controls.Button
$Button1.Anchor = 5
$Button1.TextAlign = 32
$Button1.Enabled = "False"
$Button1.FlatStyle = 2
$Button1.FontBold = "False"
$Button1.FontItalic = "False"
$Button1.FontName = "Microsoft Sans Serif"
$Button1.FontSize = 8.25
$Button1.FontUnderline = "False"
$Button1.ForeColor = 0,0,0
$Button1.Height = 23
$Button1.Left = 45
$Button1.TabStop = "True"
$Button1.Tag = ""
$Button1.Text = "Start"
$Button1.ToolTipText = ""
$Button1.Top = 75
$Button1.Visible = "True"
$Button1.Width = 75
$Button1.OnClick = 'StartButton_Click($TestArray)'
;*************************************

;************* BUTTON2 **************
$Button2 = $Form.Controls.Button
$Button2.Anchor = 5
$Button2.TextAlign = 32
$Button2.Enabled = "False"
$Button2.FlatStyle = 2
$Button2.FontBold = "False"
$Button2.FontItalic = "False"
$Button2.FontName = "Microsoft Sans Serif"
$Button2.FontSize = 8.25
$Button2.FontUnderline = "False"
$Button2.ForeColor = 0,0,0
$Button2.Height = 23
$Button2.Left = 165
$Button2.TabStop = "True"
$Button2.Tag = ""
$Button2.Text = "Dock"
$Button2.ToolTipText = ""
$Button2.Top = 75
$Button2.Visible = "True"
$Button2.Width = 75
$Button2.OnClick = 'DockButton_Click()'
;*************************************

;************* BUTTON3 **************
$Button3 = $Form.Controls.Button
$Button3.Anchor = 5
$Button3.TextAlign = 32
$Button3.Enabled = "True"
$Button3.FlatStyle = 2
$Button3.FontBold = "False"
$Button3.FontItalic = "False"
$Button3.FontName = "Microsoft Sans Serif"
$Button3.FontSize = 8.25
$Button3.FontUnderline = "False"
$Button3.ForeColor = 0,0,0
$Button3.Height = 23
$Button3.Left = 285
$Button3.TabStop = "True"
$Button3.Tag = ""
$Button3.Text = "Exit"
$Button3.ToolTipText = ""
$Button3.Top = 75
$Button3.Visible = "True"
$Button3.Width = 75
$Button3.OnClick = 'ExitButton_Click()'
;*************************************

; Create the second form that is used for
; the docked scenario

;********* FORM1 CREATE BEGIN **********
$Form1 = CreateObject('Kixtart.Form')
$Form1.BackColor = 212,208,200
$Form1.ControlBox = "True"
$Form1.DrawGrid = "True"
$Form1.FontBold = "False"
$Form1.FontItalic = "False"
$Form1.FontName = "Microsoft Sans Serif"
$Form1.FontSize = 8.25
$Form1.FontUnderline = "False"
$Form1.ForeColor = 0,0,0
$Form1.FormBorderStyle = 0
$Form1.Height = 1
$Form1.Left = 0
$Form1.MaximizeBox = "False"
$Form1.MinimizeBox = "False"
$Form1.SizeGripStyle = 0
$Form1.StartPosition = 4
$Form1.Tag = ""
$Form1.Text = ""
$Form1.Top = 0
$Form1.ToolTipText = ""
$Form1.TopMost = "False"
$Form1.Width = $ScreenWidth
$Form1.WindowState = 0
$Form1.Visible = 'False'
;********* FORM CREATE END **********

;************* BUTTON1a **************
$Button1a = $Form1.Controls.Button
$Button1a.Anchor = 5
$Button1a.TextAlign = 32
$Button1a.Enabled = "True"
$Button1a.FlatStyle = 2
$Button1a.FontBold = "False"
$Button1a.FontItalic = "False"
$Button1a.FontName = "Microsoft Sans Serif"
$Button1a.FontSize = 8.25
$Button1a.FontUnderline = "False"
$Button1a.ForeColor = 0,0,0
$Button1a.Height = 23
$Button1a.Left = $ScreenWidth - 100
$Button1a.TabStop = "True"
$Button1a.Tag = ""
$Button1a.Text = "UnDock"
$Button1a.ToolTipText = ""
$Button1a.Top = 5
$Button1a.Visible = "True"
$Button1a.Width = 75
$Button1a.OnClick = 'UnDockButton_Click()'
;*************************************

; Define our variables
; $Count = used in multiple places to
; provide a counting mechanism

; $rc = used anytime we want to pass
; a variable into a command  ex:
; $rc=execute('$checkbox'+$Count+'.enabled = true')
; where $Count is the variable being passed.
; if we do not do an execute the script will
; just look for $checkbox.$count (literal)
; instead of the varaible being passed.

; $File = the name of the text file that holds
; all of the netbios (or dns, ip, etc) of the servers
; that we wish to check against.

; $result = the value returned with the use of
; the $rc variable

; $serv = what is returned as we read the file
; that contains our test names.

;$Left = the left hand position passed to
; a form control

; $Top = the top position passed to a form
; control

; $ScreenWidth = the width of the clients
; screen resolution, passed to create the
; docked window

; $Selection = which checkbox did they check?

; $TestArray = the actual array that contains
; the names that we are going to test against

;************Declarations*************
Global $Count, $rc, $File, $result, $serv, $Left, $Top, $ScreenWidth
Global $Selection
Global $Testarray[]
$rc=setoption('novarsinstrings','on')
$ScreenWidth = $Form1.Screen.Width
;*************************************

$Form.Show
$Form.SetFocus
While $Form.Visible Or $Form1.Visible
  $=Execute($Form.DoEvents())
Loop
Exit 1

;*************************************
FUNCTION On_Click()

; Test to see if we have just unchecked a box
; If it is true that there had been a box checked
; prior to this, destory (.dispose) all of the labels
; that we created earlier.
; Reset all of the controls back to their basic configuration

   If UBound ($TestArray) >= 0
      For $Count = 1 to 6
         $rc=execute('$checkbox'+$Count+'.enabled = true')
      Next

      For Each $Element in $TestArray

;Actuall destruction of the labels.

         $rc=execute('$label'+$name+'.Dispose')
       $rc=execute('$labela'+$name+'.Dispose')
      Next

;Reset everything

      $Selection = ""
      Redim $TestArray[]
      $Form.Height = 150
      $button1.enabled = 'false'
     $button2.enabled = 'false'
      If $Timer => 0
         $Timer.Dispose
      Endif
   Else

; Since this a checking of a checkbox
; lets determine which checkbox they checked
; Since we know that there are exactly 6 checkboxes
; we can just quickly look at each one and check the
; status of it.

For $Count = 1 to 6
         $rc=execute('$result=$CheckBox'+$count+'.CheckState')
         If $result = 0
            $rc=execute('$CheckBox'+$Count+'.Enabled = False')
         Else

;Once we find the box that is checked set the $Selection so
; we can determine which file to go read

            If $result = 1
               $Selection = $Count
            EndIf
        EndIf
Next

; Now we read the $Selection and determine what file we are
; going to read for the server names.

; the script expects to find the file in the following
; format

; Name
; Name
; Name

; so on and so forth, nothing special, just a
; list of names (NetBios, DNS, IP etc).
;========================
;==                    ==
;== Change the file to ==
;== what works in your ==
;== enviroment         ==
;==                    ==
;========================

      Select
         Case $Selection = 1
            $File = 'anc.txt'

; Form Height is determined for each
; file by taking the base height of the form
; (in this case 150) and adding the number of
; rows that we are going to have + 50
; this is true in all cases for the form
; (not true for form1)

            $Form.Height = 200
      
         Case $Selection = 2
            $File = 'ser.txt'
            $Form.Height = 260
      
         Case $Selection = 3
            $File = 'scro.txt'
            $Form.Height = 350
        
         Case $Selection = 4
            $File = 'nro.txt'
            $Form.Height = 290
      
         Case $Selection = 5
            $File = 'co.txt'
            $Form.Height = 230
      
         Case $Selection = 6
            $File = 'all.txt'
            $Form.Height = 630
      
      EndSelect

; Here we open the file that we assigned if the step above

;========================
;==                    ==
;== Change the path to ==
;== what works in your ==
;== enviroment         ==
;==                    ==
;========================

      If Open (1, '\\%appservpri%\execs\kixstart\'+$File, 2) = 0
         $Count = 0

; Assign the $Serv to the line that we just read (only expecting
; there to be one entry per line so we don't have to do any special
; parsing of the file

         $Serv = ReadLine (1)
         While @Error = 0

; While we have not reached the end of the file
; Reset the $Testarray to have one more element than it
; it did just a moment ago, ensuring that we have
; saved all of the elements that were there to begin with

            Redim Preserve $TestArray[$count]

; Again since there are no special conditions
; within this file just put the data into the
; $Testarray

            $TestArray[$Count] = $Serv
            $Count = $Count + 1
            $Serv = ReadLine(1)

; Keep doing it till we reach the end of the file

         Loop

; Now we close the file since we are done with it.

         $null = Close (1)

; If we had a problem opening the file let the use know it.

      Else
         MessageBox('Unable to open server list file, please contact network administrator', 'Warning', 0, 90)
      EndIf
      For Each $Element in $TestArray

; Call the Function Build_Array

       Build_Array($Docked, $element)         
      Next
   EndIf

; Set variable's for the display of the
; the label array
; Turn on the Start button

$button1.enabled ='true'
$Left = 5
$Top = 150

; Call Function Display_Array

Display_Array ()

ENDFUNCTION
;*************************************

; Should be self explanatory

;*************************************
Function ExitButton_Click()
 Quit()
EndFunction
;*************************************

; The user has clicked the Start Button
; also known as button1

;*************************************
Function StartButton_Click ($TestArray)

; Turn on the Dock button

$Button2.enabled ='true'

; Turn off the Start button

$button1.enabled='false'

; Call function Test

Test ($TestArray)

; Set up a timer so that we aren't
; constantly running pings

$Timer = $Form.Controls.Timer

; Interval is set in milliseconds
;========================
;==                    ==
;== Change the interval==
;== towhat works in    ==
;== your enviroment    ==
;==                    ==
;========================
$Timer.Interval = 60000

; Once we reach the end of the time
; cycle run the Test fuction again

$Timer.Ontimer = 'Test ($TestArray)'

EndFunction
;*************************************

; The user has clicked on the Dock Button
; Also known as button2

;*************************************
Function DockButton_Click ()

; Set our variables so that we
; display the label array correctly

$Docked = 'True'
$Left = 5
$Top = 5

; Hide the first form

$Form.Visible = 'False'

; Turn on the docked form

$Form1.Visible = 'True'

; Set the form to always be on top

$Form1.TopMost = 'True'

; Set the form to be the width of the
; clients monitor resolution

$Form1.Width = $ScreenWidth

; Plase the form at the top
; of the screen

$Form1.Top = 0
$Form1.Left = 0

; Place the undock button
; also known as button1a

$Button1a.Left = $ScreenWidth - 100

; Call the function to display the
; the label array

Display_Array()

; Add 30 to the height of the form
; so that the bottom row of labels don't
; get cut off

$Form1.Height = $top +30
EndFunction
;*************************************

; User has clicked on the undock button
; also known as button1a

;*************************************
Function UnDockButton_Click ()

; Reset all of our label
; variables for a possible
; rebuild

$Docked = 'False'
$Left = 5
$Top = 150

; Turn on the main
; Form again

$Form.Visible = 'True'

; Turn off the docked version
; of the form

$Form1.Visible = 'False'

; Make sure the start button is turned off

$Button1.Enabled = 'False'
EndFunction
;*************************************

; Here we are actually going to do something
; other than build forms.

;*************************************

Function Test ($TestArray)

For Each $Element in $TestArray

; Change the background of the label
; to yellow so that the user knows
; that we are doing something

$rc=execute('$Label'+$Name+'.BackColor = Yellow')
$rc=execute('$Labela'+$Name+'.BackColor = Yellow')

; Now we actually ping the server that we
; got from the $testarray, and look for the
; "TTL" so show that it responded

Shell 'CMD.EXE /c PING '+$Element+' -n 2 | find /i "TTL" >nul'
  If @error = 0

; If it found the TTL in the response then change
; the background to green to show a positive
; response

    $rc=execute('$Label'+$Name+'.BackColor = Green')
   $rc=execute('$Labela'+$Name+'.BackColor = Green')
  Else

; Otherwise turn the background Red so that the user
; can know immediatly to check it out.

    $rc=execute('$Label'+$Name+'.BackColor = Red')
    $rc=execute('$Labela'+$Name+'.BackColor = Red')
  EndIf

; Look to see if the user has clicked
; on anything

  $=Execute($Form.DoEvents(1))
Next

EndFunction

;*************************************

; Here we actually build the Array of
; labels that the user sees.
; This script builds both array's at
; the same time, and both are active
; just that one is hidden as seen above
; there is probably better way's to do this
; but I haven't figured it out as of yet.

;*************************************
Function Build_Array($Docked, $Element)

       $rc=execute('$Label'+$Name+' = $Form.Controls.Label')
         $rc=execute('$Label'+$Name+'.BackColor = 0,0,0')
         $rc=execute('$Label'+$Name+'.ForeColor = 255,255,255')
         $rc=execute('$Label'+$Name+'.Alignment = 2')
         $rc=execute('$Label'+$Name+'.Width = 80')
         $rc=execute('$Label'+$Name+'.Height = 22')
         $rc=execute('$Label'+$Name+'.Text = $Element')

       $rc=execute('$Labela'+$Name+' = $Form1.Controls.Label')
         $rc=execute('$Labela'+$Name+'.BackColor = 0,0,0')
         $rc=execute('$Labela'+$Name+'.ForeColor = 255,255,255')
         $rc=execute('$Labela'+$Name+'.Alignment = 2')
         $rc=execute('$Labela'+$Name+'.Width = 80')
         $rc=execute('$Labela'+$Name+'.Height = 22')
         $rc=execute('$Labela'+$Name+'.Text = $Element')

EndFunction
;*************************************

; Here we actually place the labels within
; the form.
; the labels for $Form were fairly strait
; forward as it is a fixed window width.
; However since in the docked configuration
; the screen could be different sizes, I had
; to do some extra math to make it work.

;*************************************
Function Display_Array
For Each $Element in $TestArray

; Here we check to see if the $Form1
; is the active form

       If $Docked = 'True'

; If it is then we build the form accordingly

   $rc=execute('$Labela'+$Name+'.top = '+$Top)
   $rc=execute('$Labela'+$Name+'.left = '+$Left)

; Here we make sure that there is room for the
; undock button (button1a)

      If $top = 5
          If $left < ($ScreenWidth - 280)
           $Left = $Left + 90
          Else $Left = 5
             $Top = $Top + 30
          EndIf
        Else

; Otherwise we use as much of the screen
; as we can
         If $left < ($ScreenWidth - 100)
          $Left = $Left + 90
         Else $Left = 5
             $Top = $Top + 30
         EndIf
        EndIf
       Else

; Otherwise we know that the form will look like
; this.

   $rc=execute('$Label'+$Name+'.top = '+$Top)
   $rc=execute('$Label'+$Name+'.left = '+$Left)
        If $Left < 364
          $Left = $Left + 90
        Else
          $Left = 5
            $Top = $Top + 30
        EndIf
     EndIf
Next
EndFunction
;*************************************      

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Tue Jan 20, 2004 11:58 pm    Post subject: About the above code Reply with quote

I am sure that there are many things that I could clean up on my code, and I would love to hear what they are as I am still fairly new at this.

Thanks for everyone's help up to this point. Cool

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Mon Jan 26, 2004 1:08 pm    Post subject: Reply with quote

Gargoyle,

just a short observation in your ping command:

Code:
Shell 'CMD.EXE /c PING '+$Element+' -n 2 | find /i "TTL" >nul'


should be replaced by :


Code:
Shell '%ComSpec% /c PING '+$Element+' -n 2 | find /i "TTL=" >nul'


%ComSpec% - to enable w9x users making use of this Wink
"TTL=" - to keep the results accurate, just thinking of one possible reply:

Reply from ip-address: TTL expired in transit .

Will take a closer look at the rest of the script when I find some time Tired

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Jan 26, 2004 1:27 pm    Post subject: Reply with quote

I LOVE the docking feature, haven't seen anybody do that with forms yet !!!

Suggestions - might want to "soften-up" your hardcoded references to your server share (containing all.txt, etc) ... maybe put at top of script.

Can't help but think a ListView would be nice to list all the servers being monitored ... not sure how that would workout in the docked view though.

I created a sml all.txt file containing hostnames, but I see that some of the monitoring controls are not positioned properly ... not sure if im doing something wrong, just have an all.txt like this:

---all.txt---
hostname1
hostname2
hostname3
------------

Will investigate more. Want to make sure nothing is broke in the new version.

-Shawn

Did I say that I loved that docking thingy !
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Mon Jan 26, 2004 9:48 pm    Post subject: Reply with quote

Is it not building the labels in the undocked mode or the docked mode?
_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Mon Jan 26, 2004 10:15 pm    Post subject: Reply with quote

You could also put everything into a .INI file. This way, you can still keep your geographic regions.

Also, can we please include the KiXforms version used to build the script when posting a script.

_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Tue Jan 27, 2004 12:40 am    Post subject: Suggestions Reply with quote

Like I said I am a newbie at this, this is only my 3 KixForm, and my 4th script with KixStart....

I will learn as I go with all of your help.

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Tue Jan 27, 2004 3:07 pm    Post subject: Reply with quote

Still, which KiXforms version did you use as the script errors out for me on line $CheckBox1 = $Form.Controls.CheckBox with an 'unknown command' error.

Darn, had .37 running instead of .42

Still, much room for improvement, e.g. automatic setting of form size based on number of servers moitored, .INI file instead of flat text file, no hardcoding of paths but reading from same directory where script is located.

_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Tue Jan 27, 2004 9:11 pm    Post subject: INI Files Reply with quote

I am unsure of how to write the INI file, suggestions or places to go read ...

As for the automatic sizing of the form, I would love to know how to do that (I assume that it would work something like I did with the "Docked" situation).

Again I am very new to this and will take all the help and criticsim that you have.


Thanks

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Tue Jan 27, 2004 10:02 pm    Post subject: Reply with quote

Read the KiXtart Manual under READPROFILESTRING and create a .INI file like this:
Code:

[Anchorage]
Server1=Windows 2000 Server
Server2=Windows Server2003
[Duluth]
Server1=Windows Server2003
Server2=Windows Server2003


Also, you say that you have to add 50 pixels for each monitored server somewhere in your code, but you DO know the number of servers monitored, anyway. So, this can be done automatically.

_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Tue Jan 27, 2004 10:29 pm    Post subject: Reply with quote

So you are saying that I should replace all of my .txt files with a single INI file that could be read instead?

As for the automatic sizing of forms, I am specifiying in the first form what the height is because I know the width of the form, for the second form (form1) I do not know the width of the form and thereby have to dynamically create the height each time.

Or am I totally missing the point?

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Tue Jan 27, 2004 10:40 pm    Post subject: Reply with quote

Yes, that's what I mean. I don't like making changes in code just because I add another server to it.

Also,
Code:

      Select
         Case $Selection = 1
            $File = 'anc.txt'

; Form Height is determined for each
; file by taking the base height of the form
; (in this case 150) and adding the number of
; rows that we are going to have + 50
; this is true in all cases for the form
; (not true for form1)

            $Form.Height = 200
       
hardcodes the height for anc.txt to 200, which means that there's one server in anc.txt. However, you do read the number of servers in anc.txt, thus you could dynamically calculate the height based on the content fo the file.
_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Tue Jan 27, 2004 10:55 pm    Post subject: The light bulb comes on Reply with quote

I finally get it. When I build $Form I should use a dynamic $Form.Height, just as I do when I build $Form1

I see how easy it would be to change and what a difference it could make for future additions or subtractions of servers.


Like this....
Code:
Display_Array()

; Add 30 to the height of the form
; so that the bottom row of labels don't
; get cut off

$Form.Height = $top +30
EndFunction
;*************************************


And then remove all refrences to $Form.Height = from the Select Case.


Any suggestions on how I can handle a form resize? In particular what event would I be looking for? I could then code it so that the same form is used for both docked and undocked.

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Wed Jan 28, 2004 1:16 pm    Post subject: Reply with quote

The .Refresh method will force a form redraw.
_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group