TheSwamp
Code Red => .NET => Topic started by: Kerry on October 01, 2010, 05:42:50 PM
-
I had planned translating a couple of VBA routines to .NET today.
First glitch ....
My box is win7 x64 using ACADM2010 ACADM2011
AND I CAN"T READ THE .DVB 'cause I don't have the VBA enabler downloaded.
Before I download the enabler.
Has anyone had functionality problems using VBA on an x64 machine ???
-
I've not under vanilla 2010 and Vista
-
Thanks David.
-
This might give you some ideas
http://blogs.msdn.com/b/csharpfaq/archive/2010/09/28/converting-a-vba-macro-to-c-4-0.aspx
I like the alt + click trick in it
-
Thanks Jeff.
Now, where did I store my VB6 installation CD ??
-
Thinking about Migration ..
anyone heard from 'Mook' in Hawaii. ??
-
Not in a few years. I had a play with 7 and vba, slow, but functional. I printed all my stuff to pdf filed it away for conversion later.
edit: I should add that the 7 machine was a VM, so that might have caused more slowness than you will experience
-
Thanks David.
I only have a couple I want to Migrate, so no big issue ... and I've had some enquiries regarding translating some code, so I thought I'd better get my act together.
Not in a few years.
I assume that was regarding migration rather than having contact with Leslie. ?
-
Kerry I thought you had to download the vba from autodesk.
I had so much code to convert from vba to C# I wrote this
[CommandMethod("VtoC")]
public static void VbaToCsharp()
{
MessageBox.Show("starting");
// the file to read from.
string path = @"C:\Documents and Settings\Yourname\Desktop\VtoC.txt";
string readText = File.ReadAllText(path);
readText = readText.Replace("Option Explicit", "");
readText = readText.Replace("Exit Sub", "return;");
readText = readText.Replace("End Sub", "} //end");
readText = readText.Replace("End Function", "} //end");
readText = readText.Replace("Private", "private");
readText = readText.Replace("Public", "public");
readText = readText.Replace("End If", "}");
readText = readText.Replace("()", "()" + Environment.NewLine + "{");
readText = readText.Replace(" Sub ", "static void ");
readText = readText.Replace(" Function ", "static ");
readText = readText.Replace("If", "if(");
readText = readText.Replace("Then", ")");
readText = readText.Replace("Else", "else" + Environment.NewLine + "{");
readText = readText.Replace("ElseIf", "else if(");
readText = readText.Replace("Select Case", "switch(");
readText = readText.Replace("End Select", "}");
readText = readText.Replace("Case", "case");
readText = readText.Replace("For Each", "foreach (");
readText = readText.Replace(" In ", " in ");
readText = readText.Replace("On Error Resume Next", "");
readText = readText.Replace("Next", "} //next");
readText = readText.Replace("Not", "!");
readText = readText.Replace("While","while");
readText = readText.Replace("Wend", "}");
readText = readText.Replace("'", "//");
readText = readText.Replace("(0)", ".X");
readText = readText.Replace("(1)", ".Y");
readText = readText.Replace("(2)", ".Z");
readText = readText.Replace("String", "string");
readText = readText.Replace("Double", "double");
readText = readText.Replace("AcadBlockReference", "BlockReference");
readText = readText.Replace("False", "false");
readText = readText.Replace("GoTo", "goto");
readText = readText.Replace("On Error GoTo 0", "");
readText = readText.Replace("On Error GoTo Err_Control", "");
readText = readText.Replace("Set", "");
readText = readText.Replace("ThisDrawing.ActiveUCS = CurrentUcs", "");
readText = readText.Replace("Err_Control:", "");
readText = readText.Replace("Err.Clear", "");
readText = readText.Replace("Err.Number", "");
readText = readText.Replace("Resume", "");
readText = readText.Replace("Dim util As AcadUtility", "");
readText = readText.Replace("Set", "");
readText = readText.Replace("AcadLWPolyline", "Polyline");
readText = readText.Replace("AcadAttribute", "Attribute");
readText = readText.Replace("AcadCircle", "Circle");
readText = readText.Replace("AcadLWPolyline", "Polyline");
readText = readText.Replace("AcadLWPolyline", "Polyline");
readText = readText.Replace("Pi ", "Math.PI ");
readText = readText.Replace("Color", "ColorIndex");
readText = readText.Replace("True", "true");
readText = readText.Replace("MsgBox", "MessageBox.Show(");
File.WriteAllText(path, readText);
}
} //end test ////////////////////////////////
To use it you copy some code from vba to notepad and save it on your desktop.
Then run the code. It could do with a lot of work but it does save a little time.
If you copy code directly from vba you can crash.
I can definately see the point made, that is just as easy to rewrite it than convert it.
-
Actually, it has been a few years since I last spoke to Mook
-
First glitch ....
My box is win7 x64 using ACADM2010 ACADM2011
AND I CAN"T READ THE .DVB 'cause I don't have the VBA enabler downloaded.
Before I download the enabler.
Has anyone had functionality problems using VBA on an x64 machine ???
I had many problems with x64. To be fair I support 32bit XP systems and was trying to make the same code run on my 64bit system.
Between Win 7 (x64), VS 2010 (x64) and Acad 2011 (x64) I found it to be too much trouble and did a reinstall to 32.
If I didn't have to support 32bit I suppose I would just put my head down and work out all the issues.
Otherwise I don't see much ROI for the pain of 64.
Our drawings aren't very large, and we do have a great deal of legacy VBA.
-
I'm running ACADM2011 on Win 7 x64 with Visual Studio 2010 (admittedly without vba support) and the only issue I've had so far was debugging with C# - you have to add /p to the Command Line Arguments box on the debug page otherwise acad.exe automatically starts with the AutoCAD Mechanical profile and will cause all kinds of BS - at least, it caused 5 days+ of head scratching - I even sent my code to Kean Walmsley only to be told that it ran just fine on his vanilla 2011 installation. :pissed:
EDIT: Actually, just putting /p isn't enough. (Yet it was yesterday!?)
It seems you need to put "/p <<VANILLA>>" to force regular AutoCAD if you have AutoCAD Mechanical installed. As per the below:
(http://bigbeardy.co.uk/images/ACADM.PNG)
:)
-
Thanks I needed to do that too. Funny I dont use the quotes
/p Lex2010 /nologo /b GetThangs10.scr
-
If you run autocad with a certain profile, then launch autocad again it will use the last profile that you ran (assuming the shortcut you used to launch autocad does not force the profile with the /p switch). So if you run the autocad shortcut that comes with MEP. Close autocad. THen open vs project and launch autocad without any /p it will load up the 2D Drafting & Annotation profile.
But that still has not resolved my issues with Win7 64Bit and Autocad MEP 2011
-
Here is the error i get
Cannot load assembly. Error details: System.BadImageFormatException: Could not
load file or assembly 'file:///C:\Users\JJS\Documents\Visual Studio
2010\Projects\VbMgdAcadJJS\VbMgdAcadJJS\bin\Debug\Testing.dll' or one of its
dependencies. This assembly is built by a runtime newer than the currently
loaded runtime and cannot be loaded.
File name: 'file:///C:\Users\JJS\Documents\Visual Studio
2010\Projects\VbMgdAcadJJS\VbMgdAcadJJS\bin\Debug\Testing.dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark,
Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,
Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
at loadmgd()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure
logging.
To turn this feature off, remove the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog].
It shows up when in Autocad when I netload the debug.dll
-
Here is the error i get
Cannot load assembly. Error details: System.BadImageFormatException
Add this to your 2011 acad.exe.config.
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
-
you are awesome.
-
Kerry,
Are you looking for Mook specifically or for the VBA to VB translator he had made? If you remember what the name of it was, I can look and see if i might still have it.
JJS
-
Hi jj
Just wondering what became of 'mook'.
I think I have his translator in one of my archives, thanks.
Stay well
Kerry
-
hopefully i will be around more. I finally got a 64bit machine with enough oomph to run 2011. The problem is that none of my vba routines work very well because fo the 64 bit. SO i am going to have to start porting. I am also starting to use Autocad MEP for the electrical. It needs quite a bit of customization to make it fast. THings that should be a simple command line prompt are 6 mouse clicks all over the screen.
-
Hi all,
I realise this is slightly off-topic, so it might benefit from its' own thread, but it might save a whole heap of work for someone:
I was looking around for an Excel VBA Protection remover (I bought one a couple of years back but couldn't find the installer for it anywhere on my system) and stumbled across the following:
Removing an Excel Workbook VBA Password
A VBA project password can be removed with a hex editor. Close the workbook and open the workbook file in the hex editor. Find the string "DPB" and change it to "DPx". Save the file. Open the workbook and click OK until the workbook is open (one or more dialogs are displayed describing various problems with the VBA project). Press ALT+F11, choose the menu command Tools->VBAProject Properties, navigate to the Protection tab, and change the password but do not remove it (note the new password). Save, close, and re-open the workbook. Press ALT+F11 and enter the new password. Choose Tools->VBAProject Properties, navigate to the Protection tab, and remove the password. Save the workbook.
I couldn't quite believe it until I tried it on a new workbook myself. I've no idea if it will work on any other vba-created application, but feel free to give it a whirl.
:)
-
perfect! thank You
-
VBA is very slow in acad2011
-
I have been testing some of our VBA programs under Windows 7 with Autocad 2012. The first thing I found is that every one of them that ran using Randall's batch processing failed. Many of the VBA programs (not requiring batch processing) that strictly deal with changing properties of existing (common) entities, passed on the Win 7 computer with the VBA enabler installed. Although these will still need to be re-written in the future, they have moved down my priority list.
On the optimistic side of re-writing these programs is that many of the wish list items from my users can now be easily incorporated in the newer versions. As well as some of those "Oh man, I wish I had thought of that sooner".
Practice, practice, practice... Probably what I need the most of :-)