VB6 Copy Array AutoCAD - vb.net

I'm in the process of transfering our VBA AutoCAD script to VB.NET but i came across a warning. VB.net 2010 give me a warning that this code is obsolute, and probally won't work with 64 bit.
The program needs to be 64 compatibel because of the problems with our vba file and AutoCAD 2012 & Windows 7 X64. What do i need to use instead of VB6.CopyArray?
If Flipline = True Then
P1 = VB6.CopyArray(Endpoint)
P2 = VB6.CopyArray(Beginpoint)
Else
P1 = VB6.CopyArray(Beginpoint)
P2 = VB6.CopyArray(Endpoint)
End If

According to MSDN documentation for Support.CopyArray:
The Visual Basic 6.0 Variant data type is no longer supported in Visual Basic 2010. The CopyArray function is used by the upgrade tools to copy an Array to or from a Variant array.
To copy an array in Visual Basic 2010, use the Clone, Copy or CopyTo methods of the Array class.
Array.Clone Documentation
If Endpoint is an array, then:
P1 = Endpoint.Clone()

Related

Telling VBA to look at 64-bit registry view

I want to assign an ArrayList to a variable.
Sub Create_ArrayList()
Dim arrL As Object
'Creating an ArrayList, option 1 - fails
Set arrL = CreateObject("System.Collections.ArrayList")
'Creating an ArrayList, option 2 - fails
Set arrL = GetObject("New:{6896B49D-7AFB-34DC-934E-5ADD38EEEE39}")
End Sub
Both options fail :
Run-time error '-2146232576 (80131700)':
Automation error
I found that the CLSID exists in the registry in HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID
The Office is 32-bit and Windows is 64-bit. I am not familiar with the registry, but it seems from what I have read, that 32-bit Office is trying to find ArrayList in some 32-bit Windows location (view), while it actually is in 64-bit location. Can it be the case? How to make the application get ArrayList from the correct location?
It seems, to access an alternative registry view, I should somehow use the flag KEY_WOW64_64KEY (value 0x0100), but the examples that I found are too big to comprehend (eg1, eg2). I don't want to edit registry data, I only want to tell VBA that I am using 64-bit Windows, so the object that I need is to be found somewhere else than it expects.

Upgrading project to Visual Studio 2015 causes errors with Enums

I have a VB.NET project targeting framework 3.5 that references a dynamic DLL of compiled enums generated from a database. My project compiles and runs in Visual Studio 2012. I am beginning to upgrade my solutions to Visual Studio 2015 and ran in to a bunch of errors when I tried doing this project.
The two errors I get for just about every enum are
Operator '=' is not defined for types MyEnumType and MyEnumType
Field MyEnumType.Field has an invalid constant value
Viewing the definition of the enum meta data (which I can do in 2015 but not 2012) I see it being defined as
Enum EnumName as Object
Field1
Field2
End Enum
As you can see its appending As Object which I've never seen before. But that explains the operator = error because if it's an object than you would have to define an overloaded Equals operator.
I'm just seeing if anyone has any insight or know of anything in 2015 that would be causing this issue. I tried creating a new project an importing the .DLLs just to see if they worked at all in VS 2015. They work when referenced in C# but not in VB.NET. The .DLLs were written and compiled in VB.NET. S
For the time being I can still use 2012, but would like to upgrade to 2015 in the future and not have to rewrite a bunch of things.
EDIT:
Here is the (simplified) code that is being used to create the enum .DLL. An xml is being read with the Enum name and sql query used to generate the enum.
Dim myEnumBuilder As Emit.EnumBuilder
Dim myAppDomain as AppDomain
Dim myModuleBuilder As ModuleBuilder
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = EnumDll.Name
' Create a dynamic assembly.
myAssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Save, msOutputDirectoryPath)
' Create a dynamic module.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("Library." & EnumDll.Name, EnumDll.Name & ".dll")
' Creating a dynamic Enum.
myEnumBuilder = myModuleBuilder.DefineEnum(EnumDll.Name & "." & EnumName, TypeAttributes.Public, GetType(Int32))
Dim myFieldBuilder As FieldBuilder = myEnumBuilder.DefineLiteral(StrEnum, CInt(oReader(0)))
myEnumBuilder.CreateType()
myAssemblyBuilder.Save(EnumDll.Name & ".dll") 'save the dll

Get list of all properties for an Excel object in Windows 10

