|
-
Apr 2nd, 2005, 11:27 AM
#1
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!!
-
Apr 2nd, 2005, 11:44 AM
#2
Frenzied Member
Re: Moving text
VB Code:
'add:
'label1 as label
'timer1 as timer
Const Song As String = "In Extremo - Erdbeermond"
Private Sub Form_Load()
ScrollName (Song)
Timer1.Interval = 100
Timer1.Enabled = 1
End Sub
Function ScrollName(Name As String) As String
Static N As String
If Name <> "" Then N = Left(Name & Emp(40), 40) 'enter a songname
N = Right(N, Len(N) - 1) & Left(N, 1) 'move first char to back
ScrollName = N
End Function
Private Sub Timer1_Timer()
Label1.Caption = ScrollName("")
End Sub
Function Emp(Length As Integer) As String
For i = o To Length
Emp = Emp & " "
Next i
End Function
-
Apr 2nd, 2005, 11:46 AM
#3
Re: Moving text
Put a timer on your form and...
VB Code:
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 250
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Right$(Label1.Caption, Len(Label1.Caption) - 1) & Left$(Label1.Caption, 1)
End Sub
-
Apr 3rd, 2005, 09:17 AM
#4
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
-
Apr 3rd, 2005, 09:34 AM
#5
Frenzied Member
Re: Moving text
VB Code:
Function FileName(Path As String) As String
Dim P As Long
P = InStrRev(Path, "\") 'find the position of the last \
FileName = Right(Path, Len(Path) - P) 'cut off and return the part after the last \
End Function
FileName = Right(Path, Len(Path) - InStrRev(Path, "\")) 'in one line
Search around for string manipulation.
-
Apr 3rd, 2005, 09:39 AM
#6
Re: Moving text
just expanding on Martins code.
VB Code:
Dim str1 As String, str2 As String
str1 = Left$(Label1.Caption, InStrRev(Label1.Caption, "\"))
str2 = Right$(Label1.Caption, Len(Label1.Caption) - Len(str1))
Label1.Caption = str1 & Right$(str2, Len(str2) - 1) & Left$(str2, 1)
casey.
-
Apr 3rd, 2005, 08:35 PM
#7
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:
Option Explicit
Private Sub Form_Load()
'set up text display
Label1(0).AutoSize = True
Load Label1(1)
Label1(1).Visible = True
Picture1.Height = Label1(0).Height + 60
Picture1.ScaleMode = vbPixels
End Sub
Private Sub Command1_Click()
'text we want to display
SetText "Hello World - C Programmer's Group"
'set scroll speed
Timer1.Interval = 20
End Sub
Private Sub Timer1_Timer()
ScrollText
End Sub
'use this routine to set the display text
Sub SetText(StrText As String)
Label1(0) = StrText & Space(10)
Label1(1) = Label1(0)
Label1(0).Left = 0
Label1(1).Left = Label1(0).Width
End Sub
'Here is where we do all the work
Public Sub ScrollText()
Static i As Integer
Dim k As Integer
k = i Xor 1 'other label
'move the label left by one pixel
Label1(i).Left = Label1(i).Left - 1
'other label follows like a train
Label1(k).Left = Label1(i).Left + Label1(i).Width
'if engine is off screen, then make it caboose
If Label1(k).Left = 0 Then i = k
End Sub
If you get too much flicker with this, then we can get even more complicated.
-
Apr 3rd, 2005, 11:45 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|