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

.net progress bars and breaking out of loops.

 
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic
View previous topic :: View next topic  
Author Message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Tue Aug 12, 2008 4:22 pm    Post subject: .net progress bars and breaking out of loops. Reply with quote

I am trying to use a progress bar in association with a timeout to check by PING whether a TARGET machine is present. I have tried a variety of combinations but it is the progress bar which seems to be the sticking point.
Would someone please point out A} why I get a blank bar whichever incramental form I use and b} how to trap an Esc if I need to....
Code:

BREAK ON
$system = CreateObject("Kixforms.System")
IF NOT $system
 $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
 QUIT()
ENDIF
;Call this to determine if Target is present
Global $Timeout
$Timeout=20 ;seconds
$Target='myserver.inter.net'
$=PingIt($TARGET,$Timeout)
beep
;rest of script...

 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Function PingIT($TARGET,$Timeout)
 Dim $Query,$oWMI,$oItem,$cItems,$wmiPing
 $=progress()

 $Query = "Select ResponseTime,StatusCode From Win32_PingStatus Where Address='" + $TARGET + "'"
 $oWMI = GetObject("winmgmts:root\cimv2")
 While $Active=0
 $cItems = $oWMI.ExecQuery($Query)
 For Each $oItem In $cItems
  If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
   $Active = "0"
  Else
   $Active = "1"
  EndIf
 Next
 Loop

 $progressform.close
 $progressform.dispose
 $Timer1.stop
 $Timer1.dispose
 EndFunction
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 FUNCTION Progress()
  $Timer1 = $System.Timer()
  $Timer1.Interval=1000
  $Timer1.Tick='PerformStep()'
  $Timer1.start

  $progressform = $system.form()
  $progressform.backcolor = $system.color.fromname("ControlLightLight")
  $progressform.font = $system.font("Tahoma",9,1) ;Bold
  $progressform.maximizebox = 0  ;False
  $progressform.minimizebox = 0  ;False
  $progressform.showintaskbar = 0  ;False
  $progressform.size = $system.size(200,40) ;(Width,Height)
  $progressform.startposition = 1  ;FormStartPosition_CenterScreen
  $progressform.controlbox = 0  ;False
  $progressform.Topmost=1
  $progressform.KeyPress = 'ProgItemKey("progressform")'

  $progressbar1 = $system.progressbar()
  $progressbar1.backcolor = $system.color.fromname("ControlLightLight")
  $progressbar1.dock = $system.dockstyle_fill
  $progressbar1.Step=1
  $progressbar1.Minimum=0
  $progressbar1.Maximum=$Timeout
  $progressbar1.KeyPress = 'ProgItemKey("progressbar1")'
  $ = $progressform.controls.add($progressbar1)
  $progressform.show
 ENDFUNCTION
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 FUNCTION ProgItemKey($Form)
 Dim $key
 $Form="$"+$Form
 $ = execute("$$key = $Form.KeyPressEventArgs.KeyChar")
 if $key= chr(27);Esc
  $progressform.close
  $progressform.dispose
  $Timer1.stop
  $Timer1.dispose
 ENDSELECT
 ENDFUNCTION

________
Apple Games


Last edited by MACE1 on Fri Feb 18, 2011 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
Mart
KiXforms Regular
KiXforms Regular


Joined: 03 Oct 2005
Posts: 57
Location: Rotterdam - Netherlands

PostPosted: Wed Aug 13, 2008 7:47 am    Post subject: Reply with quote

Shouldn’t the last EndSelect be an Endif?
_________________
Mart

- He's chained forever to a world that's departed.....It's not enough, it's not enough - Sorrow by Pink Floyd.
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Wed Aug 13, 2008 8:09 am    Post subject: Reply with quote

Confused That was a typo on the post, not the actual issue. Corrected makes no difference.
I am missing something on the 'progress' sheme which I have insufficient experience to detect.
________
FREE THEMES


Last edited by MACE1 on Fri Feb 18, 2011 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Thu Aug 14, 2008 11:46 am    Post subject: IT WAS THE TIMER !!! Reply with quote

For a reason which escapes me, the TIMER was not working hence no progress.
Although less accurate, if I simply put the progress call within the ping loop it works - So now need to understand WHY the timer is kaput !

Also I can't get the 'Esc' breakout to activate : HELPPP

Code:

BREAK ON
$system = CreateObject("Kixforms.System")
IF NOT $system
 $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
 QUIT()
ENDIF

;Call this to determine if Target is present
$Timeout=30 ;seconds
$Step=1 ;seconds
$Target='my.inter.net'

$=PingIt($TARGET,$Timeout,$Step)
;rest of script...

 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Function PingIT($TARGET,$Timeout,$Step)
 Dim $Query,$oWMI,$oItem,$cItems,$wmiPing,$Count
 $=progress($Timeout,$Step)
 $Query = "Select ResponseTime,StatusCode From Win32_PingStatus Where Address='" + $TARGET + "'"
 $oWMI = GetObject("winmgmts:root\cimv2")

 While $Active=0 and $Count < $Timeout
 $cItems = $oWMI.ExecQuery($Query)
 For Each $oItem In $cItems
  If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
   $Active = "0"
  Else
   $Active = "1"
  EndIf
 Next
  $Count=$Count+1
  $=ProgressStep($Timeout,$Step)
 Loop
 $progressform.close
 $progressform.dispose
