Results 1 to 8 of 8

Thread: Moving text

  1. #1

    Thread Starter
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Moving text

    i m working on mp3 player n i wish to move the name of the song (only name and not location) scrolling, just as in winamp. can neone help?? please!!

  2. #2
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Moving text

    VB Code:
    1. 'add:
    2. 'label1 as label
    3. 'timer1 as timer
    4.  
    5. Const Song As String = "In Extremo - Erdbeermond"
    6.  
    7. Private Sub Form_Load()
    8.   ScrollName (Song)
    9.   Timer1.Interval = 100
    10.   Timer1.Enabled = 1
    11. End Sub
    12.  
    13. Function ScrollName(Name As String) As String
    14. Static N As String
    15.   If Name <> "" Then N = Left(Name & Emp(40), 40) 'enter a songname
    16.  
    17.   N = Right(N, Len(N) - 1) & Left(N, 1) 'move first char to back
    18.   ScrollName = N
    19. End Function
    20.  
    21. Private Sub Timer1_Timer()
    22.   Label1.Caption = ScrollName("")
    23. End Sub
    24.  
    25. Function Emp(Length As Integer) As String
    26.   For i = o To Length
    27.     Emp = Emp & " "
    28.   Next i
    29. End Function

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Moving text

    Put a timer on your form and...

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     Timer1.Interval = 250
    6. End Sub
    7.  
    8. Private Sub Timer1_Timer()
    9.  
    10.     Label1.Caption = Right$(Label1.Caption, Len(Label1.Caption) - 1) & Left$(Label1.Caption, 1)
    11.    
    12. End Sub

  4. #4

    Thread Starter
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Moving text

    hey i tried the codes and it worked fine but it is also showing the whole location of the file.

    E.G. c:\my documents\aabb\xyz.txt

    this whole string is scrolling n i need only "xyz.txt" to scroll.

    plz help

  5. #5
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Moving text

    VB Code:
    1. Function FileName(Path As String) As String
    2.   Dim P As Long
    3.   P = InStrRev(Path, "\")               'find the position of the last \
    4.   FileName = Right(Path, Len(Path) - P) 'cut off and return the part after the last \
    5. End Function
    6.  
    7. FileName = Right(Path, Len(Path) - InStrRev(Path, "\")) 'in one line
    Search around for string manipulation.

  6. #6
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Moving text

    just expanding on Martins code.
    VB Code:
    1. Dim str1 As String, str2 As String
    2.  
    3. str1 = Left$(Label1.Caption, InStrRev(Label1.Caption, "\"))
    4. str2 = Right$(Label1.Caption, Len(Label1.Caption) - Len(str1))
    5.  
    6. Label1.Caption = str1 & Right$(str2, Len(str2) - 1) & Left$(str2, 1)

    casey.

  7. #7
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Moving text

    Of course if you want a more complicated solution leave it to me to provide it.
    This method scrolls more smoothly, one pixel at a time, rather than one character at a time.

    On your form put a
    picturebox (Picture1)
    Label (Label1)
    Timer (Timer1)
    Set index of label control to zero
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. 'set up text display
    5.  
    6.     Label1(0).AutoSize = True
    7.     Load Label1(1)
    8.     Label1(1).Visible = True
    9.     Picture1.Height = Label1(0).Height + 60
    10.     Picture1.ScaleMode = vbPixels
    11.  
    12. End Sub
    13.  
    14. Private Sub Command1_Click()
    15.  'text we want to display
    16.  SetText "Hello World - C Programmer's Group"
    17.  'set scroll speed
    18.  Timer1.Interval = 20
    19. End Sub
    20.  
    21. Private Sub Timer1_Timer()
    22.     ScrollText
    23. End Sub
    24.  
    25. 'use this routine to set the display text
    26. Sub SetText(StrText As String)
    27.     Label1(0) = StrText & Space(10)
    28.     Label1(1) = Label1(0)
    29.     Label1(0).Left = 0
    30.     Label1(1).Left = Label1(0).Width
    31. End Sub
    32.  
    33. 'Here is where we do all the work
    34. Public Sub ScrollText()
    35.  Static i As Integer
    36.  Dim k As Integer
    37.  k = i Xor 1 'other label
    38.  'move the label left by one pixel
    39.  Label1(i).Left = Label1(i).Left - 1
    40.  'other label follows like a train
    41.  Label1(k).Left = Label1(i).Left + Label1(i).Width
    42.  'if engine is off screen, then make it caboose
    43.  If Label1(k).Left = 0 Then i = k
    44.  
    45. End Sub
    If you get too much flicker with this, then we can get even more complicated.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Moving text

    Cool I came up with a way that flickered something awful. This method is much better!

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