Results 1 to 3 of 3

Thread: Text Scroll

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Location
    Edmonton,AB,Canada
    Posts
    28

    Post

    I would like some help to create a text scroll in the background of a form. I want to have it constanly loop without getting trapped in a traditional loop where the users computer gets trapped in an endless loop. Any ideas?

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Post Re: Text Scroll

    Use a timer control.
    Example:

    Put a Timer and a Picturebox with a Label inside it on a window.
    Set Label1's caption to "Example Text Scroller for hlieu"
    Set Timer1.Interval = 200
    Code:
    Private Sub Timer1_Timer()
        Label1.Left = Label1.Left - 105
        If Label1.Left < (Label1.Width * -1) then Label1.Left = Picture1.Width
    End Sub
    This will not cause an endless loop

    r0ach™
    Don't forget to rate the post

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Post

    Here's another way, without using a picture box.

    Create a form, strech a label across it and keep the default name, Label1. Make sure you change the Alignment property to "1 - Right Justify" to scroll from right to left. Add a timer and set the interval to 50 to start with (this will control the speed of scrolling). Again, keep the default name Timer1.

    Now paste this code into the form's code window and run the project:

    Code:
    Option Explicit
    
    Private sMsg As String                  'Holds the scrolling message text
    Private nStartPos As Integer            'Counter
    Const nTextDisplayLen As Integer = 50   'Width of text to display
    
    Private Sub Form_Load()
    
        'Creates a message to scroll
        sMsg = "Hello, how are you today? "
        sMsg = sMsg & "I am fine. "
        sMsg = sMsg & "Nice weather we're having. "
        sMsg = sMsg & "Did you catch the game last night? "
        
    End Sub
    
    Private Sub Timer1_Timer()
        
        nStartPos = nStartPos + 1
        
        If nStartPos = Len(sMsg) Then
            nStartPos = 1
        End If
        
        Label1 = right$(Label1 & Mid$(sMsg, nStartPos, 1), nTextDisplayLen)
        
    End Sub
    If you want to stop the scrolling, set Timer1.Interval = 0 and Label1.Caption = "".

    Hope that helps

    ~seawe

    Edited by seaweed on 02-23-2000 at 03:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width