Author Topic: Vb to VBA  (Read 9257 times)

0 Members and 1 Guest are viewing this topic.

krampaul82

  • Guest
Vb to VBA
« 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.....

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Vb to VBA
« Reply #1 on: February 18, 2011, 01:48:28 PM »
For what it's worth, it works just fine in 2008.   :|
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

krampaul82

  • Guest
Re: Vb to VBA
« Reply #2 on: February 18, 2011, 01:54:53 PM »
I Always seem to get results that are not normal  :x Do I need to have certian references checked?

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Vb to VBA
« Reply #3 on: February 18, 2011, 02:06:04 PM »
The only references I have checked are the defaults for 2008.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Vb to VBA
« Reply #4 on: February 20, 2011, 01:17:49 AM »
What OS are you using? Is it the same one when you were using this previously?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

jgr

  • Guest
Re: Vb to VBA
« Reply #5 on: February 20, 2011, 01:47:14 PM »
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

krampaul82

  • Guest
Re: Vb to VBA
« Reply #6 on: February 21, 2011, 09:36:18 AM »
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

jgr

  • Guest
Re: Vb to VBA
« Reply #7 on: February 21, 2011, 10:32:44 AM »
 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

krampaul82

  • Guest
Re: Vb to VBA
« Reply #8 on: February 21, 2011, 11:34:36 AM »
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...

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Vb to VBA
« Reply #9 on: February 21, 2011, 11:57:01 AM »
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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

krampaul82

  • Guest
Re: Vb to VBA
« Reply #10 on: February 22, 2011, 09:09:24 AM »
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...

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Vb to VBA
« Reply #11 on: February 22, 2011, 10:15:28 AM »
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)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

krampaul82

  • Guest
Re: Vb to VBA
« Reply #12 on: February 22, 2011, 12:07:41 PM »
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...

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Vb to VBA
« Reply #13 on: February 22, 2011, 01:56:21 PM »
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!
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Vb to VBA
« Reply #14 on: February 22, 2011, 01:58:45 PM »
And, the licensing allows you to use the Express editions for corporate and for-profit (i.e. non-hobby programming) work.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}