Results 1 to 12 of 12

Thread: vb6 arraylist type to vb.net

  1. #1

    Thread Starter
    Addicted Member t3cho's Avatar
    Join Date
    Mar 2014
    Posts
    234

    vb6 arraylist type to vb.net

    At vb6 i have a custom built list

    Code:
    Public Type ArrayList
       str1 As String
       str2 As String
       str3 As String
     End Type
    
    Dim dataList() As ArrayList
    
    dataList(0).str1 = "String 1"
    That is something i fill in vb6 object. Now i want to pass that to my vb.net object.

    I defined property at vb.net called
    Code:
    Public Property WarrantyDetails As ArrayList ...
    But when i reference my object it pop up error like

    Name:  fvjRD.png
Views: 1150
Size:  4.8 KB

    Which is the easiest way to pass data from vb6 object to .net object. Anything other than multidimensional array ??

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: vb6 arraylist type to vb.net

    Yeah, plenty, but this particular error is kind of interesting. There happens to be an object called an ArrayList that was built into .NET since the original version. It has been entirely deprecated since 2005, but it is still around. So, you were able to create an ArrayList in .NET, since it was the deprecated object, but it differs from what you created in VB6 in a couple different ways, which means that your conversion won't be quite as clear.

    What you had in VB6 would essentially be an array of structures. The structures were called ArrayList. You wouldn't want to create a structure with that name in .NET because that name is already in use. Of course, you could avoid the name conflict using namespaces, but that would be a bad idea, in this case, because the objects are so different...and you wouldn't want to be using ArrayLists in any version of .NET after 2005.

    What you could do is create either a structure or class with a name that is something other than ArrayList. I'd use a class, myself. It might look like this:

    Code:
    Public Class WeThreeStrings
     Public Property OfOrient As String
     Public Property R As String
     Public Property NoPunsHere as String
    End Class
    Then you would create a List(of WeThreeStrings):
    Code:
    Public carolSet As new List(of WeThreeStrings)
    that's about as far as I can take that example, because it isn't clear what the objective is. The point is that the Type in VB6 could be a Structure or Class in .NET. As a general rule, classes are used far more often than structures, even for simple things like that. There are some rules as to when to use a Structure and when to use a class, but you can also just say: Always use a class. Structures are value types, which means that there can be some real costs to passing them around if they have more than a couple simple members, and they will behave differently if held in an array. So, at the very least, there is more for you to think about if you use a structure. The savings may be a slight benefit in memory, though it would be VERY slight, and a slight performance benefit (possibly) in certain scenarios that would be a bit hard to identify without thorough testing. If there WAS a performance benefit, it wouldn't show up all the time, and would be so small that it wouldn't be detectable unless it happened millions of times. Thus, most people use classes rather than structures.

    The other point is the generics, for which there was nothing like them in VB6. The List(of T) is certainly the most common. In VB6, you had arrays and just arrays. If you wanted to change the size of an array, you used either Redim or Redim Preserve. These were ok, but had a cost. The cost is that arrays aren't mutable, so if you did resize an array, you were really creating a new array and copying the old one into the new. I believe that VB6 did this, as well, because the alternative would be hit or miss. The alternative is to extend the size of the existing array. Since an array is nothing more than a contiguous block of memory, you can only extend the size of an existing array up until the next used chunk of memory, so you may not be able to extend the size of an existing array because the neighborhood is full. Therefore, when you try to extend, what you really have to do is allocate a chunk of memory large enough for the new array and move everything over. That's what .NET does, and I'm pretty sure that VB6 would have had to do the same, since the problem has nothing to do with the language.

    So, the ArrayList was a way around this. An ArrayList does wrap an array, but it added Add, Insert, and Remove methods. The way it worked was that the array started at some size, and when you used up all the space initially allocated, then the object allocated new memory for an array twice that size, and copied all the data over. In other words, the array doubled in size any time it grew. This is an ancient algorithm that is efficient for the average usage of arrays. You never saw the size, though, or dealt with the sizing. All that was automatic. The drawback of the ArrayList was that it was not strongly typed. All it held was Objects, and that was inefficient.

    The generics were added in 2005. These are strongly typed. When you create a List(of WeThreeStrings), an implementation of List is created that can ONLY hold objects of the type that was supplied, whether that type is Integer, Date, String, or WeThreeStrings. The mechanism is the same as the ArrayList, but the list is strongly typed. Also, since an array is at the heart of a List, you can convert a List to an array by calling .ToArray.

    So, in .NET, you only use arrays when the number of elements will never change. If the number of elements can change, then you use a List. There are also a series of other generic collections, the most valuable of which is the Dictionary, but that's a different story.

    There is almost never any use for a multi-dimensional array in .NET, and the use of a multi-dimensional array is almost always a sign of an inefficient design. The only exception to that is that some data makes most conceptual sense in a 2D grid, such as rows and columns, or matrices.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member t3cho's Avatar
    Join Date
    Mar 2014
    Posts
    234

    Re: vb6 arraylist type to vb.net

    By reading this i assume maybe better method would be to use recordset to transfer data vb6 - .net object ? ..

    That would be the easiest way

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: vb6 arraylist type to vb.net

    That probably depends on how the information is stored. If it is stored in a database, then yes. If it stored in a text file, then maybe. Of course, a recordset is also a VB6 construct, but you can still use them in .NET and should be able to find tutorials on how to do so.

    On the other hand, that all starts with the assumption that the data is actually coming from some type of file. If it is a direct transfer of data from one running program to another, then there would be other alternatives, perhaps, such as XML, JSON, or just some kind of string passed via something like TCP or UDP.
    My usual boring signature: Nothing

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: vb6 arraylist type to vb.net

    Im confused, you keep saying
    transfer data vb6 - .net object ?
    Are you talking about converting VB6 code to .Net code? Or are you wanting to transer data from a running VB6 application to a running .Net application.

  6. #6

    Thread Starter
    Addicted Member t3cho's Avatar
    Join Date
    Mar 2014
    Posts
    234

    Re: vb6 arraylist type to vb.net

    Quote Originally Posted by wes4dbt View Post
    Im confused, you keep saying

    Are you talking about converting VB6 code to .Net code? Or are you wanting to transer data from a running VB6 application to a running .Net application.
    Runing vb6 to .net application. Data such as FirstName LastName Age.

  7. #7

    Thread Starter
    Addicted Member t3cho's Avatar
    Join Date
    Mar 2014
    Posts
    234

    Re: vb6 arraylist type to vb.net

    Quote Originally Posted by Shaggy Hiker View Post
    That probably depends on how the information is stored. If it is stored in a database, then yes. If it stored in a text file, then maybe. Of course, a recordset is also a VB6 construct, but you can still use them in .NET and should be able to find tutorials on how to do so.

    On the other hand, that all starts with the assumption that the data is actually coming from some type of file. If it is a direct transfer of data from one running program to another, then there would be other alternatives, perhaps, such as XML, JSON, or just some kind of string passed via something like TCP or UDP.
    I wouldn't go with XML and JSON formats because probbably it will change tomorrow ( expands some fields and so ) . Expanding one field in json is quite a job.

  8. #8
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: vb6 arraylist type to vb.net

    So you want to export data from a VB6 app and import the data using a .Net app. So as SH said, is this data in a database/XML/Text ... file or is this live entry, non stored data. The next question might be why not just do it all in .Net.

  9. #9

    Thread Starter
    Addicted Member t3cho's Avatar
    Join Date
    Mar 2014
    Posts
    234

    Re: vb6 arraylist type to vb.net

    The point is i have a plenty of vb6 objects.

    Now i need to create a universal .net object. The point of that object is to print the data about products (Word,Excel) such as ( Code, ProductName, SerialNumber).

    Those product details was read from different tables depending from object to object, So i cant use query in my universal vb.net object. I thought about read details in vb6 object from database and then pass it to vb.net object just to print.

  10. #10
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: vb6 arraylist type to vb.net

    It would honestly be faster, and most likely far easier to re-create it in .NET. It takes 4 lines to read data from a database, and it reads it far faster and more efficiently than any of the methods from the VB6 days.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: vb6 arraylist type to vb.net

    I never worked with XML when I was working in VB6, and I had never even heard of JSON back then, so I don't know what is available. Working with JSON isn't so tough these days with the various libraries, but it wouldn't surprise me if VB6 never had a good library for JSON, due to the timing. XML, on the other hand, is something that I would expect VB6 to handle pretty well. If there is a good XML library for VB6, that may well be the easiest route, as .NET would allow you to query a well formed XML file much like a database. In fact, if the formation was right, you could bring an XML into a .NET datatable with a single line (ReadXML). So, if there is a good XML library for VB6, that may well be the easiest solution.

    Another option that I know you can do with VB6 is a CSV file. That would likely be a somewhat clumsier solution in VB6, since there wouldn't be any library helping out. I would assume that you'd have to do the work yourself, in that case, though it's usually not terribly difficult. ADO.NET can query a CSV file as a database, so drawing that data into a .NET datatable would be simple.

    On the other hand, it seems like either solution would be better off having a database behind it, based on your description. If the data were all in a database, then it wouldn't really matter whether the program that dealt with it was VB6, .NET, something else, or a combination of multiple things.
    My usual boring signature: Nothing

  12. #12
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: vb6 arraylist type to vb.net

    So i cant use query in my universal vb.net object
    Why? Because you don't know how or is there another reason?

    Also when you say "universal vb.net object" are you talking about a DLL or an Application (EXE).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width