I would like to list all properties for an Excel Chart object, and I found a question with a solution:
Get list of all properties for an object
but it seems that this solution does not work on Windows 10 (and I think it does not work on Windows 7). The dll for TypeLib Information is apparently not compatible with Windows 10.
I use Office 2003, 2010 and 2013, and Windows 7 and 10. If you have a suggestion then please specify which version your suggested solution is tested on or expected to work on.
I haven't found an answer for VBA, but in AutoIt autoit it is possible to do something like this (requires that you select the first property in the Object browser (e.g. select Activate of the Chart object).
#include <GuiListBox.au3>
_ReadItems()
Func _ReadItems()
const $delay=100
;;get handle to Object Browser window
$hwnd=WinWait("Microsoft Visual Basic - Book1 - [Object Browser]")
;;get handle to Object list box
Local $hLB = ControlGetHandle($hwnd,"","[CLASS:ListBox; INSTANCE:3]")
;;get handle to "property information box"
Local $hInfo= ControlGetHandle($hwnd,"","[CLASS:RichEdit20A; INSTANCE:1]")
Local $sMsg = ""
Local $text=""
;; loop through all items in list
Local $iCnt =_GUICtrlListBox_GetCount ( $hLB )
For $n = 0 To $iCnt - 1
sleep($delay)
;;copy text in information box
ControlFocus($hWnd, "",$hInfo)
sleep($delay)
send("^a")
sleep($delay)
send("^c")
sleep($delay)
$text= ClipGet()
;;move down in object list box
send("+{TAB}")
sleep($delay)
send("{DOWN}")
;;add information to result string
$sMsg &= $text & #CRLF
Next
;;put result on clipboard
ClipPut($sMsg)
EndFunc ;==>_ReadItems

Error 438 from using Filesystemobject.OpentTextFile but not on my computer

Note: I'm new to using Visual Studio and writing code outside of VB6 and VBA. Also, I've resolved my problem by using IO.File.
However, I really want to learn why this wouldn't work:
Dim FSO As New FileSystemObject
Dim FSOts As TextStream
FSOts = FSO.OpenTextFile(filepath1, IOMode.ForReading, True)
While FSOts.AtEndOfStream = False
temp = FSOts.ReadLine()
MsgBox(temp)
tempcollection.Add(temp)
End While
FSOts.Close()
It works on my computer, but for some reason it won't on others. I've used this object in a vb script before but in that situation the 2nd argument was 'ForReading' and was written in a different IDE (FEMAP) which referenced the 32bit scrrun.dll. In Visual Studio I noticed the scripting library is pointing to syswow64; I'm not sure if that makes any difference. All distributed sites run 64 bit OS and have this library. In any case I get an error 438 when I try to use:
FSOts = FSO.OpenTextFile(filepath1, IOMode.ForReading, True)
VS will not let me compile it with just 'ForReading'.
Again, I've used this object before in vb6 but the 2nd argument was not iomode.forreading but 'ForReading'. In that situation it worked fine on the same machines that are giving me problems (except for mine of course!).

Cannot instanciate a NotesUIWorkspace from VBA (Word)

The source situation: I have an Notes Application which uses MS Office 2000 under Windows XP. The new situation has to be MS Office 2010 under Windows 7. IBM Notes is 8.5.3FP3.
The old one uses a VBA template to communicate with Notes which works properly. At one time a Notes.NotesUiWorkSpace object is created to open a document, navigate to a richtext item, select all the content (formatted) and copy to the clipboard. Then the clipboard content ist pasted into the Word document via VBA. That works fine.
The same code in the second environment doesn't work anymore. I noticed that the Notes.NotesUIWorkSpace object cannot be instanciated in VBA. No errors, no hints. Only the runtime error when I reference the workspace-object later.
Here is a code excerpt:
' this is a profile document which is filled correctly
Call prof.Save(True, True)
Call prof.replaceItemValue("Form", "Profile")
' setting up the ui
dim WS as Object
set WS = CreateObject("Notes.NotesUiWorkSpace")
Set uiprof = WS.EditDocument(True, prof)
' Set uiprof = WS.currentDocument
If uiprof.editMode Then Call uiprof.gotofield("RT")
Call uiprof.SelectAll
Call uiprof.Copy
Call uiprof.Close
' later on the clipboard will be pasted into the word document
Any ideas what could be the cause here? I am setting up an environment with XP, MS Office 2010 and Notes tonight to check it out that it is not caused by Windows 7.
If the Windows 7 machine is 64 bit, take a look at the answers here. Note that those refer to the COM classes (lotus.), and you are using the OLE classes (notes.), but I believe the 64/32 bit issue applies to both.