Hi guys
I am getting a Runtime Error 16: Overflow. when my EXE that I created in VB 6 is running for few minutes and when I Click ok on the OK Button on error msg, the application shut down.
Any idea what could be the cause?
Thanks
Printable View
Hi guys
I am getting a Runtime Error 16: Overflow. when my EXE that I created in VB 6 is running for few minutes and when I Click ok on the OK Button on error msg, the application shut down.
Any idea what could be the cause?
Thanks
The overflow error means that you are trying to put a number into a variable (or property etc), but the value is too high - such as 33000 into an Integer variable.
What does your application do?
Does this happen in the IDE or only in the compiled version?
You may need to declare your numeric variable As Long or Double rather than Integer.
I'm guessing, btw - you didn't show any code ... :confused:
When this runs it gives the user a choice to delay a reboot of his computer, when he choses to delay, after few minutes I would say about 10 min , this errors kicks in, If I run the EXE without clicking on the Command2, it works well.
Here is the Code:
VB Code:
Private Sub Command1_Click() Dim startTime As String Dim minutesToDelay As String With Timer1 .Interval = 1 .Enabled = True End With myApp = "shutdown.exe -r" startTime = CStr(timeGetTime) minutesToDelay = "5" 'must be a number character, otherwise Val returns 0 endTime = Val(startTime) + Val(minutesToDelay * 60000) SetWindowPos Me.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE Me.WindowState = vbMinimized delayCount = delayCount + 1 'increase delay counter for 1 If delayCount = 5 Then 'if you want to limit number of delays Shell "shutdown -a" Sleep 1200 Shell "shutdown -f -r -t 300 -c ""Your machine will reboot in 5 minutes""" End If End Sub Private Sub Form_Load() ' Timer1.Interval = 100 'fire timer Timer1.Enabled = True Timer1.Interval = 60000 '1 minute End Sub Private Sub Picture1_Click() End Sub Private Sub Timer1_Timer() Static iCounter As Integer If iCounter = 3600000 Then SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE Me.WindowState = vbNormal iCounter = 0 End If iCounter = iCounter + 1 End Sub
by the way ,this is part of the code where I think where the problem is
As RhinoBull said, you need to declare the variable as Long (max value over 4 billion) rather than Integer (max value just over 32000), ie:
VB Code:
Static iCounter As [u]Long[/u]
I will try this out
Isn't Long a max of just over 2 billion?
Double is bigger... (but long should do for what he needs)....
ok now, I am not getting the error msg anymore, but it seems its NOT calling the task that it supposed to every 60 mins. changing it to LONG do I have to change the format of the number to reflect 60 min, in another words ,what number I need to put in the iCounter to reflect 60 min?
VB Code:
Private Sub Form_Load() ' Timer1.Interval = 100 'fire timer Timer1.Enabled = True Timer1.Interval = 60000 '1 minute End Sub Private Sub Picture1_Click() End Sub Private Sub Timer1_Timer() Static iCounter As Long If iCounter = 3600000 Then SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE Me.WindowState = vbNormal iCounter = 0 End If iCounter = iCounter + 1 End Sub
Your timer interval is set to 1 minute so static counter within the timer procedure should go upto 60 not 3600000:
If iCounter = 60 Then
Thanks let me try it out
Yep.. silly me! :blush:Quote:
Originally Posted by tward_biteme1