; $Timer1.stop
; $Timer1.dispose
 EndFunction
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 FUNCTION Progress($Timeout,$Step)
;  $Timer = $System.Timer()
;  $Timer.Interval=1000
;  $Timer.Tick='ProgressStep($Timeout,$Step)'

  $progressform = $system.form()
  $progressform.backcolor = $system.color.fromname("ControlLightLight")
  $progressform.font = $system.font("Tahoma",9,1) ;Bold
  $progressform.maximizebox = 0  ;False
  $progressform.minimizebox = 0  ;False
  $progressform.showintaskbar = 0  ;False
  $progressform.size = $system.size(200,40) ;(Width,Height)
  $progressform.startposition = 1  ;FormStartPosition_CenterScreen
  $progressform.controlbox = 0  ;False
  $progressform.Topmost=1
  $progressform.KeyPress = 'ProgItemKey("progressform")'

  $progressbar1 = $system.progressbar()
  $progressbar1.backcolor = $system.color.fromname("ControlLightLight")
  $progressbar1.dock = $system.dockstyle_fill
  $progressbar1.Style=2
  $progressbar1.Visible = "True"
  $progressbar1.Step=$Step
  $progressbar1.Minimum=0
  $progressbar1.Maximum=$Timeout
  $progressbar1.KeyPress = 'ProgItemKey("progressbar1")'
  $ = $progressform.controls.add($progressbar1)

  $progressform.show
;  $Timer.start
 ENDFUNCTION
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Function ProgressStep($Timeout,$Step)
  If $ProgressBar1.value < $Timeout
   $ProgressBar1.value=$ProgressBar1.value+$Step
  Else
   $ProgressBar1.value=0
  Endif
 EndFunction
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 FUNCTION ProgItemKey($Form)
 Dim $key
 $Form="$"+$Form
 $ = execute("$$key = $Form.KeyPressEventArgs.KeyChar")
 if $key= chr(27);Esc
  $progressform.close
  $progressform.dispose
  $Timer1.stop
  $Timer1.dispose
 ENDIF
 ENDFUNCTION

________
ROOR BONG


Last edited by MACE1 on Fri Feb 18, 2011 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Wed Aug 27, 2008 9:36 am    Post subject: Reworked the Timer but Still not triggering - HELP Reply with quote

Rolling Eyes
The timer event is not firing and I really don't see why - Can anyone spot the issue ??
Code:

 ;SETCONSOLE("HIDE")
 BREAK ON
 $system = CreateObject("Kixforms.System")
 IF NOT $system
  $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
  QUIT()
 ENDIF

 $=pingit('10.10.10.10',45,1)
 $Clock.Stop
 $Clock.dispose
? "PRESS A KEY"
get $
quit()
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Function PingIT($TARGET,$Timeout,$Step)
 Dim $Query,$oWMI,$oItem,$cItems,$wmiPing,$Count
 $=progress($TARGET,$Timeout,$Step)
 $Query = "Select ResponseTime,StatusCode From Win32_PingStatus Where Address='" + $TARGET + "'"
 $oWMI = GetObject("winmgmts:root\cimv2")

 While $Active=0 and $Count < $Timeout
/*
 $cItems = $oWMI.ExecQuery($Query)
 For Each $oItem In $cItems
 $=Execute($progressform.doevents(0))
  If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
   $Active = "0"
  Else
   $Active = "1"
  EndIf
 Next
*/
sleep 1
  $Count=$Count+1
 Loop
 $progressform.close
 $progressform.dispose
 EndFunction
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 FUNCTION Progress($Target,$Timeout,$Step)
  $Clock=$System.timer()
  $Clock.Tick='ProgressStep($TARGET,$Timeout,$Step)'
  $Clock.Interval=1000/$Step
  $Clock.Enabled='True'
  $Clock.Start

  $progressform = $system.form()
  $progressform.backcolor = $system.color.fromname("ControlLightLight")
  $progressform.font = $system.font("Tahoma",9,1) ;Bold
  $progressform.maximizebox = 0  ;False
  $progressform.minimizebox = 0  ;False
  $progressform.showintaskbar = 0  ;False
  $progressform.size = $system.size(200,60) ;(Width,Height)
  $progressform.startposition = 1  ;FormStartPosition_CenterScreen
  $progressform.controlbox = 0  ;False
  $progressform.Topmost=1
  $progressform.Text='Pinging: '+$TARGET
  $progressform.KeyPress = 'ProgItemKey("progressform")'

  $progressbar1 = $system.progressbar()
  $progressbar1.backcolor = $system.color.fromname("ControlLightLight")
  $progressbar1.dock = $system.dockstyle_fill
  $progressbar1.Style=2
  $progressbar1.Visible = "True"
  $progressbar1.Step=$Step
  $progressbar1.Minimum=0
  $progressbar1.Maximum=$Timeout
  $progressbar1.KeyPress = 'ProgItemKey("progressbar1")'
  $ = $progressform.controls.add($progressbar1)

  $progressform.show
 ENDFUNCTION
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Function ProgressStep($TARGET,$Timeout,$Step)
 $=Execute($progressform.doevents(0))
 If $progressform.visible
  If $ProgressBar1.value < $Timeout
   $ProgressBar1.value=$ProgressBar1.value+$Step
  Else
   $ProgressBar1.value=0
  Endif
  $progressform.text='Pinging: '+$TARGET+' ~ '+$ProgressBar1.value
 Endif
 EndFunction
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 FUNCTION ProgItemKey($Form)
 Dim $key
 $Form="$"+$Form
 $ = execute("$$key = $Form.KeyPressEventArgs.KeyChar")
 if $key= chr(27);Esc
  ? "ESCAPED"
  $progressform.close
  $progressform.dispose
  $Clock.Enabled='False'
 ENDIF
 ENDFUNCTION
 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

________
MERCEDES-BENZ 300 SLR SPECIFICATIONS


Last edited by MACE1 on Fri Feb 18, 2011 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Wed Aug 27, 2008 2:25 pm    Post subject: Reply with quote

Before i dig into your code, i need to understand exactly what and how you want to accomplish it,

example,... i want a timer to kick off and in between every tick i want it to try to ping a machine until it reaches it.

or,... i want to kick off a timer and wait until it times out before it pings the machine.

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Wed Aug 27, 2008 2:40 pm    Post subject: Reply with quote

Very Happy
I want an independant timer to incrament the progress bar as a clock, regardless of any other function going on.
In this particular case I happen to be using ping, but rather than incramenting the progress bar between pings, which I currently have working, I am trying to make the timer work on its own irrespective of the ping timing etc.
I can invoke the progress bar OK but I can't see why the timer is not incramenting it !
I was also trying to trap an Esc key press in case I choose to abandon progress / main ping function.
________
No2 Vaporizer Reviews


Last edited by MACE1 on Fri Feb 18, 2011 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Wed Aug 27, 2008 2:47 pm    Post subject: Reply with quote

so, you want it to continue to ping the machine over and over, at the same time you want the progress bar to count up and reset and count up and reset until you cancel the entire process with the 'esc' key?
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Wed Aug 27, 2008 3:03 pm    Post subject: Reply with quote

YES until the ping gets a response or times out in which case the timer and progress bar are closed automatically anyway.

To put it in context for you, this scriptlet is called when remoting to systems via a VPN which on initial connection can take 15 to 60+ seconds before dns will resolve remote system names. Rather than keep trying and failing to make a RDP connection or waiting an arbitary period before trying, I inserted the ping function to wait for a response before invoking RDP. It works well now, but the timer would make it far less 'jumpy' when pinging.
________
FAMILY 1 ENGINE


Last edited by MACE1 on Fri Feb 18, 2011 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Wed Aug 27, 2008 4:46 pm    Post subject: Reply with quote

I don't think that it possable to do what you are wanting, kixforms can only do one thing at a time, and that creates a problem for what you are asking, you can not have a ping happening and at the same time ask the progress bar to change, i don't think that its a timer problem because it continues to tick but you cant ask it to kick off a process if it is already busy doing something else.
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Wed Aug 27, 2008 5:18 pm    Post subject: Reply with quote

Idea
Understand the logic, so I would then need to abandon the timer and try and get a more frequent update during PING.
How about:
Code:

 Function PingIT($TARGET,$Timeout,$Step)
 Dim $Query,$oWMI,$oItem,$cItems,$wmiPing,$Count
 $=progress($Target,$Timeout,$Step)
 $Query = "Select ResponseTime,StatusCode From Win32_PingStatus Where Address='" + $TARGET + "'"
 $oWMI = GetObject("winmgmts:root\cimv2")
 $PingIT=0
 While $Active=0 and $Count < $Timeout
 $cItems = $oWMI.ExecQuery($Query)
 For Each $oItem In $cItems
  $=Execute($progressform.doevents(0))
  If (VarTypeName($oItem.StatusCode) = 'Null') Or $oItem.StatusCode
   $Active = "0"
  Else
   $Active = "1"
   $PingIT=1
  EndIf
 Next
  $Count=$Count+1
  $=ProgressStep($Target,$Timeout,$Step)
 Loop
 $progressform.close
 $progressform.dispose
 EndFunction


Would that make the KEY scan quicker ?
________
OXYGEN VAPORIZER


Last edited by MACE1 on Fri Feb 18, 2011 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Wed Aug 27, 2008 5:38 pm    Post subject: Reply with quote

i think you have the right idea, the quickness of the keyscan will be directly connected to the number of things you ask it to do before it checks for a keypress over and over.
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic 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