PDA

Click to See Complete Forum and Search --> : What's wrong with this code


bucko
Jan 19th, 2000, 04:35 PM
Hi, I'm trying to get some old code working (it's been converted from VB3 binary format).

i've had a few problems but managed to solve them but the latest one is puzzling me (i'm a bit of a beginner).

when i try to run the program i get the error message

Runtime error '6':
overflow

and the piece of code
chk = Shell(ret, 8)
is highlighted when i click the debug button

the function is shown below

does anyone have any ideas
thanks in advance
MICK

Private Function StartAcad() As Integer

Dim ret$
Dim nSize%, chk%, chk2%

ret = String$(145, Chr$(0))
nSize = Len(ret)
chk2 = True

chk = GetPrivateProfileString("AUTOCAD", "EXEPATH", "", ret, nSize, INI_path)

If chk = 0 Then
MsgBox "Unable to start AutoCAD, check PLOTLOG.INI for validity."
chk2 = False
Else
chk = Shell(ret, 8)
End If

StartAcad = chk2
End Function

Crazy D
Jan 19th, 2000, 04:43 PM
Allmost all Win32 API's are changed from integer to long... change the declarations of the integers to long and it should work (at least no overflow error...)

Clunietp
Jan 20th, 2000, 11:57 AM
You need a double or variant variable to receive the return value of the SHELL function:

from MSDN:



Shell Function

Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero.


So change that % to a #

Better yet, explicitly declare the data types instead of using those old-fashioned operators, so the next programmer won't want to strangle you.