Hi Meraldo,
Here is a nice way of achieving a Scrolling Text on a UserForm
:
You will need to design your Form as follos:
Let's suppose the Form is
UserForm1.
Add the following Controls:
Frame1 to serve as a container for the Label .
Label1 to display the scrolling Text. This label should be placed within Frame1.Adjust its position as required.
SpinButton1 to change the Speed of the srolling text.
One CommandButton:
ScrlBttn to activate the scrolling.
One CommandButton :
StpScrlButtn to halt the Scrolling.
One CommandButton :
UnloadFrmBttn to unload the Form.
Note that ,unlike the other controls, the 3 CommandButtons have their names changed for clarity purposes. Rename them via the Property sheet in the VBE at design time.
Ok, that's all for the UserForm design.
Now, let's begin with the Codes and Modules.
Paste this Code in the
UserForm1 Module:
<font face=Courier New>
<SPAN style="color:#007F00">' // Code Purpose:</SPAN>
<SPAN style="color:#007F00">'===================================</SPAN>
<SPAN style="color:#007F00">' Displays a scrolling text on a UserForm and</SPAN>
<SPAN style="color:#007F00">' add other controls to mange the speed of the</SPAN>
<SPAN style="color:#007F00">' scrolling.</SPAN>
<SPAN style="color:#007F00">' The code uses a Class Module to hook the</SPAN>
<SPAN style="color:#007F00">' ccrpTimer Object to which a reference must</SPAN>
<SPAN style="color:#007F00">' be established Via Tools¦References in the</SPAN>
<SPAN style="color:#007F00">' VB Editor.</SPAN>
<SPAN style="color:#007F00">' The ccrpTimer is part of the High-Performance</SPAN>
<SPAN style="color:#007F00">' Timer Objects which can be downloaded from</SPAN>
<SPAN style="color:#007F00">' www.mvps.org/ccrp/download/ccrpdownloads.htm</SPAN>
<SPAN style="color:#007F00">'====================================</SPAN>
<SPAN style="color:#007F00">' // Code written by Jaafar Cobos on 30/06/03.</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> ClssT <SPAN style="color:#00007F">As</SPAN> Class1
<SPAN style="color:#00007F">Dim</SPAN> ccrpTmr <SPAN style="color:#00007F">As</SPAN> ccrpTimer
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UnloadFrmBttn_Click()
Unload Me
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> SpinButton1_SpinDown()
Beep
ScrollSpeed = ScrollSpeed / 2
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> SpinButton1_SpinUp()
Beep
ScrollSpeed = ScrollSpeed * 2
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UserForm_Initialize()
ScrollSpeed = 1
msg = "This is a nice scrolling text demonstration !!!"
<SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> 12
msg = msg & vbCrLf & msg
<SPAN style="color:#00007F">Next</SPAN>
Me.Caption = "Scrolling Text Test."
<SPAN style="color:#00007F">With</SPAN> Label1
.Caption = msg
.Font.Bold = <SPAN style="color:#00007F">True</SPAN>
.ForeColor = vbRed
.Top = Frame1.Height
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">With</SPAN> StpScrlButtn
.Enabled = <SPAN style="color:#00007F">True</SPAN>
.Caption = "Stop Label Scrolling"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">With</SPAN> ScrlBttn
.Enabled = <SPAN style="color:#00007F">False</SPAN>
.Caption = "Scroll Label"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
UnloadFrmBttn.Caption = "Unload Form"
Frame1.Caption = ""
SpinButton1.Enabled = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">Set</SPAN> ClssT = <SPAN style="color:#00007F">New</SPAN> Class1
<SPAN style="color:#00007F">Set</SPAN> ClssT.ccrpTmr = <SPAN style="color:#00007F">New</SPAN> ccrpTimer
ClssT.ccrpTmr.Enabled = <SPAN style="color:#00007F">True</SPAN>
ClssT.ccrpTmr.Interval = 10
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ScrlBttn_Click()
ClssT.ccrpTmr.Enabled = <SPAN style="color:#00007F">True</SPAN>
SpinButton1.Enabled = <SPAN style="color:#00007F">True</SPAN>
ScrlBttn.Enabled = <SPAN style="color:#00007F">False</SPAN>
StpScrlButtn.Enabled = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> StpScrlButtn_Click()
ClssT.ccrpTmr.Enabled = <SPAN style="color:#00007F">False</SPAN>
SpinButton1.Enabled = <SPAN style="color:#00007F">False</SPAN>
StpScrlButtn.Enabled = <SPAN style="color:#00007F">False</SPAN>
ScrlBttn.Enabled = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
Place this at the
top of a
Standard Module:
<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> ScrollSpeed <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>
</FONT>
Insert a Class module
Class1 in your project and paste the following code in it:
<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">WithEvents</SPAN> ccrpTmr <SPAN style="color:#00007F">As</SPAN> ccrpTimer
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ccrpTmr_Timer(<SPAN style="color:#00007F">ByVal</SPAN> Milliseconds <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>)
<SPAN style="color:#00007F">With</SPAN> UserForm1
<SPAN style="color:#00007F">If</SPAN> .Label1.Top < -.Label1.Height <SPAN style="color:#00007F">Then</SPAN>
.Label1.Top = .Frame1.Height
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
.Label1.Top = .Label1.Top - ScrollSpeed
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
As you can see the code makes use of the ccrpTimer object.
If you don't have the ccrpTimer.dll library on your disk try downloading it from here under the High Performance Timer Objects and establish a reference to it via Tools¦References in thr VB editor:
http://www.mvps.org/ccrp/download/ccrpdownloads.htm
Enjoy the scrolling !