Results 1 to 2 of 2

Thread: Scrolling Text

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Location
    Tallahassee, Florida
    Posts
    24

    Scrolling Text

    I want to add scrolling text to my website. I have about 5 news updates that need to be displayed. I am using sql server to store the data in, and would like to display each record I have in my table.

  2. #2
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271
    This VB project will scroll text across a form. Add 2 text boxes
    (named txtMessage and txtScroll) and a button (named
    Command1) to a form then paste this code to the form's module.

    Code:
    Option Explicit
    Private Sub Form_Load()
      Me.Left = 0
      Me.Width = Screen.Width
      txtScroll.Locked = True
      txtScroll.Text = ""
      txtScroll.BorderStyle = 0
      txtScroll.BackColor = vbBlack
      txtScroll.ForeColor = vbWhite
      txtScroll.Top = 0
      txtScroll.Left = 0
      txtScroll.Height = 240
      txtScroll.Width = Me.Width
      Command1.Caption = "Add Text"
      Command1.Width = TextWidth(Command1.Caption) + 220
      txtMessage = "Add you're message here"
      txtMessage.Width = TextWidth(txtMessage) + 300
    End Sub
    
    Private Sub Form_Activate()
      txtMessage.SetFocus
      'prime txtScroll
      Do Until TextWidth(txtScroll) >= txtScroll.Width
        txtScroll = txtScroll & "."
      Loop
      txtScroll = txtScroll & "First message is scrolling on to form..."
      StartMessage
    End Sub
    
    Private Sub Command1_Click()
      'add message
      txtScroll = txtScroll & txtMessage
    End Sub
    
    Private Sub txtMessage_GotFocus()
      txtMessage.SelStart = 0
      txtMessage.SelLength = Len(txtMessage.Text)
    End Sub
    
    Private Sub StartMessage()
      Do Until Trim(txtScroll.Text) = ""
        DoEvents
        If TextWidth(txtScroll.Text) >= txtScroll.Width Then
          'strip first char.
          txtScroll.Text = Right(txtScroll.Text, Len(txtScroll.Text) - 1)
        Else
          'add a space to end of message
          txtScroll = txtScroll & " "
        End If
        Pause 0.075 'changes speed default=.075 seconds/character
      Loop
      MsgBox "No more messages"
    End Sub
    
    Private Sub Pause(gSeconds As Single)
      Dim gCurrent As Single
      'operations wait for gSeconds to ellapse
      gCurrent = Timer
      Do While Timer - gCurrent < Val(gSeconds)
        DoEvents
      Loop
    End Sub
    Note: To change the scroll speed adjust the Pause call.
    Sometimes what you're looking for is exactly where you left it.

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