Runtime error

Runtime error

Anonymous
Not applicable
395 Views
3 Replies
Message 1 of 4

Runtime error

Anonymous
Not applicable
Okay here’s the deal. I have this simple program (for now) that simply gets a few variables, prints them to a text file, starts a new drawing, and runs a LISP routine that simply reads those variables from the text file and presents an alert box that says “HEY! I think It works.” More code will be added to that later, to do a multitude of calculations and draw some “stuff”, but for now this is how I begin most VBA/LISP programs. I have several that work on the same concept, a VBA dialog box (or boxes) collect information, print it to a text file and then a LISP r5outine reads that information and performs the calculations and draws the object(s).

This one works fine but when I close AutoCAD after running it I get this message.

Microsoft Visual C++ Runtime Library
Runtime Error!
Program C:\Program Files\AutoCAD 2002\acad.exe
abnormal program termination

None of the other programs cause this, and I even get it when I have the LISP routine unload the VBA project.

The main VBA code is
[Private Sub CmdOkay_Click()

If CboNumPocks.Value <> "" Then
If CboNumPocks.Value Mod 2 > 0 Then
MsgBox "The number of pockets MUST be an even number.", _
vbExclamation, " Rollover Wheel ERROR!"
CboNumPocks.SetFocus
Exit Sub
Else
IntNumPocks = CboNumPocks.Value
End If
Else
MsgBox "You must enter the desired number of pockets!", vbExclamation, _
" Number of Pockets ERROR."
CboNumPocks.SetFocus
Exit Sub
End If

If CboRollDia.Value = "" Then
MsgBox "You must enter the desired roll diameter!", vbExclamation, _
" Roll Diameter ERROR."
CboRollDia.SetFocus
Exit Sub
Else
DblRollDia = CboRollDia.Value
End If

If TxtProdLong.Value = "" Then
MsgBox "You must enter the product length!", vbExclamation, _
" Product Length ERROR."
TxtProdLong.SetFocus
Exit Sub
Else
DblProdLong = TxtProdLong.Value
End If

If TxtProdWide.Value = "" Then
MsgBox "You must enter the product width!", vbExclamation, _
" Product Width ERROR."
TxtProdWide.SetFocus
Exit Sub
Else
DblProdWide = TxtProdWide.Value
End If

StrRollWheel = "C:\RollWheel.txt"

IntFileNum = FreeFile

Open StrRollWheel For Output As #IntFileNum
Print #IntFileNum, IntNumPocks
Print #IntFileNum, DblRollDia
Print #IntFileNum, DblProdLong
Print #IntFileNum, DblProdWide
Close
Unload Me
ThisDrawing.Application.Documents.Add ("L.dwt")
ThisDrawing.SendCommand "(if (not C:RollMe)(load ""RollMe"")) RollMe "

End

End Sub]

AND the LISP is
[(defun c:RollMe (/ A B C D File inspt)
(setq File (open "C://RollWheel.txt" "r"))
(setq A (read-line File))
(setq B (read-line File))
(setq C (read-line File))
(setq D (read-line File))
(close File)
(setq Inspt (getpoint "Select center Point; "))
(alert "HEY! I think it's working.")
(command "vbaunload" "h:/VBA Routines/RollOverWheels.dvb")

)]
Any ideas??

Thanks

Dave. K
0 Likes
396 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Don't know for sure if it's the cause of the problem, but try removing the
"End" statement from your VBA code.
"End" instantly and unconditioanlly clears all variables (see VB help)
including pointers to/from the calling app and usually causes problems.

Gary

ThisDrawing.SendCommand "(if (not C:RollMe)(load ""RollMe"")) RollMe "
End << Remove this statement
0 Likes
Message 3 of 4

Anonymous
Not applicable
Hey Gary, thanks for the try. Unfortuneately the "End" statement was one of my attempts to fix the problem. I deleted it anyway, just to be sure, and no change.
It may help to know that if I run the program in debug and step throught, it I do not get the error on closing. I also do not get it if I do not start a new drawing. May be I'll try starting the new drawing earlier in the program. Anyway Thanks for ths shot.

Dave. K
0 Likes
Message 4 of 4

Anonymous
Not applicable
Dave,

 

I have lots of code, and have the same message, but
not all the time. We just igonre it.

 

Chris


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Okay
here’s the deal. I have this simple program (for now) that simply gets a few
variables, prints them to a text file, starts a new drawing, and runs a LISP
routine that simply reads those variables from the text file and presents an
alert box that says “HEY! I think It works.” More code will be added to that
later, to do a multitude of calculations and draw some “stuff”, but for now
this is how I begin most VBA/LISP programs. I have several that work on the
same concept, a VBA dialog box (or boxes) collect information, print it to a
text file and then a LISP r5outine reads that information and performs the
calculations and draws the object(s).

This one works fine but when I close AutoCAD after running it I get this
message.

Microsoft Visual C++ Runtime Library

     Runtime Error!

     Program C:\Program Files\AutoCAD
2002\acad.exe
     abnormal program termination

None of the other programs cause this, and I even get it when I have the
LISP routine unload the VBA project.

The main VBA code is
[Private Sub CmdOkay_Click()

If CboNumPocks.Value <> "" Then
    If
CboNumPocks.Value Mod 2 > 0 Then

        MsgBox "The number of
pockets MUST be an even number.", _

        vbExclamation, " Rollover
Wheel ERROR!"

        CboNumPocks.SetFocus

        Exit Sub

    Else

        IntNumPocks =
CboNumPocks.Value
    End If
Else

    MsgBox "You must enter the desired number of
pockets!", vbExclamation, _
    " Number of Pockets
ERROR."
    CboNumPocks.SetFocus

    Exit Sub
End If

If CboRollDia.Value = "" Then
    MsgBox "You must
enter the desired roll diameter!", vbExclamation, _

    " Roll Diameter ERROR."

    CboRollDia.SetFocus

    Exit Sub
Else

    DblRollDia = CboRollDia.Value
End If

If TxtProdLong.Value = "" Then
    MsgBox "You must
enter the product length!", vbExclamation, _
    "
Product Length ERROR."
    TxtProdLong.SetFocus

    Exit Sub
Else

    DblProdLong = TxtProdLong.Value
End If

If TxtProdWide.Value = "" Then
    MsgBox "You must
enter the product width!", vbExclamation, _
    "
Product Width ERROR."
    TxtProdWide.SetFocus

    Exit Sub
Else

    DblProdWide = TxtProdWide.Value
End If

StrRollWheel = "C:\RollWheel.txt"

IntFileNum = FreeFile

Open StrRollWheel For Output As #IntFileNum

        Print #IntFileNum,
IntNumPocks
        Print
#IntFileNum, DblRollDia

        Print #IntFileNum,
DblProdLong
        Print
#IntFileNum, DblProdWide
    Close
Unload Me

ThisDrawing.Application.Documents.Add ("L.dwt")

ThisDrawing.SendCommand "(if (not C:RollMe)(load ""RollMe"")) RollMe "

End

End Sub]

AND the LISP is
[(defun c:RollMe (/ A B C D File inspt)

  (setq File (open "C://RollWheel.txt" "r"))

  (setq A (read-line File))
  (setq B (read-line
File))
  (setq C (read-line File))
  (setq D
(read-line File))
  (close File)
  (setq Inspt
(getpoint "Select center Point; "))
  (alert "HEY! I think it's
working.")
  (command "vbaunload" "h:/VBA
Routines/RollOverWheels.dvb")

)]
Any ideas??

Thanks

Dave. K

0 Likes