PDA

View Full Version : Odd Excel behavior



nst1107
12-22-2008, 09:12 PM
I'm working on this marquee textbox, and I have code that I think should work. At least, in theory. However, Excel is doing something I'm at a loss to explain. The problem occurs in this function:Public Function cbkRoutine(ByVal Window_hWnd As Long, _
ByVal WindowsMessage As Long, _
ByVal EventID As Long, _
ByVal SystemTime As Long) As Long
Dim w As Integer
Dim marqueeRefresh As String
Dim flag As Boolean
scrollPoss = scrollPoss + 1
Do
With TimerSheet.Cheater
.Value = Mid(scrollStr, l, scrollPoss / 10 - w)
.AutoSize = True
curWidth = .Width
End With
If curWidth > TimerSheet.Marquee.Width Then
With TimerSheet.Cheater
.AutoSize = False
.Width = TimerSheet.Marquee.Width
End With
l = l + 1
w = w + 1
Else
flag = True
marqueeRefresh = TimerSheet.Cheater
End If
Loop Until flag = True
TimerSheet.Marquee = marqueeRefresh
If scrollPoss / 10 = Len(scrollStr) Then scrollPoss = 0
End Function

All goes well until the first time curWidth is greater than TimerSheet.Marquee.Width. The code executes perfectly to the end of the function, then jumps back to With TimerSheet.Cheater
.AutoSize = False I don't know why it does this.

Also, if I am stepping through the code, and don't have a breakpoint set at that line, then the code runs on without allowing me to step through it anymore.

I'll post the workbook in case the cause isn't in this function. The workbook is essentially the workbook that Bob posted in a previous thread (so help me, I don't remember which thread it was anymore), and most of the code is his. I'm simply trying to modify it to my end.

nst1107
12-22-2008, 09:16 PM
Here's the file.

GTO
12-22-2008, 10:08 PM
Hey Nate -

Any chance of posting a pre-2007 version? Many of us don't have 2007.

Mark

nst1107
12-23-2008, 08:22 AM
Here's a pre-2007 version. In Excel 97, if you have a breakpoint at that line, the code breaks and opens the VBE at that point, but then immediately resumes as if you were holding down F8, only it executes at a much faster rate. 97 also runs out of stack space after a few seconds. 2007 doesn't do this.

nst1107
12-23-2008, 08:23 AM
Here's

nst1107
12-23-2008, 08:24 AM
Here's the workbook

GTO
01-04-2009, 08:59 PM
Hey Nate,

Sorry - this "fell out of my brain" over the holidays. I did get to look today, and found all the API in it. Now when I say found all the API, I might has well said "opened the cover to the box and found the High Voltage warning!"

I've used API a tiny bit here and there, such as to hide a titlebar or similar; but always a bit cautiously and while following a good (nothing blows up when the example is run) example.

Did you ever get any better results from the pseudo marquee? Also, if you downloaded it from somewheres, any chance at recollecting where?

Thank you so much,

Mark

Bob Phillips
01-05-2009, 01:58 AM
I can tell you where he got the timer code from, he got it from my timer download.

nst1107
01-05-2009, 12:41 PM
I remember downloading it from one of Bob's replies in a thread here. I looked for the thread a bit before I started this thread, but I didn't find it. I think it was one where someone was trying to make a flashing commandbutton. And, no, I haven't gotten any better results. I didn't do anything over the holidays.

GTO
01-06-2009, 04:26 AM
@XLD: Greetings Bob :-) If I grabbed the wrong one, please correct me straightaway.

Hi Nate,

Might you be referring to: http://www.vbaexpress.com/forum/showthread.php?t=24207 , post #2, VBAX - 24207 - Flashing Button.xls ?

I ask this, as I may have done a poor search and glommed on to the wrong example. If correct however, is the remainder of the code yours, or could this be a couple of examples combined?

Sorry to be so thick-headed, but as aforementioned, I have not learned much in the area of API. Thus - would like the "best chance" at understanding what's happening.

A side note: You mentioned where stepping thru the code is frustrating; I have experienced the same. In fact, I have had to: (1) remove API, (2) test, (3) re-insert API, (4) test, on several occassions. Frustrating to say the least.

Finally, I would mention that at least on my sickly laptop, there is a difference in results, reference what I set Interval to. Therefore, I am suspicious of any further observations. But... if my observations are correct - the "marquee" is not supposed to actually scroll the text across the textbox, but rather, scrolls into view and then starts over. That is to say, the textstring isn't supposed to "disappear" as it "exits" out the left side of the textbox. Do I understand that part(?), and if yes, is this your goal, or, would you rather have it "exit" like an HTML Marquee does?

Well, hopefully my questions were halfway sensible...

Mark

Bob Phillips
01-06-2009, 04:38 AM
@XLD: Greetings Bob :-) If I grabbed the wrong one, please correct me straightaway.

Just pointing out that the API code was taken straight from one of one posts, and is simply to allow finer resolution on the timing, down to 1,000th of a second.

GTO
01-06-2009, 05:46 AM
Just pointing out that the API code was taken straight from one of one posts, and is simply to allow finer resolution on the timing, down to 1,000th of a second.

@XLD:

Thnk you brother. Just didn't want to disallow for the possibility that OP had taken from a more exact sample (ie - where (a) textbox(es) / marquee example were present).

Hope you and your bride had a lovely Christmas.

Mark

nst1107
01-06-2009, 08:33 AM
Yes, that looks like exactly the post I was looking for. The rest of the code, though I haven't added much, is mine. And, yes, the end goal was to have the text "exit" as in an HTML marquee. Wouldn't know it from looking at what I have, though.
You know, this all started because I used to have an old computer with Office 97, and it had a marquee control (most likely foreign to Excel) that I could add to Excel. I didn't have access to the internet back then, so I never found out how to operate the thing (for all I know, it was impossible). I don't have such a control on this computer, though, so I'm doing this out of curiosity.
About all that API, I don't have a clue what it's doing. I assumed I could find the point where Bob changed the color of the button and switch his code with mine, but apparently it's not that simple. In fact, I didn't know what API was until Mark mentioned it and I looked it up. So, there's my ignorance.