Jump to content
Software FX Community
Sign in to follow this  
MarcoS

[Guest Blogger] Creating a stock ticker with out-gauge

Recommended Posts

One thing I asked for recently on the community forums was a stock ticker gadget.  It just sounded like something interesting to have in my toolbox.

After some thought after a recent long flight, I thought of an easy way this could be done.  I just needed to create a string of text, and figure out how to make it appear to move.  One easy way was using the Substring() method of the System.String class.

The code is pretty easy once you think about it, which you should be able to just copy and paste into your favorite PowerShell editor (mine is Notepad):

---------start scroll.ps1---------

#We setup a global variable here.  Global because we are going to use the -refresh parameter
#and need the variable to be available in the new PowerShell runspace created.

#The value is 7 in this case simply because this is how many characters we want to see on the
#screen in this case.

$global:scrollValue=7

#To save some typing, we create a couple of local variables also.

$spacer=" "*7
$string="this is a test of powergadgets"

#We create are complete string.  The "spacer" is used so the text appears to start from
#nowhere after a short pause.

$scrollString=$spacer+$string+$spacer

#Here we get the section of string that we want to show on the screen during the current iteration.

$scrollText=$scrollString.Substring($global:scroll_iteration,$global:scrollValue)

#On each run, we increment the global iteration variable so we move along the string.
#We also reset the global iteration value to zero, so the scroll goes on indefinitely.

if ($global:scroll_iteration -lt $scrollString.length-$global:scrollValue) {
  $global:scroll_iteration++
  } else {
  $global:scroll_iteration=0
}

#The final text outputted.

$scrollText

---------stop scroll.ps1---------

So once you have the script saved, you can call it like so:

PSH>./scroll.ps1|out-gauge -type digital -refresh 0:0:01 -floating -topmost

Note, if you see some text appear, then it appears the gadget resets itself, and then seems to run OK, the script sets some global variables, and that will affect anything using those particular variables in any scope in your current PowerShell session.  You may need to do something like this in your PowerShell session to reset the global variables:

PSH>$scroll_iteration=0;$scrollValue=0

I hope you like this little addition.  I will be blogging about a traffic light I created soon.

[Edit: September 14th, 2007, by Marco Shaw: See this forum thread for more information on different things that can be done with the stock ticker.  There's also a "version 2" posted there.]

Share this post


Link to post
Share on other sites
Sign in to follow this  

×
×
  • Create New...