-
Oct 11th, 2021, 06:27 PM
#1
Thread Starter
PowerPoster
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.
-
Oct 11th, 2021, 06:33 PM
#2
Thread Starter
PowerPoster
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.
-
Oct 12th, 2021, 05:10 AM
#3
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.
-
Oct 12th, 2021, 05:27 AM
#4
Thread Starter
PowerPoster
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.
-
Oct 12th, 2021, 05:50 AM
#5
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?
-
Oct 12th, 2021, 06:17 AM
#6
Re: Can anyone write an array module?
Originally Posted by xiaoyao
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).
Originally Posted by xiaoyao
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.
Originally Posted by xiaoyao
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.
-
Oct 12th, 2021, 06:23 AM
#7
Re: Can anyone write an array module?
Originally Posted by Phill.W
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
-
Oct 12th, 2021, 06:27 AM
#8
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.
-
Oct 12th, 2021, 07:26 AM
#9
Re: Can anyone write an array module?
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Oct 12th, 2021, 08:29 AM
#10
Re: Can anyone write an array module?
Originally Posted by yereverluvinuncleber
xiaoyiao is trolling...
Don't believe it because the thread is not started in the CodeBank, no? :-))
cheers,
</wqw>
-
Oct 12th, 2021, 09:08 AM
#11
Re: Can anyone write an array module?
Originally Posted by wqweto
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.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
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
-
Oct 12th, 2021, 03:02 PM
#12
Thread Starter
PowerPoster
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
-
Oct 12th, 2021, 03:11 PM
#13
Thread Starter
PowerPoster
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.
-
Oct 12th, 2021, 03:12 PM
#14
Thread Starter
PowerPoster
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
-
Oct 12th, 2021, 03:18 PM
#15
Thread Starter
PowerPoster
Re: Can anyone write an array module?
Originally Posted by Schmidt
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.
-
Oct 12th, 2021, 03:23 PM
#16
Thread Starter
PowerPoster
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)
-
Oct 13th, 2021, 03:10 AM
#17
Re: Can anyone write an array module?
Originally Posted by xiaoyao
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.
-
Oct 13th, 2021, 03:44 AM
#18
Thread Starter
PowerPoster
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.
-
Oct 13th, 2021, 05:15 AM
#19
Re: Can anyone write an array module?
Originally Posted by xiaoyao
Sort an array of integers and get the sorting sequence number, and then sort another array.
Mission accomplished.
Regards, Phill W.
-
Oct 16th, 2021, 01:43 PM
#20
Re: Can anyone write an array module?
Originally Posted by Phill.W
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.
-
Oct 16th, 2021, 01:45 PM
#21
Re: Can anyone write an array module?
Originally Posted by xiaoyao
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.
-
Oct 16th, 2021, 02:03 PM
#22
Re: Can anyone write an array module?
Originally Posted by Zvoni
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.
-
Oct 16th, 2021, 02:20 PM
#23
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.
-
Oct 16th, 2021, 06:21 PM
#24
Re: Can anyone write an array module?
Originally Posted by baka
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.
-
Oct 16th, 2021, 06:34 PM
#25
Re: Can anyone write an array module?
Originally Posted by xiaoyao
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.
-
Oct 17th, 2021, 10:12 AM
#26
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
-
Oct 17th, 2021, 10:29 AM
#27
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
-
Oct 17th, 2021, 11:26 AM
#28
Re: Can anyone write an array module?
Originally Posted by dz32
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.
-
Oct 17th, 2021, 02:17 PM
#29
Re: Can anyone write an array module?
Originally Posted by PlausiblyDamp
...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
-
Oct 17th, 2021, 02:23 PM
#30
Re: Can anyone write an array module?
Originally Posted by Niya
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
-
Oct 17th, 2021, 02:36 PM
#31
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>
-
Oct 17th, 2021, 03:43 PM
#32
Re: Can anyone write an array module?
Originally Posted by Schmidt
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.
-
Oct 17th, 2021, 04:29 PM
#33
Re: Can anyone write an array module?
Originally Posted by PlausiblyDamp
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
-
Oct 17th, 2021, 04:45 PM
#34
Re: Can anyone write an array module?
Originally Posted by Schmidt
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.
Originally Posted by Schmidt
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.
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Oct 17th, 2021, 10:12 PM
#35
Re: Can anyone write an array module?
Originally Posted by Schmidt
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.
-
Oct 17th, 2021, 10:33 PM
#36
Re: Can anyone write an array module?
Originally Posted by Schmidt
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
-
Oct 18th, 2021, 03:06 AM
#37
Re: Can anyone write an array module?
Originally Posted by Schmidt
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.
Originally Posted by Schmidt
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.
-
Oct 18th, 2021, 06:56 AM
#38
Re: Can anyone write an array module?
Originally Posted by dz32
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.
-
Oct 18th, 2021, 07:26 AM
#39
Re: Can anyone write an array module?
Originally Posted by Niya
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.
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Oct 18th, 2021, 08:01 AM
#40
Re: Can anyone write an array module?
Originally Posted by DataMiser
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|