Results 1 to 6 of 6

Thread: Change text multiple times..

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    12

    Resolved Change text multiple times..

    I did a simple search, really couldn't think of what to search for so I figured I'd post.

    What I'm trying to do is change the text in a textbox to "h" then "he" forming up to hello. What I don't want to do is use multiple timers(hate doing this). So basically I'm asking, is there a way to do this with a single Timer some how? Or any other way besides using more than one timer?
    Last edited by Souljahz0r; Aug 3rd, 2007 at 12:16 AM.

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Change text multiple times..

    Code:
    Private mstrDisplay As String
    
    Private Sub Form_Load()
        mstrDisplay = "Hello, world!"
        Timer1.Interval = 1000
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        Static slngLen As Long
        
        slngLen = slngLen + 1
        If slngLen > Len(mstrDisplay) Then
            Timer1.Enabled = False
            slngLen = 0
        Else
            Text1.Text = Left(mstrDisplay, slngLen)
        End If
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    12

    Re: Change text multiple times..

    Sweet, thanks

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    12

    Re: Change text multiple times..

    I tried messing around with that code but couldn't quite get it. How can I make it go back down like "Hello" goes to "Hell" "Hel" etc etc

  5. #5
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Re: Change text multiple times..

    Code:
    Private mstrDisplay      As String
    Private Direction        As String
    Private slngLen          As Integer
    
    Private Sub Form_Load()
          mstrDisplay = "Hello, world!"
          Timer1.Interval = 100
          Timer1.Enabled = True
          Direction = "FW"
          slngLen = 1
    End Sub
    
    Private Sub Timer1_Timer()
    
          If Direction = "FW" Then
                Text1.Text = Mid(mstrDisplay, 1, slngLen)
                slngLen = slngLen + 1
                If slngLen >= Len(mstrDisplay) Then Direction = "BW"
          Else
                Text1.Text = Mid(mstrDisplay, 1, slngLen)
                slngLen = slngLen - 1
                If slngLen <= 0 Then Direction = "FW"
          End If
    End Sub

  6. #6
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Change text multiple times..

    I'd keep the logic in the Timer() sub:
    Code:
    Private mstrDisplay As String
    
    Private Sub Form_Load()
        mstrDisplay = "Hello, world!"
        Timer1.Interval = 1000
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        Static slngLen As Long
        Static slngIncrement As Long
        
        Select Case slngLen
            Case 0: slngIncrement = 1
            Case Len(mstrDisplay): slngIncrement = -1
        End Select
        slngLen = slngLen + slngIncrement
        Text1.Text = Left(mstrDisplay, slngLen)
    End Sub
    This will keep it bouncing back and forth between growing and shrinking.

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