TheSwamp
Code Red => VB(A) => Topic started by: krampaul82 on February 18, 2011, 01:43:22 PM
-
Option Explicit
The following code works in visual Basic but I cannot seem to get it to work in vba 2010
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Public Function OpenFile(ByVal FileName As String) As Long
OpenFile = ShellExecute [This is where it hangs] (0, "Open", FileName, "", "C:\ALL_pdf_Cut_Sheets\Actuators\", 1)
End Function
Sub file_get()
OpenFile "C:\ALL_pdf_Cut_Sheets\Actuators\ms8105a1008.pdf"
End Sub
Any ideas appreciated...
Mark.....
-
For what it's worth, it works just fine in 2008. :|
-
I Always seem to get results that are not normal :x Do I need to have certian references checked?
-
The only references I have checked are the defaults for 2008.
-
What OS are you using? Is it the same one when you were using this previously?
-
Checks the return value of ShellExecute.
ShellExecute returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise.
Error codes:
http://msdn.microsoft.com/en-us/library/bb762153%28v=vs.85%29.aspx
Private Const ERROR_BAD_FORMAT As Long = 11
Private Const SE_ERR_ACCESSDENIED As Long = 5
Private Const SE_ERR_ASSOCINCOMPLETE As Long = 27
Private Const SE_ERR_DDEBUSY As Long = 30
Private Const SE_ERR_DDEFAIL As Long = 29
Private Const SE_ERR_DDETIMEOUT As Long = 28
Private Const SE_ERR_DLLNOTFOUND As Long = 32
Private Const SE_ERR_FNF As Long = 2
Private Const SE_ERR_NOASSOC As Long = 31
Private Const SE_ERR_OOM As Long = 8
Private Const SE_ERR_PNF As Long = 3
Private Const SE_ERR_SHARE As Long = 26
-
What OS are you using? Is it the same one when you were using this previously?
windows xp32 bit. The original code was written in visual basic 6.0 and i tried to get it to work in acad2010 vba (the add on.) and it hangs at the openfile = ShellExecute(0, "Open", FileName, "", "C:\gtc_proj\2008_Blocks\Valves\Honeywell\Product Link\", 1). The Run-time error says 49 Bad DLL calling convection.
any help appreciated.... at your convienence.... Mark
-
windows xp32 bit. The original code was written in visual basic 6.0 and i tried to get it to work in acad2010 vba (the add on.) and it hangs at the openfile = ShellExecute(0, "Open", FileName, "", "C:\gtc_proj\2008_Blocks\Valves\Honeywell\Product Link\", 1). The Run-time error says 49 Bad DLL calling convection.
any help appreciated.... at your convienence.... Mark
[/quote]
It's strange.
it works fine in my pc: XP SP3 32-bit + AutoCAD 2010
-
windows xp32 bit. The original code was written in visual basic 6.0 and i tried to get it to work in acad2010 vba (the add on.) and it hangs at the openfile = ShellExecute(0, "Open", FileName, "", "C:\gtc_proj\2008_Blocks\Valves\Honeywell\Product Link\", 1). The Run-time error says 49 Bad DLL calling convection.
any help appreciated.... at your convienence.... Mark
It's strange.
it works fine in my pc: XP SP3 32-bit + AutoCAD 2010
[/quote] I know! i have had many other quirks with other things in vba (things like this that work on other peoples machines but not mine!) very frustrating :realmad: I really should dump vba altogether but I have and extensive library of blocks that was set up in vb(a) and i know the boss will not shell out the bucks for vb.net program. If it was not for me they would still be on ACAD R13!
thank you for your input though.
Mark...
-
VB.Net is a free download for the express version - but at least there is a clue in your latest comments,
The bad calling convention sounds like the variable types are getting mangled in the API call. In .NET the behavior has changed and instead of Long, many times you have to use IntPtr.
-
VB.Net is a free download for the express version - but at least there is a clue in your latest comments,
The bad calling convention sounds like the variable types are getting mangled in the API call. In .NET the behavior has changed and instead of Long, many times you have to use IntPtr.
Does vb.net run like vb or vb(a)? I am not very good at vb(a) i usually hack what other people have done and taylor it to my needs. why do they always take a good thing and complicate it? (sorry for the rant) :| Mark...
-
The only thing similar to VB and VBA in VB.NET is the language, and there are some key differences. If you understand that, then porting your code to .NET is a pretty straightforward process, however, that being said, when using a .NET assembly in AutoCAD, you have to create an interface for your application because AutoCAD doesn't do that for you.
There are tons of examples showing how to build a .NET assembly and make it work in AutoCAD - add a few libraries and then build the command interface and you are done. (Yeah, I know .. if it were only that easy)
-
The only thing similar to VB and VBA in VB.NET is the language, and there are some key differences. If you understand that, then porting your code to .NET is a pretty straightforward process, however, that being said, when using a .NET assembly in AutoCAD, you have to create an interface for your application because AutoCAD doesn't do that for you.
There are tons of examples showing how to build a .NET assembly and make it work in AutoCAD - add a few libraries and then build the command interface and you are done. (Yeah, I know .. if it were only that easy)
does the express version handle that? i do not mind digging into it if it does...
-
It does, in fact, if you take your VBA code and paste it into the VB6 upgrade window, it will attempt to convert it for you. The only issue I had was most of the interfaces aren't available until you actually add the required libraries so you will probably have some types that don't convert properly.
Oh, and you have to make sure to install the .NET libraries for each version being used.
VS '10 Express comes with .NET 4.0 but I'm not sure if AutoCAD is fully compatable with this version - since I haven't built an AutoCAD assembly in well over a year ... and the last version I worked on was A2k8
Oh, if you get the entire VS package, you can also forray into C# ... it isn't hugely different from VB except in some of the code delimiters, and the fact that case is important (i.e. thisObject is different from thisobject) ... C# seems to be in-vogue right now ... although I never quite understood why, since VB.NET and C#.NET all get compiled to CLI anyway ... the reflector will convert the code between as needed with few modifications.
Good luck!
-
And, the licensing allows you to use the Express editions for corporate and for-profit (i.e. non-hobby programming) work.
-
It does, in fact, if you take your VBA code and paste it into the VB6 upgrade window, it will attempt to convert it for you. The only issue I had was most of the interfaces aren't available until you actually add the required libraries so you will probably have some types that don't convert properly.
Oh, and you have to make sure to install the .NET libraries for each version being used.
VS '10 Express comes with .NET 4.0 but I'm not sure if AutoCAD is fully compatable with this version - since I haven't built an AutoCAD assembly in well over a year ... and the last version I worked on was A2k8
Oh, if you get the entire VS package, you can also forray into C# ... it isn't hugely different from VB except in some of the code delimiters, and the fact that case is important (i.e. thisObject is different from thisobject) ... C# seems to be in-vogue right now ... although I never quite understood why, since VB.NET and C#.NET all get compiled to CLI anyway ... the reflector will convert the code between as needed with few modifications.
Good luck!
Could you provide a link for download?
-
To download the VB Express go to the Microsoft website:
http://www.microsoft.com/express/downloads/
click on the Visual Studios 2010 Express tab, then click the item "Visual Basic 2010 Express Edition". Make sure to select the language version of your choice and then select the Free Download icon to download the setup file to your computer.
-
To download the VB Express go to the Microsoft website:
http://www.microsoft.com/express/downloads/
click on the Visual Studios 2010 Express tab, then click the item "Visual Basic 2010 Express Edition". Make sure to select the language version of your choice and then select the Free Download icon to download the setup file to your computer.
Thank You Keith! I really appreciate all of your help, both past and present, It has made my life WAAAY easier... Mark