
-----------------------------------
Lapsus Antepedis
Tue Jul 05, 2005 3:47 am

Scrolling title
-----------------------------------
Yet another early-morning program from Lapsus!
This process (sorry Delos!) scrolls a string across
the title bar of the program run window thanks to
some string manipulation! It actually looks pretty
cool, and it also scrolls while in the startbar. I 
just need how to turn it off to change the title string
if needed.

Thoughts? Comments?


process titlescroll (title : string, display, del : int)

    % 'title' is the string that will be scrolled in the titlebar
    % 'display' is the number of characters that will be shown at once
    % 'del' Is the delay between updates to the titlebar

    const header : string := "title:"
    var thing : string := ""
    for i : 1 .. display
        thing += ' '
    end for
    thing += title
    for i : 1 .. display
        thing += ' '
    end for
    var titlestring : string
    titlestring := header
    loop
        for i : 1 .. length (thing) - display
            titlestring := header
            for ii : 0 .. display - 1
                titlestring += thing (i + ii)
            end for
            View.Set (titlestring)
            delay (del)
        end for
    end loop
end titlescroll

fork titlescroll ("Yes it was necessary to make this into a process seeing as the rest of the program would not run otherwise!", 20, 100)

put "This title scrolling program was written by Lapsus Antepedis in 2005"
put "Feel free to use this code in your programs as long as you give credit"
put "I always seem to do my best programming around 3 in the morning..."

-----------------------------------
Cervantes
Tue Jul 05, 2005 8:31 am


-----------------------------------
Intriguing.  I've tried to run your code four times, but every time I get the "The environment (not your program) has crashed!" error.  Yet, it seems to be your program that's causing the trouble, since my other programs work.  :think:

*A minute later*
I was wondering why you didn't have any drawing commands.  Then I realized you were adjusting the title bar.  I added the "title:" +  before the titlestring and it now works fine.  
View.Set ("title:" + titlestring)

*A while later*
Now I'm really confused, because titlestring starts with "title:".  And yet, when I changed the View.Set it worked as it should.  When I left it alone, I discovered that just before the View.Set line titlestring has a value of "title:".  Nothing more.  Opening a new Turing window and running the following causes the Turing to crash in the same manner.

View.Set ("title:")

I don't know why titlestring's value is merely "title:" however.  It's not as though that second for loop

            for ii : 0 .. display - 1
                titlestring += thing (i + ii)
            end for

will not execute.  display - 1 is 19, which is definately bigger than 0.  So that should run.

*A small amount of time later*
Oh.  It adds to the titlestring variable, but it adds spaces.

View.Set ("title:                                 ")

That still causes the program to crash.  It seems you need to have at least some title at any given time.  You'll need to modify the code such that there's always at least one character in the title at any time.

Here's my modification.  I've changed it into procedure format, though it now relies on the existance of a global variable called starting_character.  :(  On the plus side, it's been shortened to eleven lines.

var starting_character := 0
procedure titlescroll (title : string, display : int)
    var full_title := repeat (" ", display) + title
    if starting_character < length (full_title) then
        starting_character += 1
    else
        starting_character := 1
    end if
    if starting_character 