Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arraylist in VB6

Status
Not open for further replies.

Sniipe

Programmer
Oct 9, 2006
115
IE
Hello all,

I use arraylists in vb.net in an application.
This application is called by a vb6 application and it falls over when it tries to deal with arraylists...
It would be easier to change the vb6 code rather than the .net code.
What would I need to do?
 
Not enough information.

What are you attempting to do, pass an arraylist directly to the VB6 application? That won't work, as it's not a structure recognized by VB6.

What's in the arraylist, basic types such as strings, or more complex objects?

I think you will need to add a method to your VB6 app that your .NET app can use to pass the data. If the data is simple, perhaps the method could accept a delimited string, which your VB6 app when then parse into an array for use internally.

You could also try using Interop, where you either wrap your .NET application as a "COM" object, or wrap your VB6 app as .NET assembly.

 
Of course ArrayLists are already exposed as COM objects in .Net anyway, so you may be able to do what you want all in your VB6 app. I have to agree though, not enough info.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hey Joe, thanks for your reply.

I will be passing a complex arraylist of objects directly into VB6.

At the moment I'm still working with the problem... I'm looking at something called VBCoreLib, but I'm still not getting the values populated.

I'm not overly familiar with Interop;

This unfortunately is two huge applications... The VB is the main application and the .net is an addon as such
 
This is VBScript because I'm too lazy to fire up VS, but this will show you how to use ArrayLists in a VB6 app:

Set oAList = CreateObject ("System.Collections.ArrayList")

oAList.Add "Foo"
oAList.Add "Bar"


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I'll try and give more information:

The .net application populates the arrayList correctly, but the value does not come back to the VB6 application

Code:
Set arrayPromos = Quote.getQualifyingPromotions
Set Quote.arrPromotions = Quote.GetQualifyingPromotions

If Quote.arrPromotions.Count > 0 Then
Quote is an object in the .net application and returns arrayList from getQualifyingPromotions
 
I have 2 SET above, I was just trying it two different ways... neither produce an answer.

would it be worth changing the function getQualifyingPromotions to return nothing, but just to populate Quote.arrPromotions???
 
Interop is pretty easy to use, especially if you have .NET Visual Studio. In your case you would be wrapping your .NET assemblies so they are appear as COM objects to VB6. Then you just reference these pseudo-COM objects in your VB6 code.

Make sure you reference all the .NET assemblies that your objects originate from.

 
ok, I don't know much about interop... but I can step into .net functions from the VB already...
 
could it be my class in .net?
Code:
public property ArrPromotions() As ArrPromotions Implements IclsQuote.arrPromotions
...

it has the same class name as the properties name which may confuse vb6?
 
This code worked just fine for me. Didn't need to add any refferences or anything:

Dim oAList As Object

Set oAList = CreateObject("System.Collections.ArrayList")
oAList.Add "Foo"
oAList.Add "BAR"

MsgBox oAList(0)



