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

Problems with the stock ticker

Recommended Posts

valdezdj    0

I read the blog on the stock ticker and thought I would try to create some kind of scrolling text. But when I added a few different things, there would be at times where nothing would show up and other times when the first three letters would show but then just stop. Anyways here's my script and please help.

Add-PSSnapin PowergadgetsAdd-PSSnapin PrimalToys#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 = Read-InputBox -message "Put something here." -defaultvalue "" -Title "Ticker Message" #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|out-gauge -type digital -floating -topmost -Appearance_OffDigitTransparency 0 -Appearance_Color Black -Style 3 -Appearance_Style SevenSegments05 -Border_InsideColor WhiteThanks in advance and I'm using PrimalScript Pro for all my scripting.

Share this post


Link to post
Share on other sites
marco.shaw    0

Interesting use of my blog post.  I don't have time right now to provide you with a working/tested solution, but I see some fundamental issues with variables and how PowerGadgets with refresh works:

1.  You didn't declare a -refresh parameter in your out-gauge call.2.  You cannot use out-gauge in this manner to use it to refresh.3.  When you do actually use -refresh, a couple of problems will happen:  a)  You are declaring a *local* or *script* variable when you simply declare "$string=read-inputbox...".  :D  When using -refresh, your first invokation of the .ps1 script runs in the current PowerShell runspace/console, but on the 2nd (and forever after) invokation of the script, it is actually run from another "detached" PowerShell runspace.  This new detached runspace starts from scratch and will try to run "$string=read-inputbox..." again by itself, but won't be able to send anything to you because it can't talk to the console.4. I also mention in the blog post about seeing strange things when the ticker is first called (having to reset global variables to zero manually).

So, the important thing that I think will be required is that when the script is first called, it will have to write the string to a temporary file, and then the new PowerShell runspace will read the file, store its contents in a *global* variable, then delete the temporary file.

Something for you to think about...  I'll provide you with something that works by Tuesday, if you need help.

[Edit: Added point #4.]

post-3268-13922403391781_thumb.jpg

Share this post


Link to post
Share on other sites
marco.shaw    0

OK, here's "version 2".  Instead of using read-inputbox from Sapien, I just used read-host which is built-in with PowerShell.  You may want to modify "test.tmp" to a name/location more appropriate.  This is a temporary file only, that will be created, then deleted.

-------scrollv2.ps1------------

$global:value=7$spacer=" "*7

if (test-path test.tmp) {  $global:string=get-content test.tmp;remove-item test.tmp} else {  if ($global:string -eq $null) {   read-host "Enter the text to scroll"|out-file -filepath test.tmp -encoding ascii   $global:string=get-content test.tmp  }}

$scrollString=$spacer+$global:string+$spacer$scrollText=$scrollString.Substring($global:iteration,$global:value)

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

$scrollText

------------

Sorry, no code comments this time around...  Let me know if that does the trick for you.

[Edit: Added a prompt to the read-host cmdlet.]

Share this post


Link to post
Share on other sites
valdezdj    0

Marco,Yeah I took out the refresh because it kept prompting me for an input box for however many seconds or minutes I set it to. Also, I wanted to put a input box for our staff to run the gadget and enter text based on present events. I don't really need it to refresh because, i.e., whenever we have an outage, we want to put in text to scroll for staff to see it. We have a large LCD TV setup so staff can see what's going on at that time. Thanks for the help I haven't tried using your last script that you just posted but I just wanted to reply back to your first post. Thanks for the help.

valdezdj

Share this post


Link to post
Share on other sites
marco.shaw    0

Marco,

Yeah I took out the refresh because it kept prompting me for an input box for however many seconds or minutes I set it to. Also, I wanted to put a input box for our staff to run the gadget and enter text based on present events. I don't really need it to refresh because, i.e., whenever we have an outage, we want to put in text to scroll for staff to see it. We have a large LCD TV setup so staff can see what's going on at that time. Thanks for the help I haven't tried using your last script that you just posted but I just wanted to reply back to your first post. Thanks for the help.

valdezdj

Sorry, I'm not fully following you.  You mention not needing it to refresh, but you must have it refresh for the text to appear to scroll.  That's how I create the illusion.

I'm also going to add my flash code with the scrolling code...  That might be useful in your scnenario where you just put up a new message: it will first scroll when something new is added, then start to scroll...  You'd have to kill/quit the gadgets, then restart the .ps1 script.  Is that acceptable, or you'd want something more automatic like that.  Being able to start a gadget, have it run *forever*, but have the text be variable all the time could have some issues.

I hope I'm making myself clear...

ZoomIssue.zip

Share this post


Link to post
Share on other sites
valdezdj    0

Still nothing, I'm getting the same results as my original script. Its just a blank gadget with nothing there. Am I supposed to get an input box or something??? How does it know what I want to scroll? Sorry taking so much of your time, thanks for the help.

Share this post


Link to post
Share on other sites
marco.shaw    0

How exactly are you trying to run it?  My way actually prompts you in the PowerShell console.  I've slightly edited my previous post to show the prompt in the PowerShell session.  I could also edit it for use with read-inputbox...

Share this post


Link to post
Share on other sites
valdezdj    0

Sorry took me so long to reply, I've been working on other things. I did run it in the Powershell console and I put in the text but it still doesn't show anything at all. I mean if you want to edit your script to work with read-inputbox, that would be nice but whatever you want to do. I'm just glad your helping me out to this extent. The read-inputbox is just alittle fancier than the Powershell console and its more user friendly.

Thanks,D

Share this post


Link to post
Share on other sites
marco.shaw    0

OK, maybe this is the problem...

You have to call it like this, for example:

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

I have an idea on how I can get the $global variables to reset properly to zero (see note in the comments to my first version).

I have to leave right now.  Using read-inputbox will be simple to implement...

Share this post


Link to post
Share on other sites
marco.shaw    0

To use Sapien's read-inputbox, simply replace this code from my scrollv2.ps1:

read-host "Enter the text to scroll"

And replace with:

Read-InputBox -message "Put something here." -defaultvalue "" -Title "Ticker Message"

As simple as that...

Share this post


Link to post
Share on other sites
valdezdj    0

Ok...Finally!!! I found out why there was nothing being displayed when I ran the script. It's because for some reason PowerGadgets will not display text in a SevenSegments style. I had to go into the creator and copy and paste my script and it was showing up. But when I changed it to SevenSegments(its FourteenSegments by default) nothing was showing up. So there you go, just one of those things that drives you crazy when you can't figure it out. So anyways you can use fourteensegments or LED whichever you decide. One more question is there any way to set a speed for the ticker? If not don't worry about it just thought. Thanks for all your help!

Share this post


Link to post
Share on other sites
marco.shaw    0

Speed?  You want slower or faster?  For slower, just increase the -refresh value from 0:0:01 to something higher.  To make it faster...  Well, out-gauge -refresh doesn't seem to accept milliseconds.  Another way would be to make it scroll 2 characters at a time, but the appearance would be "jerky-ish"...

post-2775-13922403397488_thumb.jpg

Share this post


Link to post
Share on other sites
marco.shaw    0

Speed?  You want slower or faster?  For slower, just increase the -refresh value from 0:0:01 to something higher.  To make it faster...  Well, out-gauge -refresh doesn't seem to accept milliseconds.  Another way would be to make it scroll 2 characters at a time, but the appearance would be "jerky-ish"...

I was wrong, -refresh does accept milliseconds: -refresh 0:0:0.1 (for 100 milliseconds).  That will make the scolling go much faster.  So a 1/2 second refresh would be "-refresh 0:0:0.5" (seems anything missing is automatically filled in).

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  

×