|
-
Aug 25th, 2006, 11:19 AM
#1
Thread Starter
Hyperactive Member
I am getting Runtime Error 16
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
-
Aug 25th, 2006, 11:21 AM
#2
Re: I am getting Runtime Error 16
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.
-
Aug 25th, 2006, 11:21 AM
#3
Re: I am getting Runtime Error 16
What does your application do?
Does this happen in the IDE or only in the compiled version?
-
Aug 25th, 2006, 11:22 AM
#4
Re: I am getting Runtime Error 16
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 ...
-
Aug 25th, 2006, 11:28 AM
#5
Thread Starter
Hyperactive Member
Re: I am getting Runtime Error 16
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
-
Aug 25th, 2006, 11:29 AM
#6
Thread Starter
Hyperactive Member
Re: I am getting Runtime Error 16
by the way ,this is part of the code where I think where the problem is
-
Aug 25th, 2006, 11:30 AM
#7
Re: I am getting Runtime Error 16
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]
-
Aug 25th, 2006, 11:40 AM
#8
Thread Starter
Hyperactive Member
Re: I am getting Runtime Error 16
-
Aug 25th, 2006, 12:09 PM
#9
Hyperactive Member
Re: I am getting Runtime Error 16
Isn't Long a max of just over 2 billion?
Double is bigger... (but long should do for what he needs)....
-
Aug 25th, 2006, 12:52 PM
#10
Thread Starter
Hyperactive Member
Re: I am getting Runtime Error 16
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
Last edited by wajdi; Aug 25th, 2006 at 12:56 PM.
-
Aug 25th, 2006, 01:07 PM
#11
Re: I am getting Runtime Error 16
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
-
Aug 25th, 2006, 01:08 PM
#12
Thread Starter
Hyperactive Member
Re: I am getting Runtime Error 16
-
Aug 25th, 2006, 02:23 PM
#13
Re: I am getting Runtime Error 16
 Originally Posted by tward_biteme1
Isn't Long a max of just over 2 billion?
Yep.. silly me!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|