Link to home
Start Free TrialLog in
Avatar of Afrofish
AfrofishFlag for Ireland

asked on

Scrolling Marquee for Access - Causing PC to crash

Hi there,

I have written some VB code to provide a scrolling marquee for an access form.  It seems to work fine but on a couple of occasions since implementing it my PC has frozen without warning and I suspect the marquee.  Can one of the experts please check my code (adapted from previous posts on the subject), to ensure I haven't done anything wrong.

Thanks,

John
Option Compare Database
Private ScreenText As String
Private Const cStartPos = 9000
Private Const cOffset = 3000
Private stringLen As Integer
Private txtAlign As Byte
 
Private Sub Form_Open(Cancel As Integer)
    
    ScreenText = "Latest exchange rates from 'www.fxcentre.com' :  "
    ScreenText = ScreenText & "GBP>EUR " & GetRate("GBP", "EUR")
    ScreenText = ScreenText & " : "
    ScreenText = ScreenText & "DKK>EUR " & GetRate("DKK", "EUR")
    stringLen = Len(ScreenText) * 106
    If stringLen > cStartPos Then
        stringLen = cStartPos
    End If
    ResetScroll
    
End Sub
 
Private Sub cmdToggle_Click()
    If Form.TimerInterval = 0 Then
        Form.TimerInterval = 40
        Me.cmdToggle.Caption = "Stop Ticker"
    Else
        Form.TimerInterval = 0
        Me.cmdToggle.Caption = "Start Ticker"
    End If
End Sub
 
Private Sub ResetScroll()
    lblInfo.Caption = ScreenText
    lblInfo.Width = 50
    lblInfo.Left = cStartPos + cOffset - 50
    lblInfo.TextAlign = 1 'left
    txtAlign = 1
End Sub
 
Private Sub Form_Timer()
    If lblInfo.Left < 51 + cOffset And _
       lblInfo.Width < 51 Then
       ResetScroll
    End If
    If lblInfo.Left > 50 + cOffset Then
       lblInfo.Left = lblInfo.Left - 40
    End If
    If lblInfo.Width < stringLen And _
       lblInfo.TextAlign = 1 Then
       lblInfo.Width = lblInfo.Width + 40
    ElseIf lblInfo.Width >= stringLen And _
       lblInfo.TextAlign = 1 Then
       lblInfo.TextAlign = 3
    ElseIf lblInfo.Left < 51 + cOffset Then
       lblInfo.Width = lblInfo.Width - 40
    End If
End Sub

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

try putting the codes in the Load event of the form instead of the Open event
FWIW,

I gave up on "Enhancements" like scrolling text a long time ago for reasons like this.
- Timing errors.
- Text not scrolling smoothly.
- Difficut calculating the lenght of the string against the "Appear" point and the "disappear" point.

Instead of doing this your self, you can buy a control that does this with style and professionalism. (and more options than you can dream of)
;-)
See this link:
http://www.fmsinc.com/Products/components/ControlTour/marquee.htm

JeffCoachman
Avatar of Afrofish

ASKER

Thanks for the help guys.

I may have found a solution (or I may have opened a whole new can of worms).  Moving the code seemed to have no effect on the problem so I decided to restart from scratch.  I thought about alternate ways of creating scrolling text and the most obvious is on websites.  The company I am creating the site for use internet explorer (which has the marquee tool built into the html).  For this reason I wrote a piece of code which created a webpage and then loaded the webpage into a microsoft (active x) web control on the page.  The only problem now is that the web control is incredibly resource hungry and the ie instance doesn't seem to shut down when the form is closed.  I think I feel another question coming on .....
Private Sub Form_Timer()
 
    createTheHTML
    webScroll.Navigate ("")
    webScroll.Navigate ("c:\marquee.html")
    cmdTicker.Caption = "Stop Ticker"
    webScroll.Visible = True
   
End Sub
 
Private Sub cmdTicker_Click()
 
If cmdTicker.Caption = "Stop Ticker" Then
    cmdTicker.Caption = "Start Ticker"
    webScroll.Navigate ("")
    webScroll.Visible = False
Else
    Form_Timer
End If
 
End Sub
 
Public Sub createTheHTML()
 
If Len(Dir("c:\marquee.html")) > 0 Then
    Kill "c:\marquee.html"
End If
Open "c:\marquee.html" For Output As #1
Print #1, "<html>"
Print #1, "<head>"
Print #1, "</head>"
Print #1, "<body bgcolor='black' marginheight='0' topmargin='0' vspace='0'"
Print #1, "marginwidth='0' leftmargin='0' hspace='0'"
Print #1, "style='margin:0; padding:0;"
Print #1, "font-family:verdana'>"
Print #1, "<font color='white'>"
Print #1, "<marquee loop='infinite'>"
Print #1, "Exchange rates from 'www.fxcentre.com' at "
Print #1, Now()
Print #1, " :  "
Print #1, "GBP>EUR " & GetRate("GBP", "EUR")
Print #1, " : SEK>EUR " & GetRate("SEK", "EUR")
Print #1, " : USD>EUR " & GetRate("USD", "EUR")
Print #1, "</marquee>"
Print #1, "</font>"
Print #1, "</body>"
Print #1, "</html>"
Close #1
 
End Sub

Open in new window

Anything that requires continuous timer hits will put a drain on your resources.

Is this scrolling a required feature?

Again, the control I mentioned from FMSinc is a lot less resource hungry.
Thats why I thought the website would work, It doesn't use any timer hits (atleast not in access) and I have seen scrolling text on pre-pentium PCs so it should be a breeze for modern computers.  
Sorry boag2000, I didn't answer your question fully.  The control is not mission critical but my employer is very keen to get it working and I am trying to avoid disappointing him.  As to the FMS control, I am sure it will do a great job but I don't want to add any further costs to the database (as it would be me who would have to pay for them).
ASKER CERTIFIED SOLUTION
Avatar of Afrofish
Afrofish
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial