hi
i have a problem in my vba and autolisp code and i hope to find a sloution of my problem here
my problem is :
IN VBA i have a function like -->
Public Function ShowMessage (str as string)
msgbox str
End Function
no i will use the lisp code to call my function by it
defun c:EB () ( vl-vbarun "C:/AMR LISP/AMRVB.dvb!MYMedoule.ShowMessage("hello")")
the red word is my problem how can i send this string to vba function by autolisp to show it in message
thanks for help
Solved! Go to Solution.
Solved by ProfWolfMan. Go to Solution.
Solved by Amremad. Go to Solution.
Hi,
As i know vl-vbarun function used to call vba macro only.
We can not call any function in the module directly from vl-vbarun.
We can call only macro.In which we can call other functions in that vba project.
-G
i have a lot of value for this function
say 100 value for one function
by ur solution i must create 100 function for each value so i will create 100 command for each function i think this is very hard to use
just i want to send alot of value for one function i hope u understand me
sorry for my english
Hi,
Only problem is vl-vbarun can call only macro which can not have arguments.
Here you do not need to create 100 functions.
You just create a macro set a looping function.
From that you call your function passing different value each time.
Now you can call that macro using vl-vbarun.
-G
I think you meant like this :
LISP Code :
(defun c:ax () (command "-vbarun" "C:/AMR LISP/AMRVB.dvb!ADVANCED_LIST.ShowMessage" "hello"))
VBA Code :
Public Function ShowMessage() Dim str As String Const HasSpaces = False str = UCase(ThisDrawing.Utility.GetString(HasSpaces)) MsgBox str End Function
S. You done that.
The fact is "Visual LISP and VBA has incompatable data types and you cannot to call VBA function with lisp argument".
Other way is you should get input within your vba function. Just call that function thru vl-vbarun.
-G
Hi,
You can use this routine to avoid using VBA.
;;; Val buttons ;;; 0 OK ;;; 1 OK Cancel ;;; 2 Abort Retry Ignore ;;; 3 Yes No Cancel ;;; 4 Yes No ;;; 5 Retry Cancel ;;; + icons ;;; 16 Alert ;;; 32 Question ;;; 48 Exclamation ;;; 64 Information ;;; ;;; Val return ;;; 1 OK ;;; 2 Cancel ;;; 3 abort ;;; 4 Retry ;;; 5 Ignore ;;; 6 Yes ;;; 7 No (defun MsgBox (title buttons message time / reply WshShell) (vl-load-com) (setq WshShell (vlax-create-object "WScript.Shell")) (setq reply (vlax-invoke WshShell 'Popup message time title (itoa buttons) ) ) (vlax-release-object WshShell) reply )
There is no relation between your VBA function and the alternative proposed by _gile. AS he says, this is the VLISP equivalent of the same MsgBox you wan to call in your VBA code, but using this alternative you don't need to deal with the VBA and LISP data compatibility issues. _giles solution is pure VLISP which uses ActiveX capabilities of VLISP and calls the Message box from the Windows Script Host. This code should be loaded and called as any other LISP programming.
And BTW, you should stop investing time in automating AutoCAD with VBA because Autodesk will discard VBA as an API for its products, so there will be no more VBA for AutoCAD in the near future.
Dear SomeBuddy
thank you very much for you help . but the Function ShowMessage was for an example
my problem was in parapmeter not ShowMessage Function , say also i have any other function like this DrawElbow (Type as string),DrawIPE(Size as string),i don't neet how can i showmessage box but i need to send a prameter for my VBA Function Using AutoLisp Command , i hope you understand me ,
I understand you, but I hope you understand too that there's no future in VBA (at least for AutoCAD), is dying, if not already dead.
But if you still want to invest time in this, then what you need is the Vlax.cls module by Frank Oquendo and you can read more about this at the following address, where you have examples and a link to download the class module.
http://autolisp-exchange.com/Forums/Forum6/F6T7P1.htm
Or you can read this:
Good luck
You would have to provide the arguments indirectly, such as through one of the USERnnn system variables, a registry entry, or an external file. The VBA code would then be able to read the data from that location.
Agressively mixing LISP and VBA this way makes for more trouble than its worth - go with one or the other. As mentioned its a good idea to keep VBA at arms length, as it will reduce the amount of work you will need to do later on.
As others here have said, it's true you can't do this:
(command "-vbarun" "C:/AMR LISP/AMRVB.dvb!ADVANCED_LIST.ShowMessage" "hello")
What you can do is this:
(defun c:ax () (setvar "users1" "hello")(command "-vbarun" "C:/AMR LISP/AMRVB.dvb!ADVANCED_LIST.ShowMessage"))
Then inside your vba, you can read users1 like this:
strHello = AutoCAD.Application.ActiveDocument.GetVariable("users1")
Is that what you wanted?