[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
<ok, I don't know much about interop... but I can step into .net functions from the VB already...could it be my class in .net?

You're saying none of the suggestions given work, therefore it's time for another hypothesis?

[ponder]
 
In addition to referencing System.Collections.ArrayList you will need to reference whichever (Interop wrapped) .NET assembly defines the objects that are in the ArrayList.

Take a look at your Visual Studio documentation for Interop. It's not that complicated, it just wraps your .NET assembly as a COM object, and with VS studio it's just a command or two to do.


 
Again, I will state that I ran the code that I listed without referencing anything additional. Opened a new product, wrote the code and ran it. Never even opened the references wizard.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
EBGreen - he could use your code to work with the ArrayList, but to work with the objects that are inside the ArrayList he would need to reference the appropriate assembly(s), which very likely are not in System.dll.


 
Aaah...misunderstood the issue being raised. My mistake.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I found the following registry key with a couple of values:
Code:
HKEY_CLASSES_ROOT\CLSID\{6896B49D-7AFB-34DC-934E-5ADD38EEEE39}\InprocServer32\1.0.5000.0 
Assembly=mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Class=System.Collections.ArrayList
I also find a large number (yet still a small subset of the total) of classes deriving from System in HKEY_CLASSES_ROOT. So it would seem that a number of .Net classes can be directly instantiated via COM.
 
Ehh...silly formatting here it is in code tags and I will request that the last post be deleted:

Code:
System.AccessViolationException
System.AppDomainManager
System.AppDomainSetup
System.AppDomainUnloadedException
System.ApplicationException
System.ArgumentException
System.ArgumentNullException
System.ArgumentOutOfRangeException
System.ArithmeticException
System.ArrayTypeMismatchException
System.BadImageFormatException
System.CannotUnloadAppDomainException
System.Collections.ArrayList
System.Collections.CaseInsensitiveComparer
System.Collections.CaseInsensitiveHashCodeProvider
System.Collections.Generic.KeyNotFoundException
System.Collections.Hashtable
System.Collections.Queue
System.Collections.SortedList
System.Collections.Stack
System.ContextMarshalException
System.ContextStaticAttribute
System.Data.SqlClient.SQLDebugging
System.DataMisalignedException
System.Diagnostics.Debugger
System.Diagnostics.StackFrame
System.Diagnostics.StackTrace
System.Diagnostics.SymbolStore.SymDocumentType
System.Diagnostics.SymbolStore.SymLanguageType
System.Diagnostics.SymbolStore.SymLanguageVendor
System.DivideByZeroException
System.DllNotFoundException
System.DuplicateWaitObjectException
System.EnterpriseServices.CompensatingResourceManager.ClerkMonitor
System.EnterpriseServices.CompensatingResourceManager.Compensator
System.EnterpriseServices.Internal.AppDomainHelper
System.EnterpriseServices.Internal.AssemblyLocator
System.EnterpriseServices.Internal.ClientRemotingConfig
System.EnterpriseServices.Internal.ClrObjectFactory
System.EnterpriseServices.Internal.ComManagedImportUtil
System.EnterpriseServices.Internal.ComSoapPublishError
System.EnterpriseServices.Internal.GenerateMetadata
System.EnterpriseServices.Internal.IISVirtualRoot
System.EnterpriseServices.Internal.Publish
System.EnterpriseServices.Internal.ServerWebConfig
System.EnterpriseServices.Internal.SoapClientImport
System.EnterpriseServices.Internal.SoapServerTlb
System.EnterpriseServices.Internal.SoapServerVRoot
System.EnterpriseServices.Internal.SoapUtility
System.EnterpriseServices.RegistrationConfig
System.EnterpriseServices.RegistrationHelper
System.EntryPointNotFoundException
System.EventArgs
System.Exception
System.ExecutionEngineException
System.FieldAccessException
System.FlagsAttribute
System.FormatException
System.Globalization.DateTimeFormatInfo
System.Globalization.GregorianCalendar
System.Globalization.HebrewCalendar
System.Globalization.HijriCalendar
System.Globalization.JapaneseCalendar
System.Globalization.JulianCalendar
System.Globalization.KoreanCalendar
System.Globalization.NumberFormatInfo
System.Globalization.StringInfo
System.Globalization.TaiwanCalendar
System.Globalization.ThaiBuddhistCalendar
System.IndexOutOfRangeException
System.InvalidCastException
System.InvalidOperationException
System.InvalidProgramException
System.IO.DirectoryNotFoundException
System.IO.DriveNotFoundException
System.IO.EndOfStreamException
System.IO.FileLoadException
System.IO.FileNotFoundException
System.IO.IOException
System.IO.IsolatedStorage.IsolatedStorageException
System.IO.MemoryStream
System.IO.PathTooLongException
System.IO.StringWriter
System.MemberAccessException
System.MethodAccessException
System.MissingFieldException
System.MissingMemberException
System.MissingMethodException
System.MTAThreadAttribute
System.MulticastNotSupportedException
System.NonSerializedAttribute
System.NotFiniteNumberException
System.NotImplementedException
System.NotSupportedException
System.NullReferenceException
System.Object
System.ObsoleteAttribute
System.OperationCanceledException
System.OutOfMemoryException
System.OverflowException
System.ParamArrayAttribute
System.PlatformNotSupportedException
System.Random
System.RankException
System.Reflection.AmbiguousMatchException
System.Reflection.AssemblyName
System.Reflection.CustomAttributeFormatException
System.Reflection.InvalidFilterCriteriaException
System.Reflection.ObfuscationAttribute
System.Reflection.TargetException
System.Reflection.TargetParameterCountException
System.Resources.MissingManifestResourceException
System.Resources.MissingSatelliteAssemblyException
System.Runtime.CompilerServices.CallConvCdecl
System.Runtime.CompilerServices.CallConvFastcall
System.Runtime.CompilerServices.CallConvStdcall
System.Runtime.CompilerServices.CallConvThiscall
System.Runtime.CompilerServices.CompilerGlobalScopeAttribute
System.Runtime.CompilerServices.DiscardableAttribute
System.Runtime.CompilerServices.IDispatchConstantAttribute
System.Runtime.CompilerServices.IUnknownConstantAttribute
System.Runtime.CompilerServices.MethodImplAttribute
System.Runtime.CompilerServices.NativeCppClassAttribute
System.Runtime.Hosting.ApplicationActivator
System.Runtime.InteropServices.ComConversionLossAttribute
System.Runtime.InteropServices.COMException
System.Runtime.InteropServices.ComImportAttribute
System.Runtime.InteropServices.ComRegisterFunctionAttribute
System.Runtime.InteropServices.ComUnregisterFunctionAttribute
System.Runtime.InteropServices.ExternalException
System.Runtime.InteropServices.InAttribute
System.Runtime.InteropServices.InvalidComObjectException
System.Runtime.InteropServices.InvalidOleVariantTypeException
System.Runtime.InteropServices.MarshalDirectiveException
System.Runtime.InteropServices.OptionalAttribute
System.Runtime.InteropServices.OutAttribute
System.Runtime.InteropServices.PreserveSigAttribute
System.Runtime.InteropServices.RegistrationServices
System.Runtime.InteropServices.RuntimeEnvironment
System.Runtime.InteropServices.SafeArrayRankMismatchException
System.Runtime.InteropServices.SafeArrayTypeMismatchException
System.Runtime.InteropServices.SEHException
System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute
System.Runtime.InteropServices.TypeLibConverter
System.Runtime.Remoting.Channels.ClientChannelSinkStack
System.Runtime.Remoting.Channels.ServerChannelSinkStack
System.Runtime.Remoting.Channels.TransportHeaders
System.Runtime.Remoting.Contexts.Context
System.Runtime.Remoting.Contexts.SynchronizationAttribute
System.Runtime.Remoting.InternalRemotingServices
System.Runtime.Remoting.Lifetime.ClientSponsor
System.Runtime.Remoting.Lifetime.LifetimeServices
System.Runtime.Remoting.Messaging.OneWayAttribute
System.Runtime.Remoting.Messaging.RemotingSurrogateSelector
System.Runtime.Remoting.Metadata.SoapAttribute
System.Runtime.Remoting.Metadata.SoapFieldAttribute
System.Runtime.Remoting.Metadata.SoapMethodAttribute
System.Runtime.Remoting.Metadata.SoapParameterAttribute
System.Runtime.Remoting.Metadata.SoapTypeAttribute
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapAnyUri
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapBase64Binary
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapDate
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapDay
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapDuration
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapEntities
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapEntity
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapId
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapInteger
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapLanguage
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapMonth
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapName
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNcName
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNegativeInteger
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNmtoken
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNonNegativeInteger
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNonPositiveInteger
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNormalizedString
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapNotation
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapPositiveInteger
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapQName
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapTime
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapToken
System.Runtime.Remoting.Metadata.W3cXsd2001.SoapYear
System.Runtime.Remoting.ObjRef
System.Runtime.Remoting.Proxies.ProxyAttribute
System.Runtime.Remoting.RemotingException
System.Runtime.Remoting.RemotingTimeoutException
System.Runtime.Remoting.ServerException
System.Runtime.Remoting.Services.EnterpriseServicesHelper
System.Runtime.Remoting.Services.TrackingServices
System.Runtime.Serialization.FormatterConverter
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
System.Runtime.Serialization.Formatters.InternalRM
System.Runtime.Serialization.Formatters.SoapFault
System.Runtime.Serialization.Formatters.SoapMessage
System.Runtime.Serialization.ObjectIDGenerator
System.Runtime.Serialization.OnDeserializedAttribute
System.Runtime.Serialization.OnDeserializingAttribute
System.Runtime.Serialization.OnSerializedAttribute
System.Runtime.Serialization.OnSerializingAttribute
System.Runtime.Serialization.OptionalFieldAttribute
System.Runtime.Serialization.SerializationException
System.Runtime.Serialization.SurrogateSelector
System.Security.AllowPartiallyTrustedCallersAttribute
System.Security.Cryptography.CryptoConfig
System.Security.Cryptography.CryptographicException
System.Security.Cryptography.CryptographicUnexpectedOperationException
System.Security.Cryptography.CspParameters
System.Security.Cryptography.DESCryptoServiceProvider
System.Security.Cryptography.DSACryptoServiceProvider
System.Security.Cryptography.DSASignatureDeformatter
System.Security.Cryptography.DSASignatureFormatter
System.Security.Cryptography.FromBase64Transform
System.Security.Cryptography.HMACMD5
System.Security.Cryptography.HMACRIPEMD160
System.Security.Cryptography.HMACSHA1
System.Security.Cryptography.HMACSHA256
System.Security.Cryptography.HMACSHA384
System.Security.Cryptography.HMACSHA512
System.Security.Cryptography.MACTripleDES
System.Security.Cryptography.MD5CryptoServiceProvider
System.Security.Cryptography.PKCS1MaskGenerationMethod
System.Security.Cryptography.RC2CryptoServiceProvider
System.Security.Cryptography.RijndaelManaged
System.Security.Cryptography.RIPEMD160Managed
System.Security.Cryptography.RNGCryptoServiceProvider
System.Security.Cryptography.RSACryptoServiceProvider
System.Security.Cryptography.RSAOAEPKeyExchangeDeformatter
System.Security.Cryptography.RSAOAEPKeyExchangeFormatter
System.Security.Cryptography.RSAPKCS1KeyExchangeDeformatter
System.Security.Cryptography.RSAPKCS1KeyExchangeFormatter
System.Security.Cryptography.RSAPKCS1SignatureDeformatter
System.Security.Cryptography.RSAPKCS1SignatureFormatter
System.Security.Cryptography.SHA1CryptoServiceProvider
System.Security.Cryptography.SHA1Managed
System.Security.Cryptography.SHA256Managed
System.Security.Cryptography.SHA384Managed
System.Security.Cryptography.SHA512Managed
System.Security.Cryptography.SignatureDescription
System.Security.Cryptography.ToBase64Transform
System.Security.Cryptography.TripleDESCryptoServiceProvider
System.Security.Cryptography.X509Certificates.X509Certificate
System.Security.HostProtectionException
System.Security.HostSecurityManager
System.Security.Permissions.GacIdentityPermission
System.Security.Permissions.HostProtectionAttribute
System.Security.Policy.AllMembershipCondition
System.Security.Policy.ApplicationDirectoryMembershipCondition
System.Security.Policy.ApplicationTrust
System.Security.Policy.Evidence
System.Security.Policy.GacInstalled
System.Security.Policy.GacMembershipCondition
System.Security.Policy.PolicyException
System.Security.Policy.TrustManagerContext
System.Security.SecurityException
System.Security.SuppressUnmanagedCodeSecurityAttribute
System.Security.UnverifiableCodeAttribute
System.Security.VerificationException
System.Security.XmlSyntaxException
System.SerializableAttribute
System.StackOverflowException
System.STAThreadAttribute
System.SystemException
System.Text.ASCIIEncoding
System.Text.StringBuilder
System.Text.UnicodeEncoding
System.Text.UTF7Encoding
System.Text.UTF8Encoding
System.Threading.Mutex
System.Threading.Overlapped
System.Threading.ReaderWriterLock
System.Threading.SynchronizationLockException
System.Threading.ThreadInterruptedException
System.Threading.ThreadStateException
System.ThreadStaticAttribute
System.TimeoutException
System.TypeLoadException
System.TypeUnloadedException
System.UnauthorizedAccessException
System.Version

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
In VB6 References, I found I could even reference the assemblies from my own projects. This means that either:

1. The .NET Framework exposes all assemblies as COM libraries
2. When VS2005 compiles it automatically makes a COM version of the assembly

I suppose one of us could read up on it, but what would be the fun of that?

 
EBGreen - he could use your code to work with the ArrayList, but to work with the objects that are inside the ArrayList he would need to reference the appropriate assembly(s), which very likely are not in System.dll.
This is whats happening, we can see the array list but not the objects within in
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top