Page 1 of 2 12 LastLast
Results 1 to 40 of 65

Thread: Can anyone write an array module?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,634

    Can anyone write an array module?

    As we all know, the array is the most important data structure in programming. Nevertheless, because vb6/VBA is too old, arrays are basically in their most primitive state, so there are all kinds of common methods for arrays-none of them!

    And what about JS arrays? There are dozens of methods, such as commonly used array concatenation (join), addition and deletion (splice), sort (sort), filter (filter), judgment (some/every), search (find), merge (concat), fill (fill) ), flat and map, forEach, etc.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,634

    Re: Can anyone write an array module?

    The problem comes from :
    When WPS starts to support JS language, what should Microsoft Excel do?
    https://mp.weixin.qq.com/s?__biz=MzI...21969c8e402452

    The guy from Microsoft talked all day long. One said that Excel supports R, one said that it supports Python, and the other said that it supports JS... but it didn't support anything; WPS silently supported JS without a sound. Just want to ask Microsoft's big breasted brother, are you surprised or surprised?

    This year Microsoft will launch Office 2021, but it hasn't seen any changes to the scripting language; now WPS has fired its first shot, which is even more interesting. Is Microsoft talking to JS? Or does it support Python? Or do you support both by gritting your teeth?
    Last edited by xiaoyao; Oct 12th, 2021 at 03:28 PM.

  3. #3
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    540

    Re: Can anyone write an array module?

    yes anyone can create an array module. Vb has the capability to create everything you need.

    We are our own architect.

    I am sure we have all created our own helper functions for what we needed already.
    Here are two of my favorites

    Code:
    Sub push(ary, Value) 'this modifies parent ary object
        On Error GoTo Init
        Dim X
           
        X = UBound(ary)
        ReDim Preserve ary(X + 1)
        
        If IsObject(Value) Then
            Set ary(X + 1) = Value
        Else
            ary(X + 1) = Value
        End If
        
        Exit Sub
    Init:
        ReDim ary(0)
        If IsObject(Value) Then
            Set ary(0) = Value
        Else
            ary(0) = Value
        End If
    End Sub
    
    Function AryIsEmpty(ary) As Boolean
      On Error GoTo oops
      Dim X
        If IsObject(UBound(ary)) Then AryIsEmpty = False
        'x = UBound(ary)
      Exit Function
    oops: AryIsEmpty = True
    End Function
    Last edited by dz32; Oct 12th, 2021 at 05:14 AM.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,634

    Re: Can anyone write an array module?

    vb.net has been continuously upgraded for about 20 years, which is really rare. It is estimated that the array and other functions are very complete. VB1, vb3, vb5.0, and vb6 have only been developed for about 6 years and then stopped updating and no more new functions are added?
    Last edited by xiaoyao; Oct 12th, 2021 at 03:15 PM.

  5. #5
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    540

    Re: Can anyone write an array module?

    if by very complete you mean full of extra garbage you will rarely use then yes .net is very very complete.

    One of the reasons people may prefer classic vb is because it is not bloated. We can choose what we want to
    include and can build what we need. We do not need everything given to us and most of us are old and come from
    a time where it was expected we had to create our own libraries.

    Vb6 will live as long as there are virtual machines. No one can estimate when it will die on current supported Windows OS.
    It will probably live until there is no more 32bit code.

    You must see value in vb6 or you would not be here?

  6. #6
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    694

    Re: Can anyone write an array module?

    Quote Originally Posted by xiaoyao View Post
    vb.net has been continuously upgraded for about 20 years, which is really rare.
    Rare? Hardly?
    Our Friends in Redmond actively maintain and enhance all their Products, right up to the point where they choose not to.

    Look at .Net Framework 1.1. Launched in 2003, it should have lasted until 2013, under their normal, 10 year Product lifecycle.
    And yet, in 2009, a full 4 years early, Microsoft announced that they were "no longer supporting" it and that everybody should port their code to Framework 2.0 immediately. (In their defence, they simply couldn't "bend" Fx1.1 any further to meet the ever-evolving Security standards of the day but, for many, the jump to 2.0 was not trivial).

    Quote Originally Posted by xiaoyao View Post
    It is estimated that the array and other functions are very complete.
    Estimated by whom, exactly?
    Sure, there are lots of array functions and there have been lots of years for them to add new ones as they felt the need.
    A "mature set of functions" might a better description.

    Quote Originally Posted by xiaoyao View Post
    VB6 will be destroyed in about 6 years, right?
    Officially, it's been dead and buried for nearly two decades already!

    It was "discarded" from Microsoft's WorldView with the very first release of the .Net Framework, way back in 2002!
    There was even a "proper" VB7 in the works at that time, but it was thrown in the bin in their mad dash to "dot-Net-ift" the entire World.

    And yet VB "Proper" is still here, still works, and is still going strong.

    Regards, Phill W.

  7. #7
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,683

    Re: Can anyone write an array module?

    Quote Originally Posted by Phill.W View Post
    And yet VB "Proper" is still here, still works, and is still going strong.
    Besides, one can of course use a "Class-Framework" with VB6 as well.
    (e.g. via RC5 or RC6, which is two orders of magnitude smaller than the .NET-class-framework)

    The cArrayList-class offers nearly all the features of the "js-array-objects", mentioned in the opener-posting.

    Olaf

  8. #8
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,594

    Re: Can anyone write an array module?

    also, why should we write an array module?
    most of the time we create functions depending on the needs, I dont need 100 different array functions when maybe I just use 3-4 different methods, I simply create those 3-4 methods in a couple of minutes and my focus is on the project.

  9. #9
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,235

    Re: Can anyone write an array module?

    xiaoyiao is trolling...
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  10. #10
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,421

    Re: Can anyone write an array module?

    Quote Originally Posted by yereverluvinuncleber View Post
    xiaoyiao is trolling...
    Don't believe it because the thread is not started in the CodeBank, no? :-))

    cheers,
    </wqw>

  11. #11
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,709

    Re: Can anyone write an array module?

    Quote Originally Posted by wqweto View Post
    Don't believe it because the thread is not started in the CodeBank, no? :-))

    cheers,
    </wqw>
    And it's not quoting some weird chinese statistics.....

    As for his first post:
    dz32, baka and Olaf have said what there is to say about this.

    If you want an Array to be an Object/Class (Notice his "ForEach"), write your own.
    Some of those Features already exist (Join, Filter), others don't, but are available on the net as free source (Does anyone know how many sorting-algorithms there are?).

    But why anybody would want an Array to behave like an object escapes me.....
    Last edited by Zvoni; Oct 12th, 2021 at 09:13 AM.
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,634

    Re: Can anyone write an array module?

    Everyone is welcome to contribute source code together. Everyone writes a function, 10, 20 functions will come out immediately, everyone can use it.

    Recharge the array and return the sequence number array

    Code:
    Function SortLongSz(bySz,optional byref Idsz)
     
    Dim KeepChecking As Boolean
    Dim i As Long
    Dim FirstValue
    Dim SecondValue
    Dim id1 As Long
    Dim ID2 As Long
    Dim ub As Long
    Dim Ub2 As Long
    KeepChecking = True
    ub = UBound(bySz)
    Ub2 = ub - 1
    FiLLidSz Idsz, ub
    
    While KeepChecking
        KeepChecking = False
        For i = 0 To Ub2
     
            If bySz(i) > bySz(i + 1) Then
                    FirstValue = bySz(i)
                    SecondValue = bySz(i + 1)
                    id1 = Idsz(i)
                    ID2 = Idsz(i + 1)
                    bySz(i) = SecondValue
                    bySz(i + 1) = FirstValue
                    Idsz(i) = ID2
                    Idsz(i + 1) = id1
                    KeepChecking = True
            End If
        Next
    Wend
    SortLongSz = bySz
    End Function
    
    Sub FiLLidSz(Sz, SzUb As Long, Optional startid As Long)
    '[mycode_id:537],edittime:2007-2-10 下午 05:09:05
    '1,2,3,4,5
    On Error Resume Next
    ReDim Sz(SzUb)
    Dim i As Long
    For i = startid To SzUb
        Sz(i) = i
    Next
    End Sub

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,634

    Re: Can anyone write an array module?

    Just like VB.NET, system.*** in C#
    There may be hundreds or thousands of functional modules, even if there are only 10 commonly used modules, many people will use other functions.
    The advantage of the module is that, we only need to call it. Isnít it more convenient to have 30 functions? We only need to learn to use the 5 functions in it, and just delete the ones that are not needed. Of course, the more functions, the better.

    Just like WIN10 is good, but WIN8 my computer only occupies 5G space, C drive occupies less and runs faster.
    The original version of VB6 is 200M. I use the simplified version of the installation package, which only requires 10mb.
    He has many other functions, and people who use it can't do without him, but 10MB is enough for ordinary people.

    The SQL SERVER 2008 installation package may be 1GB, but the core functions are simplified to only 30MB.
    All the functions are done well, and we can take what we need.
    Just like someone in CODEBANK uploaded a huge source code package, which may have been left behind when another VB and other development language forums closed down, there are tens of thousands of source code examples. There are always some that we need, and it is up to everyone to sort out the essence, commonly used functions and modules.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,634

    Re: Can anyone write an array module?

    Code:
    Function Arr_BinToHex(Bin() As Byte, Optional Fg As String = ",") As String
    Dim i As Long
    Dim SZ() As String
    ReDim SZ(UBound(Bin))
    For i = 0 To UBound(Bin)
        SZ(i) = IIf(Bin(i) < 16, "0", "") & Hex(Bin(i))
    Next
    Arr_BinToHex = Join(SZ, Fg)
    End Function

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,634

    Re: Can anyone write an array module?

    Quote Originally Posted by Schmidt View Post
    Besides, one can of course use a "Class-Framework" with VB6 as well.
    (e.g. via RC5 or RC6, which is two orders of magnitude smaller than the .NET-class-framework)

    The cArrayList-class offers nearly all the features of the "js-array-objects", mentioned in the opener-posting.

    Olaf
    This DLL is also very convenient, but there are some open source function modules which are also good. If there are 30 functions for array operations, we only use 5, and we can delete the other functions. Some people may need the other 8, and you can choose what you need.

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,634

    Re: Can anyone write an array module?

    I have seen a lot of examples of PYTHON calling OPENCV, WEBSOCKET, etc.
    The advantage of py is that you can download any modules you want, and you don't need to install a 5GB framework like .NET at once.
    So the glue language is getting stronger and stronger, and it is cross-platform.
    It's not because he runs fast, in fact, he is really slow.
    But it is like VBS, it can createobject ("***") call a large number of third-party COM DLL or API, or form UI components, or control IE, control Google browser.
    One sentence can be read aloud by voice. If one sentence can be recorded, one sentence can be converted into text.
    Is it convenient for a code to be taken by the camera and a code to be converted into text OCR?

    What we need is a large number of functions (everyone only chooses a small amount to use)

  17. #17
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    694

    Re: Can anyone write an array module?

    Quote Originally Posted by xiaoyao View Post
    Function SortLongSz(bySz,optional byref Idsz)
    Why would anybody writing in VB6 bother to write such a function when you can do the job perfectly well with two hidden, sorted ListBoxes, linking the two together with the ItemData property?

    Every language has its own strengths and weaknesses. Embrace them.
    Don't waste your time railing against them or trying to make one language work "like" another one. You'll always wind up with the worst of both.
    • If you want to write in .Net, then go write in .Net.
    • If you want to write in VB "Proper", then learn how to use its strengths to your advantage.


    Regards, Phill W.

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,634

    Re: Can anyone write an array module?

    Because there are 2 or more arrays. Sort an array of integers and get the sorting sequence number, and then sort another array.

  19. #19
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    694

    Re: Can anyone write an array module?

    Quote Originally Posted by xiaoyao View Post
    Sort an array of integers and get the sorting sequence number, and then sort another array.
    Mission accomplished.

    Regards, Phill W.

  20. #20
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,661

    Re: Can anyone write an array module?

    Quote Originally Posted by Phill.W View Post
    Why would anybody writing in VB6 bother to write such a function when you can do the job perfectly well with two hidden, sorted ListBoxes, linking the two together with the ItemData property?
    This is precisely why this thread is a waste of time. VB6 developers would rather do the above than do this:-
    Code:
            'Not a ListBox in sight!!!
            Dim unsorted As Integer() = {23, 90, 25, 40, 16, 4}
            Dim sorted As Integer() = unsorted.OrderBy(Function(i) i).ToArray
    VB6 programmers have learned to enjoy doing things the hard way.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  21. #21
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,661

    Re: Can anyone write an array module?

    Quote Originally Posted by xiaoyao View Post
    As we all know, the array is the most important data structure in programming. Nevertheless, because vb6/VBA is too old, arrays are basically in their most primitive state, so there are all kinds of common methods for arrays-none of them!

    And what about JS arrays? There are dozens of methods, such as commonly used array concatenation (join), addition and deletion (splice), sort (sort), filter (filter), judgment (some/every), search (find), merge (concat), fill (fill) ), flat and map, forEach, etc.
    My advice to you xiaoyao is to just bite the bullet and go to C#, VB.Net, Java or whatever else is out there that hasn't stagnated for 20 years. Don't waste your time on efforts like this.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  22. #22
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,661

    Re: Can anyone write an array module?

    Quote Originally Posted by Zvoni View Post
    But why anybody would want an Array to behave like an object escapes me.....
    It's more consistent. It more perfectly aligns to what an array actually is, which is just a pointer to a contiguous block of memory. Objects have also been traditionally just pointers to blocks of memory. Treating an array as a value type like VB6 does just leads to problems because on a fundamental level they are most certainly not value types. An array is an object.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  23. #23
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,594

    Re: Can anyone write an array module?

    not sure but I dont have any problems with arrays.
    the only "issue" that I know of is the empty array check. theres different workaround but still workarounds.
    to sort, we have many different sorting algorithms, to move around, is also very easy using a temp variable, to change between bytes and string theres a few methods we can use,
    and we can create quite complex UDT, what else is there to do?

    initialization, really, the best is to have an external source, instead of adding it in the code.
    why would I do: dim a as integer() = "10,20,30"?
    if theres a need to have specific numbers in one array, you can read it from an external data file, so that u can change it there instead of add it hard coded.
    most of my stringtable/values are from external sources, thats how I program, so initialization that way is not needed.

  24. #24
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,661

    Re: Can anyone write an array module?

    Quote Originally Posted by baka View Post
    not sure but I dont have any problems with arrays.
    the only "issue" that I know of is the empty array check. theres different workaround but still workarounds.
    to sort, we have many different sorting algorithms, to move around, is also very easy using a temp variable, to change between bytes and string theres a few methods we can use,
    and we can create quite complex UDT, what else is there to do?

    initialization, really, the best is to have an external source, instead of adding it in the code.
    why would I do: dim a as integer() = "10,20,30"?
    if theres a need to have specific numbers in one array, you can read it from an external data file, so that u can change it there instead of add it hard coded.
    most of my stringtable/values are from external sources, thats how I program, so initialization that way is not needed.
    Most of you won't get it. That's understandable. When you've used languages like C# or Java for years, it's really jarring and quite off-putting when you comeback to something more primitive like VB6 when you've grown accustomed to the freedom you have in modern frameworks like .Net when it comes to dealing with arrays. I mean just for fun let me show you what xiaoyao is talking about. Lets just do some random things with arrays. I'll use VB.Net as an example.

    Lets say you have an array of names, perhaps from a file or maybe you got then through an HTTP request and you want to sort it and make them all uppercase. You can easily do it like this:-
    Code:
            'Pretend you read this from a file or something
            Dim names As String() = {"John", "Anton", "Mary", "Zyra", "Ashe", "Pinky"}
    
            Dim sortedNames As String() = names.
                                          OrderBy(Function(n) n).
                                          Select(Function(s) s.ToUpper).ToArray
    What about something simpler that requires a whole song and dance in VB6, checking if an array has been initialized or not. In VB6 this requires a bunch of tricks or error traps but in .Net:-
    Code:
            Dim myArray As Integer()
    
            'Prints "No array" because myArray is nothing
            If myArray Is Nothing Then Debug.WriteLine("No array")
    But what about an empty array? Well you can also check for that using short circuit logic:-
    Code:
            'An empty array
            Dim myArray As Integer() = {}
    
            If myArray IsNot Nothing AndAlso myArray.Length > 0 Then
                Debug.WriteLine("There is an arry with data")
            Else
                Debug.WriteLine("Array is empty or doesn't exist")
            End If
    Now lets do something a little more fun. Lets say you get a list of structures containing names and ages. You want to sort by names and then by ages. Then you want to print something like John is 12 years old. You can do that without thinking much about how you're going to do that:-
    Code:
            Dim people As PersonInfo() = {
                New PersonInfo("John", "Jones", 12),
                New PersonInfo("Mary", "Jones", 12),
                New PersonInfo("Zorro", "Michaels", 34),
                New PersonInfo("John", "Prince", 47),
                New PersonInfo("John", "April", 49),
                New PersonInfo("John", "Aster", 2),
                New PersonInfo("Avril", "Terry", 50),
                New PersonInfo("Utred", "Ragnarson", 32),
                New PersonInfo("John", "Liviningston", 72),
                New PersonInfo("Mary", "McEntyre", 20)
            }
    
    
            For Each strn As String In people.
                                OrderBy(Function(p) p.FirstName).
                                ThenBy(Function(p) p.Age).
                                Select(Function(p) $"{p.FirstName} {p.LastName} is {p.Age.ToString} years old")
    
                Debug.WriteLine(strn)
    
            Next
    The above would output this:-
    Code:
    Avril Terry is 50 years old
    John Aster is 2 years old
    John Jones is 12 years old
    John Prince is 47 years old
    John April is 49 years old
    John Liviningston is 72 years old
    Mary Jones is 12 years old
    Mary McEntyre is 20 years old
    Utred Ragnarson is 32 years old
    Zorro Michaels is 34 years old
    Now lets say for whatever reason you want to list only the 3 oldest people. Maybe a client asks for this. You can do that in less than a minute:-
    Code:
            For Each strn As String In people.
                                OrderByDescending(Function(p) p.Age).
                                Select(Function(p) $"{p.FirstName} {p.LastName} is {p.Age.ToString} years old").
                                Take(3)
    
                Debug.WriteLine(strn)
    
            Next
    The above outputs this:-
    Code:
    John Liviningston is 72 years old
    Avril Terry is 50 years old
    John April is 49 years old
    What if I wanted the average age of all those people? Well:-
    Code:
    Debug.WriteLine(people.Average(Function(p) p.Age).ToString)
    If I wanted the sum of their ages:-
    Code:
    Debug.WriteLine(people.Sum(Function(p) p.Age).ToString)
    What if I wanted to list every person under the age of 18 while sorting first by age from oldest to youngest and then sorting by name? Well, easy:-
    Code:
            For Each strn As String In people.
                                Where(Function(p) p.Age < 18).
                                OrderByDescending(Function(p) p.Age).
                                ThenBy(Function(p) p.FirstName).
                                Select(Function(p) $"{p.FirstName} {p.LastName} is {p.Age.ToString} years old")
    
    
                Debug.WriteLine(strn)
    
            Next
    Output:-
    Code:
    John Jones is 12 years old
    Mary Jones is 12 years old
    John Aster is 2 years old
    What if you wanted to transform that array from an array of structures to an array of Strings containing only the first and last names. That's easy:-
    Code:
    Dim people2 As String() = people.Select(Function(p) $"{p.FirstName} {p.LastName}").ToArray
    I could go on and on but I think I've made my point. You have such a great degree of freedom to handle array data in whatever way you want right out of the gate. None of what I showed above required anything extra. No extra libraries, no Win32 imports. You could do all of that in a fresh .Net project. If I had to do this in VB6, I'd either have to write a whole bunch of helper functions or resort to hacks like using a database engine. That's fine if you guys are satisfied with this but understand that many people, especially those of us in .Net using C# or VB.Net or perhaps some Java programmers are going to look at this and think it's insane.

    For me personally, after being used to having this much freedom and flexibility in VB.Net, could never go back to the more primitive way of doing things. I understand perfectly where xiaoyao was coming from when he made this thread. I'm guessing he is working in something like Java and C# and is already getting used to this new found freedom and wants to bring it to VB6. I'm telling you, when you get used to this, it's very difficult to go back. I honestly don't know why xiaoyao doesn't just dump VB6 already and move on. He has tasted the forbidden fruit and now he can't get enough. He is tainted now.

    Hell, even Python can do these things natively. I don't think most hardcore VB6 programmers realize just how far VB6 has fallen behind modern languages and frameworks.
    Last edited by Niya; Oct 16th, 2021 at 07:00 PM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  25. #25
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,661

    Re: Can anyone write an array module?

    Quote Originally Posted by xiaoyao View Post
    Code:
    Function Arr_BinToHex(Bin() As Byte, Optional Fg As String = ",") As String
    Dim i As Long
    Dim SZ() As String
    ReDim SZ(UBound(Bin))
    For i = 0 To UBound(Bin)
        SZ(i) = IIf(Bin(i) < 16, "0", "") & Hex(Bin(i))
    Next
    Arr_BinToHex = Join(SZ, Fg)
    End Function
    Here's another fun one. Easy in .Net:-
    Code:
            Dim blob As Byte() = {23, 255, 90, 54, 23, 90, 30}
            Dim strn As String = String.Join(", ", blob.Select(Function(b) b.ToString("X2")))
    
            Debug.WriteLine(strn)
    Output:-
    Code:
    17, FF, 5A, 36, 17, 5A, 1E
    No need for a whole extra function with all that mess. Just one line of code.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  26. #26
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    540

    Re: Can anyone write an array module?

    it doesnt actually matter if you can do x.a().b().c() or c(b(a(x)))
    or if the array functions are built into a class object or sitting in a module accepting an array as an arg

    simply preference.

    "free" built in functions of newer frameworks arent really free. Someone had to code them and stuff them in there.

    The cost of the .NET framework itself is what most of us dont like and why we didnt switch.

    I use languages with class based array objects all the time. Still never bothered to create one in vb6.
    This whole discussion is moot

  27. #27
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,735

    Re: Can anyone write an array module?

    Yeah, it's moot. Still, I'm curious about the cost you mention, and whether or not that was the reason people didn't switch?
    My usual boring signature: Nothing

  28. #28
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,496

    Re: Can anyone write an array module?

    Quote Originally Posted by dz32 View Post
    it doesnt actually matter if you can do x.a().b().c() or c(b(a(x)))
    or if the array functions are built into a class object or sitting in a module accepting an array as an arg

    simply preference.

    "free" built in functions of newer frameworks arent really free. Someone had to code them and stuff them in there.

    The cost of the .NET framework itself is what most of us dont like and why we didnt switch.

    I use languages with class based array objects all the time. Still never bothered to create one in vb6.
    This whole discussion is moot
    If they aren't free by the definition of "somebody" had to write them then absolutely no code is free. All code is written by someone. If functionality is built into the framework however then it is certainly free in terms of time, the functionality is just there. you don't have to search forums to find out how to check if an array is empty - something that should just be build into a language that has arrays.

  29. #29
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,683

    Re: Can anyone write an array module?

    Quote Originally Posted by PlausiblyDamp View Post
    ...you don't have to search forums to find out how to check if an array is empty
    Nahh, the "Pro's" among us (when starting with VB6) came up with the most simple solution all on their lonesome
    (something like below in a *.bas-module, using Err-skipping as the easiest solution):

    Code:
    Public Function ArrLen(Arr) As Long
      On Error GoTo RetZero: ArrLen = UBound(Arr) - LBound(Arr) + 1
    RetZero:
    End Function
    Took ourselves probably 1 minute to come up with (never to be written again, when "MyHelperStuff.bas" was included).

    Now please don't tell me, you deny yourself writing useful Functions or -Methods for your own convenience...

    Man, this whole discussion is ridiculous...

    Cannot understand, how a "Pro" is trying to imply "larger productivity-boosts in .NET" when there aren't any
    (given the huge COM-ecosystem we have for VB6).

    Hobbyists are Hobbyists (they like experimenting and fumbling around "near the metal") -
    whilst "Pro's use well-tested libs" in their daily work (existing and domain-specific self-written ones).

    Olaf

  30. #30
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,683

    Re: Can anyone write an array module?

    Quote Originally Posted by Niya View Post
    Here's another fun one. Easy in .Net:-
    Code:
            Dim blob As Byte() = {23, 255, 90, 54, 23, 90, 30}
            Dim strn As String = String.Join(", ", blob.Select(Function(b) b.ToString("X2")))
    
            Debug.WriteLine(strn)
    Output:-
    Code:
    17, FF, 5A, 36, 17, 5A, 1E
    No need for a whole extra function with all that mess. Just one line of code.
    The mess is, in what I read above (typical Amateur-programming).

    And I see 3 lines in that specific example - not one.

    Here's what I would use to accomplish the same thing in VB6 (with less code, as always):
    Code:
      'Dim blob As Byte() = {23, 255, 90, 54, 23, 90, 30}
      Dim a: a = Array(23, 255, 90, 54, 23, 90, 30)
      'Dim strn As String = String.Join(", ", BA.Select(Function(b) b.ToString("X2")))
      Dim i: For i = 0 To UBound(a): a(i) = Right(0 & Hex(a(i)), 2): Next
      'Debug.WriteLine(strn)
      Debug.Print Join(a, ", ")
    Have left the .NET-crime commented in, for line-length-comparisons...

    Olaf

  31. #31
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,421

    Re: Can anyone write an array module?

    There are three kinds of arrays in VB6

    1. Dim A(0 to 100) As {DataType} where A is a 4-byte pointer to the array start on the stack (or heap).

    2. Dim B() As {DataType} where B is a 4-byte pointer to a SAFEARRAY struct.

    3. Dim C As Variant where C is an actual Variant that contains a pointer to a SAFEARRAY struct.

    In both 2. and 3. cases the pointer can be NULL. In both cases the SAFEARRAY struct is always allocated on the heap.

    Only such SAFEARRAYS based arrays can be redimensioned/resized.

    Passing B-type arrays to a routine which accepts C-type parameters is possible and involves array aliasing.

    cheers,
    </wqw>

  32. #32
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,496

    Re: Can anyone write an array module?

    Quote Originally Posted by Schmidt View Post
    The mess is, in what I read above (typical Amateur-programming).

    And I see 3 lines in that specific example - not one.

    Here's what I would use to accomplish the same thing in VB6 (with less code, as always):
    Code:
      'Dim blob As Byte() = {23, 255, 90, 54, 23, 90, 30}
      Dim a: a = Array(23, 255, 90, 54, 23, 90, 30)
      'Dim strn As String = String.Join(", ", BA.Select(Function(b) b.ToString("X2")))
      Dim i: For i = 0 To UBound(a): a(i) = Right(0 & Hex(a(i)), 2): Next
      'Debug.WriteLine(strn)
      Debug.Print Join(a, ", ")
    Have left the .NET-crime commented in, for line-length-comparisons...

    Olaf
    Except the VB6 version isn't doing the same thing, the VB6 version is doing the Join as part of the Debug.Print, the VB.Net is doing the join as part of the one line.

  33. #33
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,683

    Re: Can anyone write an array module?

    Quote Originally Posted by PlausiblyDamp View Post
    Except the VB6 version isn't doing the same thing,
    the VB6 version is doing the Join as part of the Debug.Print...
    As any routine in this regard should...
    Who wants to throw away a perfecly fine, already splitted Array just for "Formatted-TextRendering"-purposes?

    The only way such a Hex-conversion makes sense, is perhaps in "serialization-scenarios"
    E.g. when you want to put an Image-blob as a string into a JSON-Property or an URL -
    and don't want to use Base64 for reasons of Upper/Lower-case hardening.

    In that regard... the performance of Linq sucks big time.

    If that's how .NET-devs deal with their Lists in e.g. serverside DBLayer-Code,
    then it is no wonder why you will need "multiple, loadbalanced Servers" in scenarios,
    where a VB6-based solution would only need a single Server-instance.

    The HexSerialization as shown (based on Linq) is about 15 times slower,
    compared to a decent VB6-solution.

    Olaf

  34. #34
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,235

    Re: Can anyone write an array module?

    Quote Originally Posted by Schmidt View Post
    Hobbyists are Hobbyists (they like experimenting and fumbling around "near the metal")
    That's me! Only until I have some of the stuff under my belt.

    Quote Originally Posted by Schmidt View Post
    whilst "Pro's use well-tested libs" in their daily work (existing and domain-specific self-written ones).
    I'll have and use those eventually.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  35. #35
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,661

    Re: Can anyone write an array module?

    Quote Originally Posted by Schmidt View Post
    Nahh, the "Pro's" among us (when starting with VB6) came up with the most simple solution all on their lonesome
    (something like below in a *.bas-module, using Err-skipping as the easiest solution):

    Code:
    Public Function ArrLen(Arr) As Long
      On Error GoTo RetZero: ArrLen = UBound(Arr) - LBound(Arr) + 1
    RetZero:
    End Function
    Took ourselves probably 1 minute to come up with (never to be written again, when "MyHelperStuff.bas" was included).

    Now please don't tell me, you deny yourself writing useful Functions or -Methods for your own convenience...

    Man, this whole discussion is ridiculous...

    Cannot understand, how a "Pro" is trying to imply "larger productivity-boosts in .NET" when there aren't any
    (given the huge COM-ecosystem we have for VB6).

    Hobbyists are Hobbyists (they like experimenting and fumbling around "near the metal") -
    whilst "Pro's use well-tested libs" in their daily work (existing and domain-specific self-written ones).

    Olaf
    Yep, that's definitely better than Arr.Length. You guys can have fun with that.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  36. #36
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,661

    Re: Can anyone write an array module?

    Quote Originally Posted by Schmidt View Post
    As any routine in this regard should...
    Who wants to throw away a perfecly fine, already splitted Array just for "Formatted-TextRendering"-purposes?

    The only way such a Hex-conversion makes sense, is perhaps in "serialization-scenarios"
    E.g. when you want to put an Image-blob as a string into a JSON-Property or an URL -
    and don't want to use Base64 for reasons of Upper/Lower-case hardening.

    In that regard... the performance of Linq sucks big time.

    If that's how .NET-devs deal with their Lists in e.g. serverside DBLayer-Code,
    then it is no wonder why you will need "multiple, loadbalanced Servers" in scenarios,
    where a VB6-based solution would only need a single Server-instance.

    The HexSerialization as shown (based on Linq) is about 15 times slower,
    compared to a decent VB6-solution.

    Olaf
    This isn't the 90s. We have multi-core processors with multi-gigahertz speeds now. But hey, when the apocalypse comes and we are all back to using 486 machines and floppy disks we'd be grateful you guys never gave up on the old tech
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  37. #37
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,496

    Re: Can anyone write an array module?

    Quote Originally Posted by Schmidt View Post
    As any routine in this regard should...
    Who wants to throw away a perfecly fine, already splitted Array just for "Formatted-TextRendering"-purposes?
    If you are going to get into petty arguments about how you can do exactly the same thing in VB6 in one line of code and even compare the line lengths then at least have the decency to make the VB6 line do the same thing.

    Quote Originally Posted by Schmidt View Post
    In that regard... the performance of Linq sucks big time.

    If that's how .NET-devs deal with their Lists in e.g. serverside DBLayer-Code,
    then it is no wonder why you will need "multiple, loadbalanced Servers" in scenarios,
    where a VB6-based solution would only need a single Server-instance.

    The HexSerialization as shown (based on Linq) is about 15 times slower,
    compared to a decent VB6-solution.

    Olaf
    So I am assuming you have done benchmarking and memory profiling over both versions of the code to decide if the .Net version really is too inefficient.

  38. #38
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,820

    Re: Can anyone write an array module?

    Quote Originally Posted by dz32 View Post
    The cost of the .NET framework itself is what most of us dont like and why we didnt switch.
    Just wondering what that cost is you are referring to. I know I have heard complaints about the size of the framework but given that it is already installed on most systems and is used by lots of modern software the size isn't really an issue as it is more often than not there no matter if you use it or not. To date I have not had to install the framework on a single customer PC as it was already there in every case.

  39. #39
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,235

    Re: Can anyone write an array module?

    Quote Originally Posted by Niya View Post
    This isn't the 90s. We have multi-core processors with multi-gigahertz speeds now. But hey, when the apocalypse comes and we are all back to using 486 machines and floppy disks we'd be grateful you guys never gave up on the old tech
    No, no, no. In an emergency you can wrap a z80 circuit board in lead sheets very quickly and run it down to the cellar. The future is 8bit not 32.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  40. #40
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,709

    Re: Can anyone write an array module?

    Quote Originally Posted by DataMiser View Post
    Just wondering what that cost is you are referring to. I know I have heard complaints about the size of the framework but given that it is already installed on most systems and is used by lots of modern software the size isn't really an issue as it is more often than not there no matter if you use it or not. To date I have not had to install the framework on a single customer PC as it was already there in every case.
    But that's just it (at least for me): What happened to the Standalone-EXE?
    Whatever i write in Lazarus/FreePascal, which doesn't use external dependencies, i compile to an EXE, put it on a Flashdisk, and distribute.
    Hell, i can even run it directly from the Flashdisk.


    It's the age old question: Executable size vs. dependency hell

    And since someone mentioned "modern" hardware: Do we really have to bother with the question "Oh my, my executable is 10MB in size. Whatever will my clients think?"
    Face it: All this dependency hell (and it doesn't matter if it's the vb-runtime, the countless ocx, the dll's, or the .NET-Framework) stems from times, when Memory was expensive.
    Remember: .NET 1.0 was released in early 2002 --> https://en.wikipedia.org/wiki/.NET_F...ersion_history

    I still remember my High-End-PC from 2002 with 256MB RAM

    Don't get me wrong: The principle of "if code has already been written, don't write it again" still applies, but really? 116MB for a Framework, which maybe 5% from it is actually used by any application on the target-PC?
    There is a difference of re-using already written code during developement and re-using it after distribution
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Page 1 of 2 12 LastLast

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