|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Time fired event, error out of stack spaceI am trying to get my application to act as the user by `clicking` command3 button once an hour for them which basically refreshes all the latest data from a big database to process. I have got my code which works out the time etc and have it on a label in the form, which in timer1 looks for etc. But when i run off a very small bit of code to start it i get error 28, out of stack space on the call command3.click bit. The code is in the timer1 which also works out how long windows has been running for. i have inserted a test time of 01:20, you can alter this to what you like to try and fire the command3.click. Any suggestions. thanks. timer1 Const MS_PER_SEC As Long = 1000 Const MS_PER_MIN = MS_PER_SEC * 60 Const MS_PER_HR = MS_PER_MIN * 60 Const MS_PER_DAY = MS_PER_HR * 24 Dim ms As Long Dim secs As Long Dim mins As Long Dim hrs As Long Dim days As Long ms = GetTickCount() days = ms \ MS_PER_DAY ms = ms - days * MS_PER_DAY hrs = ms \ MS_PER_HR ms = ms - hrs * MS_PER_HR mins = ms \ MS_PER_MIN ms = ms - mins * MS_PER_MIN secs = ms \ MS_PER_SEC ms = ms - secs * MS_PER_SEC Dim CALENDER Dim CLOCK CALENDER = Date CLOCK = Time formclock = Format(CLOCK, "HH:MM:SS") Label24.Caption = Right$(formclock, 5) Label10.Caption = Format$(hrs) & ":" + Format$(mins) & ":" + Format$(secs) & "" StatusBar2.Panels(1).Text = "Windows has been running for:- " + Format$(days) & " Days, " + Format$(hrs) & " Hours, " + Format$(mins) & " Minutes, " + Format$(secs) & " Seconds" If Format$(hrs) >= 12 Then StatusBar2.Panels(1).Text = "Windows has been running for:- " + Format$(days) & " Days, " + Format$(hrs) & " Hours, " + Format$(mins) & " Minutes, " + Format$(secs) & " Seconds - A reboot is now recommended" End If If Format$(days) >= 1 Then StatusBar2.Panels(1).Text = "Windows has been running for:- " + Format$(days) & " Days, " + Format$(hrs) & " Hrs, " + Format$(mins) & " Mins, " + Format$(secs) & " Secs - A reboot is now overdue" StatusBar2.Font.Bold = True End If If Format$(days) <= 1 Then If Check1.Value = 1 Then If Label24.Caption = "01:20" And Command3.Enabled = True Then Call Command3_Click <<==error here End If End If If
Show quote
Hide quote
> I am trying to get my application to act as the user by `clicking` command3 A stack overflow occurs when one piece of code calls itself (either directly or indirectly) indefinitely, causing an infinite loop.> button once an hour for them which basically refreshes all the latest data > from a big database to process. > > I have got my code which works out the time etc and have it on a label in > the form, which in timer1 looks for etc. > > But when i run off a very small bit of code to start it i get error 28, out > of stack space on the call command3.click bit. > > The code is in the timer1 which also works out how long windows has been > running for. > > i have inserted a test time of 01:20, you can alter this to what you like to > try and fire the command3.click. I would assume that in your Command3_Click() event handler you've got some code which is causing the timer event to be triggered immediately, causing the click event to be called again etc. Also in terms of general coding practices, you should really declare your CALENDER and CLOCK variables with a type (Date would be the most suited in this case) and CStr() would likely be more appropriate than Format$() when you're not specifying a specific format. Lines like "If Format$(days) <= 1 Then" should really be avoided since you're performing type conversion from a long to a string and then forcing VB to perform the reverse calculation to compare against a numeric argument. Also, "If Check1.Value = 1 Then" should really be "If Check1.Value = vbChecked Then" and "And Command3.Enabled = True Then" should be "And Command3.Enabled Then"; never compare a boolean against the True constant since 'True' is really anything not equal to false. Finally, with this: *** formclock = Format(CLOCK, "HH:MM:SS") Label24.Caption = Right$(formclock, 5) *** If you don't require the hours then you don't need to request them in the Format() method, and minutes should really be specified as "NN" rather than "MM" to avoid ambiguities with the moth part of the Date datatype: *** Label24.Caption = Format$(CLOCK, "NN:SS") *** Hope this helps, Mike P.s. Be warned that GetTickCount() returns an unsigned integer while VB's Long datatype is a signed integer so it's perfectly valid for it to return a negative value after and up-time of just over 24 days. To extend this to cope with an up-time of 49 days send the output from GetTickCount() through my SLongToULong() function: http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/msg/eb35844e92f7f423 This may not be an issue since you're advocating a reboot every 24 hours (Didn't think anyone was still running Win95/ME ;) but it's always worth knowing these things. - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/
Definition of an implementation
Resizing form DOS box and ALT_ENTER How 2 get data from a web form VB Package Deployment Problem How to select ListView Item with right click VB6 mdi app starts behind running application How to show a form from another dll in my current SDI form having a toolbar. What's wrong with my code? Help: random, untrappable error |
|||||||||||||||||||||||