Page 8 of 18 FirstFirst ... 567891011 ... LastLast
Results 281 to 320 of 695

Thread: Vb6 , the Future, and what I have discovered

  1. #281
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Vb6 , the Future, and what I have discovered

    Pff, please close this thread, hardly ever seen this behavior before, except for similar threads on this forum.

    Let agree to disagree

  2. #282
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: Vb6 , the Future, and what I have discovered

    Let agree to disagree
    +1 to that
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #283
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Vb6 , the Future, and what I have discovered

    I am inclined to close it, even if it might have brought Funky out of his hermitage. If it is nothing more than .Net vs VB6, it might as well be closed, since that won't go anywhere good. There was some meaningful discussion about RC5 and some other basics, though. If nobody has anything to add to that, then this will fade down. If it gets to be name calling, it will be cleaned and closed.
    My usual boring signature: Nothing

  4. #284
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Vb6 , the Future, and what I have discovered

    One thing I will say about converting code is that it is FAR faster than writing it the first time. After all, as long as the program worked, you KNOW what each function has to do. If you did a straight up one-to-one conversion, which is possible between most languages, a program that took you a few months to write could likely be converted in under a week. This is (probably) especially true between VB6 to VB.NET, though not quite as true going the other way, except for code written prior to 2005. The only conversion I did was VB6 to .NET. I can't say much of anything about the size. I don't like using lines of code as a metric. It's mostly used because it is easy to count (it's done for you), rather than being truly indicative of anything. After all, VS counts white space and comments as lines of code. I have some code that I didn't write, where the author prefaced each file with an extensive comment talking about....I forget what, so I guess it didn't matter much to me. That counts for lines of code.

    A better metric might be number of forms, but ONLY for Line of Business types of applications, and not necessarily all of them. Still, the program I converted over likely wouldn't have weighed in at as much as 20K lines, and quite likely less than that....or not, I really can't say, and tend to underestimate lines of code. It was maybe half a dozen forms, but since it was essentially one giant equation in a loop, it had an abnormally high UI/code ratio.

    Having said that, much could be converted by copying and pasting code, then doing a trivial search and replace. It feels like it took a few hours, maybe a day or two. If you re-write at the same time, that will be slower, of course. Still, I was astonished at how fast the re-write was.

    Since then, I've re-written some C# to either JS or VB.NET, and some Java to C# (just different enough to annoy). For an individual method, I'd copy in the C# code, which would immediately throw errors all over the place, so I'd comment it all out, but then I'd have the individual lines, and would be able to translate/write pretty fast.

    So, I'm not recommending it, but it's also nothing to fear. As that whole discussion started out, I was contemplating re-writing part of a pretty large project into a different language. That one...well, I don't know the size of it, either, but the number of forms is around 125, or so, which means it's not small. However, since that was just a mass of dlls (around 30 of them), it wouldn't be so hard. Each dll could be converted independently of the rest, so the whole conversion could be done piecemeal.

    That's all I've got to say about code conversion: It's WAY faster than you'd expect.
    My usual boring signature: Nothing

  5. #285
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Vb6 , the Future, and what I have discovered

    Well if it's getting to that point I'll just step back out, it's not that big a deal.

    I'm a language nerd and I like talking about designs. We don't make topics like this in the .NET forum. I mostly came here because dilettante's thread about Polaris got me wondering what the VB6 people thought about it, it's definitely a blinking red light to frown at. VB6 developers are often trying to figure out how to make their language better or extend its support, but I find VB .NET developers don't have that drive, despite the fact that our compiler has a blasted API so we can add our own keywords at this point. There are open-source toolchains for .NET so it's probably going to last forever, but little demand for VB tooling so those ends of it are poorly maintained if at all. The VB .NET developers who do care find it easier/more rewarding to just migrate to C# or some other language. So it gets boring up in that forum.

    I know what I wanted my posts to say but I don't think they did. I think a VB revival is a good chance to approach the VB language and add some new features. It seems there's a very strong opinion to stay the heck out of that language design. I don't think that's the best route, but I'd rather not discourage anyone from taking on the project and making something neat. If the clone isn't adequate, you can improve it.

    I don't know why I diverged and I can't even chart my journey through this thread anymore. I've been hopped up on allergy medicines and maybe I should've thought thrice. Believe it or not I learned a couple of things about VB6 along the way. I'm gonna keep watching but I won't jump back in unless I think what I have to say is neat and has nothing to do with some of the more sensitive topics.
    Last edited by Sitten Spynne; Jan 31st, 2018 at 09:58 PM. Reason: Just ban me if I ever type "long story short" again, we all know I can't
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  6. #286
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Sitten Spynne View Post
    I'm a language nerd and I like talking about designs.
    Nothing wrong with "talking about" that, but did you really listen, when others tried to explain,
    that VB6+COM is (in many regards) already "near the optimum"?

    I'm quite aware that the above statement will (again) raise a "red flag" on your end,
    but please consider just for a moment, that "the guy on the other end" might know more about
    "these concepts in other languages" than you do know "about comparable concepts in VB6 or COM".

    because...
    Quote Originally Posted by Sitten Spynne View Post
    Believe it or not I learned a couple of things about VB6
    ...typing the above out, should have already "make you question your stance", wouldn't you say?
    You were apparently trying to "berate us" without really knowing about, what VB6 in conjunction with the COM-subsystem can already do.

    Quote Originally Posted by Sitten Spynne View Post
    I know what I wanted my posts to say but I don't think they did.
    Speaking for myself, I knew quite well what *you* were talking about, whilst posting the little code-snippets
    (several ways to perform an async http-request with "applied fancyness, common in so called 'modern' languages") -
    But you never replied to the postings from "us", where e.g.
    - DexWerx was showing you the VB6-equivalent
    - or my earlier (more generic) comment about the Event-concept that's built into VB6, which makes a whole "class of fancy patterns" unnecessary in VB6

    So, before you begin typing again in that regard, let me ask, what *you* know about IConnectionPointContainer & Co.,
    (which are hidden in VB6, but do all the hard work behind the VB6 RaiseEvent/WithEvents concept).

    I can ensure you, that the whole thing is quite powerful, and allows (without breaking stride, or to type anything extra) also:
    - "multiple 'Event-receivers' (a kind of "delegates-Add" concept, as you perhaps know it from .NET).

    Quote Originally Posted by Sitten Spynne View Post
    ...Polaris got me wondering what the VB6 people thought about it, it's definitely a blinking red light to frown at.
    ...There are open-source toolchains for .NET so it's probably going to last forever, ...
    Well, with your second part above, you basically answered the original question already in my opinion...

    That's BTW what I was trying really hard, to make clear to the VB6-participants in this thread -
    if we want a "surviving VB6", then we have to "lift it up to platform-independence" (true independence from MS-OSes and -APIs).

    And that task is, other than Funky tried to suggest, not *that* hard to do, because with the RC5 we already
    have a capable Class-library - quite similar to the platform-independently desinged ".NET Core 2.0"
    (and other than ".NET Core 2.0", it already includes a DPI-aware and Alpha-capable Drawing- and GUI-engine, which allows to write your own UserControls with ease).

    Quote Originally Posted by Sitten Spynne View Post
    I think a VB revival is a good chance to approach the VB language and add some new features.
    Then why not "join the efforts" - there's nothing wrong with bringing up suggestions,
    when you can show that these new additions really "need to be needed".

    Also keep in mind, that the VB6-successor I aim for, will (needs to) have "full backwards-compatibility in *.bas and *.cls modules"
    (any kind of code in these two module-types, will work further - entirely unchanged, including compatibility to COM and COM-Events as they are currently supported in VB6).

    Given the above (full backwards-compatibility, which is needed to make porting easier) - new additions to the language shouldn't break "DRY" (functionality-wise)...
    It would be confusing especially for newcomers, when we'd e.g. "double up on the Event-Concept" by introducing "delegates in addition".

    On the other hand I'd have no larger problem with suggestions, which would make a new VB6 a bit more powerful on the "lower level" ...
    (Option PointerSupport or something alike, exposing a few more of those things, the C-Compiler has to offer ... since it already works under the covers anyways -
    e.g. calling Functions by Pointer in a more convenient way would be a plus - as would be the ability to specify e.g. __cdecl calling conventions in Declare-Statements).

    In that regard (opening up to the "C-side" a bit more), I'm still of two minds, whether we should expose e.g. the C-Preprocessor (to offer e.g. Macro-Definitions).

    But all that is (in my mind) a discussion for a later point in time -
    as already stated earlier, in a first step we should focus our efforts on "achieving 1:1 compatibility".

    Quote Originally Posted by Sitten Spynne View Post
    It seems there's a very strong opinion to stay the heck out of that language design.
    I don't think that's the best route, but I'd rather not discourage anyone from taking on the project ...
    If you'd start making suggestions, which are worthwhile and "carry through" - I for my part would be "all ears",
    but you'd have to do it with code-examples (how else) - then compare that with the "pattern we'd use in current VB6" -
    and if you indeed find something, where the VB6-equivalent is "utterly clumsy" in comparison, then such a thing
    would be a good candidate to inlcude in "VB.Next version 1.1" I guess.

    Currently the task to "drum up support" in the community, to tackle a 1:1 backward-compatible "version 1.0" is already hard enough as it seems.

    @Shaggy
    You rightfully mentioned that the stuff we currently talk about here is not really a "programming-problem" -
    Well, I for my part would like it very much, if we could "make it one"!
    (the most "challenging VB6-programming-problem which was ever discussed" on VBForums, with a lot to learn from, even by silent lurkers).

    I'd love when we'd talk more in detail about certain things - including VB6-code-examples
    (to clear up doubts in the community, whether some things are possible or not - e.g. similar to the COM-inheritance example I've posted for Niya in this thread).

    It is entirely possible to write a new VB6-IDE and compiler in the VB6-language itself - so why not start analyzing and producing code for it.

    Since that new compiler (in the end) will have the capabilities to understand the sources in *.bas and *.cls 1:1, the "bootstrapping" or "selfhosting"-problem:
    - the re-compiling of the initial VB6-based compiler-sourcecode with the (initially) VB6-produced, "first-level compiler-executable",
    is non-existent.

    Olaf
    Last edited by Schmidt; Feb 1st, 2018 at 06:17 AM.

  7. #287
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Schmidt View Post
    Then why not "join the efforts" - there's nothing wrong with bringing up suggestions,
    when you can show that these new additions really "need to be needed".
    Well if you want suggestions, I can give you some. A couple based on some of the thing I love about VB.Net and some based on the general things found in modern languages.

    Lets start with something simple, the ability perform declaration and initialization in a single line. As simple as it is, it can go along way towards making this new VB more appealing to a modern audience. VB.Net, C/C++, C# and a number of other popular languages support this.

    Here is an example for the sake of completeness:-
    Code:
    Dim max As Integer = 10
    Also with regards to this suggestion it would be nice if this was possible:-
    Code:
    Dim x, y, z As Integer 'All are declared as Integer
    VB.Net supports this while also supporting the older syntax where you specify the type of each variable separately. The older syntax is too verbose for no sensible reason.

    You can also do stuff like this:-
    Code:
    Dim x As Double = 10, y As Single = 90, z As Short = 40
    Now, VB6 programmers might scoff at this suggestion but when you have used languages that support this kind of declaration, trust me, it's extremely annoying when you have to use a language that doesn't especially given how common this seems to be outside of the world of BASIC.

    Another suggestion that's vaguely related to the above suggestions would be parameterized constructors. This one might be a bit sticky since I've seen nothing in COM that indicates it could support such a feature.

    Here's an example of its use:-
    Code:
    Dim p As New Point(100, 100)
    Without parameterized constructors we would be writing:-
    Code:
            Dim p As New Point
            p.X = 100
            p.Y = 100
    Again, I know a VB6 programmer might scoff at this because they are used to doing things that way but trust me this simple ability goes a long way. It feels really nice when you can just flow into a statement that looks something like this:-
    Code:
    DoSomething(New MySpecialClass1(23), New MySpecialClass1(100))
    Without it the above would look like this:-
    Code:
            Dim mc1 As New MySpecialClass1
            Dim mc2 As New MySpecialClass1
    
            mc1.ClassValue = 23
            mc2.ClassValue = 100
    
            DoSomething(mc1, mc2)
    Even if COM doesn't support parameterized constructors, you could probably implement it in your compiler. One way would be to have the compiler generate them as private method calls.

    I can say more but I'll stop here for now. See what you have to say. But personally for me, these two very simple feature makes a world of difference, even ignoring more advanced language features. And there are a couple things I would like to say when it comes to libraries but like I said, I would like to see what you have to say before I continue.
    Last edited by Niya; Feb 1st, 2018 at 07:00 AM.
    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 | I'm not wanted

    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

  8. #288
    Hyperactive Member
    Join Date
    Jul 2013
    Posts
    400

    Re: Vb6 , the Future, and what I have discovered

    For once I agree with Niya.
    I can do all the above in my lovely Visual Objects, thought using {} in class construct - Point{100,100}
    Carlos

  9. #289
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Schmidt View Post
    Nothing wrong with "talking about" that, but did you really listen, when others tried to explain,
    that VB6+COM is (in many regards) already "near the optimum"?
    This is something I've come to realize over the last 8 or so years... took a while to get there... but it's true... and I also think that's where some of the problems lie. Because now it's a matter of "OK, now what?"
    Fortunately, I think you have a good set of ideas going on with your project. I've been watching from the sidelines as it's evolved. I'll admit, I thought you were a bit crazy for it, but over time, I came to get it. And I've even suggested RC5 to people on more than one occasion - especially when they are trying to use SQLite. I know what a pain it can be to use it, and I've seen what you've done to ease that pain, and I think "oh hell, if only I had had this 15 years ago..." I probably would be on a different career path.

    Moving on...

    Quote Originally Posted by Schmidt View Post
    @Shaggy
    You rightfully mentioned that the stuff we currently talk about here is not really a "programming-problem" -
    Well, I for my part would like it very much, if we could "make it one"!
    (the most "challenging VB6-programming-problem which was ever discussed" on VBForums, with a lot to learn from, even by silent lurkers).

    I'd love when we'd talk more in detail about certain things - including VB6-code-examples
    (to clear up doubts in the community, whether some things are possible or not - e.g. similar to the COM-inheritance example I've posted for Niya in this thread).

    It is entirely possible to write a new VB6-IDE and compiler in the VB6-language itself - so why not start analyzing and producing code for it.

    Since that new compiler (in the end) will have the capabilities to understand the sources in *.bas and *.cls 1:1, the "bootstrapping" or "selfhosting"-problem:
    - the re-compiling of the initial VB6-based compiler-sourcecode with the (initially) VB6-produced, "first-level compiler-executable",
    is non-existent.

    Olaf
    It might be worthwhile to take that discussion into a new thread, one with some ground rules of what is expected, and what will not be tolerated in the discussion.
    I think if you try to do that in this thread, it's just going to get drowned out in the noise that this thread has become.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #290
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Vb6 , the Future, and what I have discovered

    RE: VB6 being "near the optimum": I mostly agree but it's buried in arguments that make it look like I don't.

    When you try to improve something that's already really good, it comes with a lot of risk. If there's not really a lot of room for improvement, it's just as likely you get "just as good" or "slightly worse" afterwards. In terms of Windows Client design, I think it's clear something like that happened with .NET. Even in the areas where I think it has advantages, we're talking very small advantages, not the kinds of things you base a career move on.

    I liken it to why despite having years of experience poking at it I still don't use WPF for my random projects. I tried it. It's a great framework. I like everything it does. But I have a deep knowledge of Windows Forms and 90% of the advantages of WPF don't matter for the things I write. This is, more or less, why MS has struggled to get support for WPF and its successors. When you're in the middle of eating a very good strawberry pie, you don't stop and move tables because someone says they have a pie that scored 1 point out of 100 better. (Technically you eat both pies bwa ha ha!)

    The gap between VB .NET and VB6 doesn't look so big to me but it's because I already know the wolf in sheep's clothing that's OO. I think I discount the amount of extra learning that goes into adjusting to that in a transition. It's easy to forget how hard it was to learn something when it was the first thing you learned. Worse, I think software engineering communities today would agree OO was best for teaching us what not to do. Surprisingly, I think they've decided to start moving back towards structured design with a handful of useful functional features.

    That's more or less my main feature suggestion for VB7: some concept of functions as a first-class citizen. I think VB6's looser typing plus late binding with function variables would make VB a pretty mean competitor against most modern scripting languages. VB .NET struggles in this arena because the typing rules require some very unintuitive behaviors sometimes. I don't have examples right now because it's pre-breakfast and I'm running late, but later I'll show off some quick syntax and examples of what it enables. Heck, maybe you'll end up telling me VB6 can already do it in a roundabout way (I'm suspicious it can.)
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  11. #291
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Vb6 , the Future, and what I have discovered

    @Niya - implementing those features are so trivial, I think we'll have almost no arguments on those. Probably a small discussion on the concrete implementation of constructors. Like what the actual Public Procedure name will be called (Init() vs Construct() vs ClassName() etc), and if it will be using a single function / signature for all Object constructors using a ParamArray for instance. .NET uses multiple aliases for each constructor (all overloaded functions actually) when adapted to COM. I would guess we should adopt the same convention.

    @Olaf, how are you implementing the parser. Are you using something generic like ANTLR or other grammar parser. Or something more custom like a hand written parser. Personally I'd probably go with a hand written parser, given that VB is not difficult to parse, and it would be more accessible, easier to modify for those not intimately familiar with compiler construction.

    Also are you using a language independent intermediate data structure (AST, ASG), before translating to C.

    for reference -->

    https://github.com/uwol/vb6parser
    http://www.goldparser.org/engine/1/vb6/index.htm
    Last edited by DEXWERX; Feb 1st, 2018 at 11:15 AM.

  12. #292
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Sitten Spynne View Post
    The gap between VB .NET and VB6 doesn't look so big to me but it's because I already know the wolf in sheep's clothing that's OO.
    The gap between the two is pretty big if you include everything from the language syntax to the IDE. The most accurate description would be to say that VB6 is a subset of VB.Net. Someone who can use VB.Net would be able to use VB6 but not the reverse. That pretty much sums up the relationship between the two environments.
    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 | I'm not wanted

    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

  13. #293
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Vb6 , the Future, and what I have discovered

    I don't agree with all suggestions from Niya.
    the Dim x,y,z as integer you could write Dim x%, y%, z%, if you really are worry about how much you need to type,
    i like the way that you need to declare what for each variable you "dim".

    next, i dont agree to declare values inside Dim. I like the way vb6 works already why change? if we want to set a value we use Const.
    but I would like to be able to add arrays in Const, example:

    Const MyArr(1 to 3) as Byte = 128,10,46

    something I would love to have is a trigger when the mouse pointer goes "outside" the picturebox.
    right now, you can monitor the x,y coordination while the mouse is inside the picturebox, but if you go outside, you need to use another method.
    what i would love is 2 new events "MouseEnter" and "MouseExit". the MouseEnter will only trigger when the mouse enter the picturebox area, once. and when you move the pointer outside the picturebox, we get the MouseExit event, once.

    (I will not consider RC5, just telling what I would like to have)
    a easy way to Load, Edit, Create, Render, Manage, Save pictures.
    I would like to create a "surface", be able to clear it when I need (clear is as raster = empty, or with a solid color)
    that surface should be in memory, until i want it to render to a dc, like a picturebox.
    i should be able to copy and paste parts from a surface to another, and they support alpha/opacity.
    a event to know when the monitor refresh, so we don't need to use a loop, instead we place the code inside the event.
    there should be a variable to set the fps lock if we want.

    scalemode should be default pixel.
    i really hate it that not all components use pixel. the form is one. and i can't get the top/left coordination.
    it should be available for us without the need to call any API. i want it hardcoded the exact position of the form and its size.
    the same with the forms clientarea, so both windowarea and clientarea. and here we need to know exactly the caption, bordersize and all that.

    i use AddFontResourceEx and CreateFont API to add new fonts.
    here I would love to be able to add multiple fonts in IDE, so I can select what fonts Im gonna use for that picturebox or form, not just 1 and a way to "load" external fonts similar to the resourcemanager. the writetext should be similar to the API, to set alignment, size, bold, italic, color etc and even effects, like shadow.

    sound/music, right now im using ShockwaveFlash to play music/sounds. its easy to use with volumecontrol and automatic loop. the only downside is that you need flash installed. most people have. of course im looking for a substitute without the need to flash but very easy to use.

    randomize numbers, right now im using RtlGenRandom Lib "AdvAPI32" for whole numbers and a custom randomize function when decimals.
    maybe a function to get a random number, example
    Ran(1-100) will give a number between 1 to 100
    or
    Ran(1-10,1) will give a number between 1 to 10 including 1 decimal, so from 1,0 - 1,1 - 1,2 up to 10,0

    i need timeGetTime and/or QueryPerformanceCounter, so something similar without the need of the API.

    the command$ is outdated, im using API calls here to retrieve it.

    i use API to get short or long path names, not sure if we need it if the file system is upgraded. but i usually convert long path to short path for compatibility.

    i know CLng is faster then Val, but Val works if the value is empty , so:
    if I write CLng(Prm) and Prm = "" I get an error, but if I write Val(Prm) and Prm = "" I get a 0.
    I would love that CLng works like Val when its nothing. Not sure if possible or it will slow down the process too much.

  14. #294
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Vb6 , the Future, and what I have discovered

    I think baka's post is exactly part of the reason for some of the bickering and why there is such a fracturing when it comes to the "VB-Next Gen" (VB-NG) projects and why they tend to get slogged down. And it's also part of the reason Olaf has kept his project closed for the time being. A lot of the "I wants" are just that: "I want this" ... and I bet if you dig further, it in response to some project-specific need... and not something that would make the language easier or better.


    Quote Originally Posted by baka View Post
    I don't agree with all suggestions from Niya.
    the Dim x,y,z as integer you could write Dim x%, y%, z%, if you really are worry about how much you need to type,
    i like the way that you need to declare what for each variable you "dim".
    And I don't agree with your suggestion. For me, being able to declare multiple integers like that isn't about typing or speed. It's about organization. The proposed syntax wouldn't replace the existing syntax either. It would simply add to it. So now you have three ways to declare your integers. When VB introduced the "as Integer" in dim statements, they didn't get rid of the % did they? No. They simply added to the lexicon of what was possible. That's why you can still use % if you wanted to. And even with Niya's proposal, that would still be possible. You could dim an integer how you like and I could do it how I'd like.
    So I downvote your downvote... or upvote your downvote... what ever.

    Quote Originally Posted by baka View Post
    next, i dont agree to declare values inside Dim. I like the way vb6 works already why change? if we want to set a value we use Const.
    but I would like to be able to add arrays in Const, example:

    Const MyArr(1 to 3) as Byte = 128,10,46
    But that's a constant, and not what we're talking about (but I do agree with being able to set const arrays, heck, I'd like to be able to set even variable arrays like that).
    Again... it's not about CHANGING VB6. Your comments make it seem like these are fundamental changes that would break existing code. Far from it. Olaf has said on more than one occasion, quite emphatically I might add, that the Prime Directive is total 100% backwards compatibility with all VB6 code. Any changes would simply be language enhancements... additives, that ADD to the language. Not take away. So you can still keep writing your two line code of declaring and setting it on two lines, while Niya does it all on one line. What's wrong with that?

    Quote Originally Posted by baka View Post
    something I would love to have is a trigger when the mouse pointer goes "outside" the picturebox.
    right now, you can monitor the x,y coordination while the mouse is inside the picturebox, but if you go outside, you need to use another method.
    what i would love is 2 new events "MouseEnter" and "MouseExit". the MouseEnter will only trigger when the mouse enter the picturebox area, once. and when you move the pointer outside the picturebox, we get the MouseExit event, once.
    Here I think you take a wrong turn. This goes back to what someone said about not understanding the difference between the language and the library code... because this isn't a function or feature of the language. At all. This is something that would need to be implemented and exposed by the picture box library. Now, it may be possible to create such a control in VB-NG, but this isn't and shouldn't be something up for consideration as a language update feature.


    Actually, I think a lot of what follows falls into that same category of being a non-language feature request and is more of a library or IDE request.
    I kinda like the font idea, but again, I only really see it as an IDE functionality, has nothing to do with the language itself.
    Quote Originally Posted by baka View Post
    (I will not consider RC5, just telling what I would like to have)
    a easy way to Load, Edit, Create, Render, Manage, Save pictures.
    I would like to create a "surface", be able to clear it when I need (clear is as raster = empty, or with a solid color)
    that surface should be in memory, until i want it to render to a dc, like a picturebox.
    i should be able to copy and paste parts from a surface to another, and they support alpha/opacity.
    a event to know when the monitor refresh, so we don't need to use a loop, instead we place the code inside the event.
    there should be a variable to set the fps lock if we want.

    scalemode should be default pixel.
    i really hate it that not all components use pixel. the form is one. and i can't get the top/left coordination.
    it should be available for us without the need to call any API. i want it hardcoded the exact position of the form and its size.
    the same with the forms clientarea, so both windowarea and clientarea. and here we need to know exactly the caption, bordersize and all that.

    i use AddFontResourceEx and CreateFont API to add new fonts.
    here I would love to be able to add multiple fonts in IDE, so I can select what fonts Im gonna use for that picturebox or form, not just 1 and a way to "load" external fonts similar to the resourcemanager. the writetext should be similar to the API, to set alignment, size, bold, italic, color etc and even effects, like shadow.

    sound/music, right now im using ShockwaveFlash to play music/sounds. its easy to use with volumecontrol and automatic loop. the only downside is that you need flash installed. most people have. of course im looking for a substitute without the need to flash but very easy to use.

    randomize numbers, right now im using RtlGenRandom Lib "AdvAPI32" for whole numbers and a custom randomize function when decimals.
    maybe a function to get a random number, example
    Ran(1-100) will give a number between 1 to 100
    or
    Ran(1-10,1) will give a number between 1 to 10 including 1 decimal, so from 1,0 - 1,1 - 1,2 up to 10,0

    i need timeGetTime and/or QueryPerformanceCounter, so something similar without the need of the API.

    the command$ is outdated, im using API calls here to retrieve it.

    i use API to get short or long path names, not sure if we need it if the file system is upgraded. but i usually convert long path to short path for compatibility.

    i know CLng is faster then Val, but Val works if the value is empty , so:
    if I write CLng(Prm) and Prm = "" I get an error, but if I write Val(Prm) and Prm = "" I get a 0.
    I would love that CLng works like Val when its nothing. Not sure if possible or it will slow down the process too much.
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  15. #295
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Vb6 , the Future, and what I have discovered

    @baka I tend to aggree with you. I would suggest that to use an updated feature like Niya proposed, the source would need to opt in to them (to keep compatibility).
    via
    Code:
    Option LazyTypes

  16. #296
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Vb6 , the Future, and what I have discovered

    Eh, for every requested feature someone's going to disagree. Sometimes violently. I've read enough language blogs I do think it's a good idea to start with "no" as the answer, and wait for the arguments for it to pass some threshold before you say "yes". It's very hard to decide what to add.

    "Simplicity" means many things to many people. To some that means the language has as few keywords and/or features as possible. C is a really good example of a "simple" language in this respect: very few keywords, very few statements to learn. To others that means the language has features that make common tasks very easy to do. Perl is a "simple" language from this viewpoint: it can do remarkably complex text processing in a fraction of the functional lines of code other languages require. Yet both of those languages have a reputation for being ridiculously complex. Meanwhile I'd argue VB6 has more keywords and features than C but is considered "simple". It is not easy to define "simple".

    A balance that must be struck is the tension between, "How many features must one learn?" and "How efficiently can one work?". Niya's suggestions make it quicker and slightly easier to get many common things done. baka's objection is it adds more complexity to learning the language. Both are good points.

    I feel like VB6 struck a very good balance, and VB .NET set the dial to "a little harder to learn, but a little more effective when mastered". I only say that if we're talking about VB 2012 or so, though, as before that we just don't have enough language features to make VB .NET interesting. Plenty disagree about that "a little more effective" part, I think that's so subjective we could spend a month on it and still believe we're both right. The "a little harder to learn" we can at least agree on, even if you think I should expand it to "a lot harder".

    Personally, I prefer languages that focus on the "more effective when mastered" end of the spectrum. It's frustrating when you're new, but every year I've been "an expert" longer, by percentage, than "a newbie". I want most languages I use to be this way. So I'd like to optimize for "being an expert" because I assume it's where I spend the most time.

    That said, some languages like Perl take it too far. It has so many shortcuts it's difficult to organize any kind of book or tutorial.

    I think Niya's post's an example of the kinds of features that could improve VB without doing much harm. The reason I say "without much harm" is a person could live their entire "VB7" life not knowing it's there and be fine. The toughest features are the ones you can't function without knowing, like "being Object-Oriented". On the other hand, Niya's suggestion is very low-impact. How much efficiency for the developer does it create? Not much. Can it make things worse? Well, adding/removing an item from a horizontal list is a little more difficult than adding/removing a vertical line, especially in a nerd editor like gVim.

    So TL;DR:

    This post doesn't really have an opinion other than "there's a reason to implement every feature and a reason to omit every feature". I think the right way to "discuss" them is to make one post, lay out why you like the feature, then leave it. Someone's going to make one post and lay out why they don't like it. Don't reply. I often find that if I could organize a forum thread into a real threaded discussion, as the "layer" of threading increases the probability people are angry gets higher. We could all do with asking, "Am I angry?" before posting and decide to wait a while if the answer is "yes". Don't take it personally if your pet language feature isn't met with widespread approval. (Yes, I'm writing this post with fingers pointed squarely at myself, too.)
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  17. #297
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Vb6 , the Future, and what I have discovered

    The discussion since my last post is the reason I didn't want to close the thread. It's been pretty interesting and 'meaty'.

    I would argue against any event on monitor refresh, as obvious as such a thing would be. Raising an event that isn't handled is nearly free, but not TOTALLY free. So, having an event raised on monitor refresh would mean that a program that did nothing but sit there like a lump on a log would still be cranking through a long string of nothing. It would impose a phantom tax on performance, even for the majority of applications that wouldn't use it.

    On the other hand, there's the VSync, so there already IS something like that, though at a lower level.
    My usual boring signature: Nothing

  18. #298
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by baka View Post
    scalemode should be default pixel.
    No, please no. Do not make that mistake.
    VB6 as it is now, defaulting to Twips, makes the App -almost- DPI aware.
    If you use pixels, it is not DPI aware anymore.

    Perhaps a tool from the toolbar to change the default scale for all the objects would be handy (for those that need to use pixels).

    We need to write applications that can work fine on any DPI and screen resolution, to use pixels as the scale is really a bad idea.

  19. #299
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by baka View Post
    I don't agree with all suggestions from Niya.
    the Dim x,y,z as integer you could write Dim x%, y%, z%, if you really are worry about how much you need to type,
    i like the way that you need to declare what for each variable you "dim".

    next, i dont agree to declare values inside Dim. I like the way vb6 works already why change? if we want to set a value we use Const.
    but I would like to be able to add arrays in Const, example:
    It isn't about how much you type, it is about how understandable the code is and how you make code readable, I personally hated the % etc as variable declarations in VB6 and earlier and despite knowing what
    Code:
    Dim i,j,k as Integer
    did I would occasionally miss this when reading code written by someone else. Anything that makes the language behave in a more predictable fashion sounds good to me.

    Quote Originally Posted by baka View Post
    something I would love to have is a trigger when the mouse pointer goes "outside" the picturebox.
    right now, you can monitor the x,y coordination while the mouse is inside the picturebox, but if you go outside, you need to use another method.
    what i would love is 2 new events "MouseEnter" and "MouseExit". the MouseEnter will only trigger when the mouse enter the picturebox area, once. and when you move the pointer outside the picturebox, we get the MouseExit event, once.

    (I will not consider RC5, just telling what I would like to have)
    a easy way to Load, Edit, Create, Render, Manage, Save pictures.
    I would like to create a "surface", be able to clear it when I need (clear is as raster = empty, or with a solid color)
    that surface should be in memory, until i want it to render to a dc, like a picturebox.
    i should be able to copy and paste parts from a surface to another, and they support alpha/opacity.
    a event to know when the monitor refresh, so we don't need to use a loop, instead we place the code inside the event.
    there should be a variable to set the fps lock if we want.

    scalemode should be default pixel.
    i really hate it that not all components use pixel. the form is one. and i can't get the top/left coordination.
    it should be available for us without the need to call any API. i want it hardcoded the exact position of the form and its size.
    the same with the forms clientarea, so both windowarea and clientarea. and here we need to know exactly the caption, bordersize and all that.

    i use AddFontResourceEx and CreateFont API to add new fonts.
    here I would love to be able to add multiple fonts in IDE, so I can select what fonts Im gonna use for that picturebox or form, not just 1 and a way to "load" external fonts similar to the resourcemanager. the writetext should be similar to the API, to set alignment, size, bold, italic, color etc and even effects, like shadow.

    sound/music, right now im using ShockwaveFlash to play music/sounds. its easy to use with volumecontrol and automatic loop. the only downside is that you need flash installed. most people have. of course im looking for a substitute without the need to flash but very easy to use.

    randomize numbers, right now im using RtlGenRandom Lib "AdvAPI32" for whole numbers and a custom randomize function when decimals.
    maybe a function to get a random number, example
    Ran(1-100) will give a number between 1 to 100
    or
    Ran(1-10,1) will give a number between 1 to 10 including 1 decimal, so from 1,0 - 1,1 - 1,2 up to 10,0

    i need timeGetTime and/or QueryPerformanceCounter, so something similar without the need of the API.
    To me that sounds more like functionality that should be part of a library rather than the language, broadly speaking it looks like you want to be doing something graphics heavy, possibly some kind of game and all those things would certainly help you but don't seem like part of the core language to me.

  20. #300
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by techgnome View Post
    The proposed syntax wouldn't replace the existing syntax either. It would simply add to it.
    The problem is the existing code.

    Now Dim a, b, c as Integer means that a is Variant, b is Variant and c is Integer.
    With that new rule, a is Integer, b is Integer and c is Integer.

    If the code flow enters some part where a = "hello", it will fail. Perhaps it never happens to you when you test it, but it happens to final users.

    IMO it's too late now to change that.

  21. #301

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    481

    Re: Vb6 , the Future, and what I have discovered

    From My perspective changing the way variables get declared is almost a laughable request.

    I would imagine once the compiler and new IDE is working those kind of changes are trivial.

    The fact that this is what is being brought up as important blows my mind.

    In my opinion the key is we work together to get a scaffold ide and compiler working and testing, and then at that point could we ask for such trivial things.

    Olafs recommendation for 1:1 .cls and .bas compatibility sounds like a VERY rational and good step forward. If I had that today, I could get all my back-end code re-compiled today, and just rework my GUI. It would be a dream come true.

    I also have to say in the beginning I did not properly see Olafs vision, but the more I use his framework the better I understand. I really believe this new framework is a house build on a proper foundation. My products have been vastly!!! improved by it, and I am now competing with products written in QT, Delphi, .NET, and C++, and match up features 1:1.

    My suggestion to Olaf to speed up his release is this:


    • Create a release plan, with a list of things that need to be done.
    • Then people capable of each of those task can volunteer to take each one on.
    • Olaf can give guidance on how each task needs to be carried out and can import it and implement it when its ready into his main project.



    I think there is alot of talent here, and if we work together this framework , IDE and compiler can become a reality much sooner.

    WP

  22. #302
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Sitten Spynne View Post
    "Simplicity" means many things to many people. To some that means the language has as few keywords and/or features as possible. C is a really good example of a "simple" language in this respect: very few keywords, very few statements to learn. To others that means the language has features that make common tasks very easy to do. Perl is a "simple" language from this viewpoint: it can do remarkably complex text processing in a fraction of the functional lines of code other languages require. Yet both of those languages have a reputation for being ridiculously complex. Meanwhile I'd argue VB6 has more keywords and features than C but is considered "simple". It is not easy to define "simple".
    My opinion in this regard is the following:
    If the language has many keywords, the problem only arises when someone needs to read someone else's code.
    Because if the language has 200 keywords and you only use 50, it is still "simple" for you (as long as you don't need to understand other's code).

    There are some VB6 keywords that I learned after many years.

    The second seems to me a more important kind of simplicity. To be able to have some common tasks completely (or most of them) automated.

    For example: to add an option in the StartUpPosition property of the forms: CenteredScreenPersistable

    If the user moves and/or rezises it, the next time to remember the size and position.

    Another one: to add another option to show a form, instead of just having vbModal, to have vbSemiModal.
    In that case the form would be modal, but allowing to show other non modal forms if needed.

    Any of those features would change the backward compatibility, but would add features of great help for the programmer.

  23. #303
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Eduardo- View Post
    The problem is the existing code.

    Now Dim a, b, c as Integer means that a is Variant, b is Variant and c is Integer.
    With that new rule, a is Integer, b is Integer and c is Integer.

    If the code flow enters some part where a = "hello", it will fail. Perhaps it never happens to you when you test it, but it happens to final users.

    IMO it's too late now to change that.
    +1 for that... I wasn't thinking clearly, especially since it then seems to contradict what I then said about Olaf's main directive being 100% backwards compatible. So yeah, I agree that it shouldn't be changed.
    I have a couple ideas that for alternatives, but I think for now, I'll leave it as it is and allow the discussion to continue.

    -tg\
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  24. #304
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Vb6 , the Future, and what I have discovered

    Long term feature request:
    (I agree with the general theme of the last few posts, that "cloning VB6" is already an ambitious goal so if release 1 includes "also improve it" it'll take that much longer. That said, it can't hurt to brainstorm "down the road" features even if they're tabled for later. My favorite upcoming C# feature's already been delayed for 4 language versions!)

    So here's what I think is the most valuable feature in VB .NET. It adds enough flexibility and power that if it weren't an object-oriented language, you can use this feature to implement features like polymorphism. .NET calls them "delegates", everyone else is content with "function pointers" and I think that helps understand what they are.

    They're the result of asking, "What if I could have a variable that represents a method?" (A "method" is a Sub or Function.) VB6 already has part of the mechanics needed, but a quick search seems like it's only used in terms of making native calls. So if you're calling something like EnumWindows(), the lpEnumFunc parameter is going to be "the address of a function", so you use AddressOf. As far as I can see, this is the only way VB lets you execute functions via that address.

    In VB .NET, instead of a Long, AddressOf returns a "delegate type". A lot of the details of what that means can be shed in a VB6 context because we aren't as worried about a strong type system. Think of a "delegate type" as a kind of object with the same properties as a method:
    • The address.
    • The number and types of parameters.
    • The return type if it's a Function.


    So:
    Code:
    Sub DoSomething()
        MsgBox("Hello.")
    End Sub
    
    Sub Example() 
        Dim action = AddressOf DoSomething
        ' Now 'action' represents "a Sub that takes no parameters" and points
        ' at DoSomething().
    
        action() ' Displays the message box.
    End Sub
    So what's the type of 'action' in a VB6 context? I'm not sure what would make sense. .NET uses a language feature called generics to help describe this. DoSomething() matches a delegate named Action. Things get more complex with functions because they have return values. In .NET:

    Code:
    Function CalculateSomething(ByVal input As Integer) As Double
        Return input * 10.0
    End Function
    
    ' --- example usage
    Dim c As Func(Of Integer, Double) = AddressOf CalculateSomething
    Dim result As Double = c(10)
    "Func" is a set of delegate types that can represent functions up to about 10 parameters. The (Of ??) syntax indicates "this is a generic type and these are the type parameters". The last type parameter of a Func(Of ??) is always its return value, and any parameters before it are the parameter types. So since CalculateSomething() takes an Integer and returns a Double, it's a Func(Of Integer, Double).

    In .NET, any two methods with the same parameter lists and return types are compatible.
    Code:
    Sub DoSomething()
    Sub DoSomethingElse()
    Sub DoSomethingWith(ByVal value As Integer)
    
    ' Valid
    Dim action As Action = AddressOf DoSomething
    action = AddressOf DoSomethingElse
    
    ' Not valid
    action = AddressOf DoSomethingWith
    There are lots of interesting type system questions concerning whether methods are compatible with each other. In a VB6 context, you might make different choices than .NET made. For example, in .NET it is not true that you can assign a method that takes a Double parameter to an Action(Of Integer) delegate. But we can reason that Integer is implicitly convertible to Double, so we could choose to allow this conversion.

    This concept is extended further if we allow "anonymous methods". These represent methods that don't have a name: we define their bodies on the fly and intend to use them in very small scopes, so in some ways leaving them anonymous helps with encapsulation. They use syntax similar to method declarations, but this syntax acts like an Expression that returns the appropriate Action or Func delegate.

    The formal syntax looks like:
    Code:
    Dim action As Action = Sub()
                                MsgBox("Hello")
                           End Sub
    As a syntax sugar, single-line anonymous methods are allowed and do not require the End statement:
    Code:
    Dim calculate As Func(Of Integer, Integer) = Function(ByVal n As Integer) n * 10
    Via a .NET language feature called type inference, (and possibly via VB6 being looser about types), production code tends to look more like:
    Code:
    Dim process = Function(i, j) i + j * 10
    The syntax and typing rules aren't as important as having the notion of "a variable that can represent a method". I don't want to bicker over syntax, if you can think of a better one, or something that looks "more VB", that's cool.

    So why do I want this feature? It enables some very neat, flexible APIs.

    Think about a sorting algorithm. The fun parts of them involve how they perform their sort, but we can describe just about any sorting algorithm as a lot of fluff around "compare two things and put them in a place based on the comparison". So by convention, we can define a comparison function as something like:
    Code:
    Function Compare(x, y) As Integer
        * If x < y Return -1
        * If x = y Return 0
        * If x > y Return 1
    So normally, when we write a sorting algorithm, we take a collection of "something" and do some work to get down to the comparison for that "something". In really old VB .NET, before we had good delegate support, I'd write a lot of code like this:
    Code:
    Function CompareCustomersByLastName(ByVal left As Customer, ByVal right As Customer) As Integer
        Dim lastResult As Integer = String.Compare(left.LastName, right.LastName)
        If lastResult = 0 Then
            Return String.Compare(left.FirstName, right.FirstName)
        Else
            Return lastResult
        End If
    End Function
    And I'd have a host of sorting methods:
    Code:
    Sub SortCustomersByLastName()
        ' <blah blah sorting code>
        If CompareCustomersByLastName(current, next) Then
            Swap(_customers, currentIndex, nextIndex)
            ' ...
    End Sub
    
    Sub SortCustomersByState()
        ' <blah blah sorting code>
        If CompareCustomersByState(current, next) > 1 Then
            Swap(_customers, currentIndex, nextIndex)
            ' ...
    End Sub
    With function pointers and anonymous functions, I'm now able to remove a lot of that tedium. I can write a more generalized sort:
    Code:
    Sub Sort(Dim data As ???, Dim comparison As Func(Of ???, ???, Integer))
        ' <blah blah sorting code>
        If comparison(left, right) > 1 Then
            Swap(data, leftIndex, rightIndex)
            ' ...
    Now I can do many different kinds of sorts without writing many different methods:
    Code:
    Sort(customers, Function(left, right)
                        If left.LastName = right.LastName Then
                            Return left.FirstName.CompareTo(right.FirstName)
                        Else
                            Return left.LastName.CompareTo(right.LastName)
                        End If
                    End Function)
    But we can take this further. More simple sorts like CompareCustomersByState() only look at one property. In that case, we only need a function that tells us what property we should sort by:
    Code:
    Sub Sort(Dim data As ???, Dim getSortKey As Func(Of ???, ???))
        ' <blah blah sort code>
        If getSortKey(left) > getSortKey(right) Then
            Swap(data, leftIndex, rightIndex)
            '...
    That tends to be a good bit more elegant in usage:
    Code:
    Sort(customers, Function(c) c.Balance)
    .NET went and made an entire library that formalizes operations on collections that happen very frequently. Mixing and matching named and anonymous methods with this library can lead to extremely expressive code. For example, suppose I'm reading a CSV file where each line represents customer data. Here's how I could get the 10 customers who owe me the most money in the state of Texas:
    Code:
    Dim topTen = File.EnumerateLines(path)
                     .Select(AddressOf ParseCustomer)
                     .Where(Function(c) c.State = "TX")
                     .OrderBy(Function(c) c.Balance)
                     .Take(10)
    EnumerateLines() will spit out more or less an array of the lines from the file (what it does is more efficient but not important.) Select() expects to receive a function that takes one parameter and returns something else: in this case ParseCustomer() is a function that parses the CSV line into a Customer object. Where() expects a function that takes an item and returns a Boolean: it returns only the items from its input collection that cause the function to return True. OrderBy() expects a function that returns the "sort key" for an object. .Take() is used to return only the first 10 elements.

    As that last example shows, function pointers can be used to write extremely flexible chains of functions that replace very boilerplate For loops we write all the time. For example, this is an implementation of Select() with more VB6-like than VB .NET style typings:
    Code:
    Public Function Select(ByVal input() As Collection, ByVal transform As Func(Of Variant)) As Collection
        Dim results As Collection
        For i As Integer = 0 To UBound(input)
            results.Add(transform(input(i))
        Next
    
        Return results
    End Function
    In terms of efficiency, it's up to how the various functions are written. Select() has to iterate an entire collection to do its work, as does OrderBy(). But some functions like Where() or Any() can quit earlier. Sometimes writing out all of the code can save you some iterations. But note in the above example this isn't really the case: traditional code would have to finish parsing all of the lines before it could sort them, so there's not a way to get through that problem without at least two full iterations of the original collection, and a full allocation of a new collection.

    You've written that about a million times. Select() lets you skip to just the conversion part. There's a fairly big library of really common collection interactions that take function pointers so you can adapt them to a wide array of inputs.

    The syntax here isn't super important to me, it's the concept of being able to pass in methods as parameters to other methods. I think VB6 could actually be a little less frustrating than VB .NET here because the rules for how .NET treats things with generic parameters are sometimes not intuitive, and VB6 isn't so obsessive about requiring explicit type conversions. But you'd probably still want some syntax so in a method parameter list you can point out exactly what kind of sub/function you expect.

    This feature has a high learning curve and is mostly intended to help experts write more expressive code. Newbies stumble over it left and right. Nonetheless, it's considered so important it's part of most fundamental APIs in .NET, so people have to confront it and overcome it. Perhaps a "VB7" might choose to be more judicious and put function-pointer based APIs in an optional set of built-ins for experts.

    I don't care to rebut or argue if it's considered "too complex" or "not needed", because it is very complex and the only example of VB6 allowing such things involved a neat little abuse of Windows API. Like it or not, I had fun explaining it.
    Last edited by Sitten Spynne; Feb 1st, 2018 at 02:07 PM. Reason: Messed up a For loop!
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  25. #305
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Vb6 , the Future, and what I have discovered

    Olaf want us to involve ourselves, and give suggestions. language wise, I don't want to change VB6 that much, but I would like some new commands/built-in functions.
    Olaf did say we need to be os independent, and my suggestions mostly are to avoid using API at all, or subclassing (that also need API).
    to make VB6 good enough is also to make it fast and have a nice set of graphic commands. tons of discussion in the past is about how to make VB6 a good choice for making games or tools using custom guis, and most of the time is that VB6 is slow and we need to use dx or something else external to speed things up. GDI is good, but API again.
    So Im not sure what you want me to suggest? the new IDE should be 1:1 of VB6 + more. thats how I envision it, why restrict it to be simple as VB6 when we can add more features, and why be scared to add a robust and fast graphic set of commands? no, without that Im not that interested, theres other basic out there that I could start working with that gives me better graphic support.

    also, cpu/gpu hungry programs and usually about graphics. so, i dont see any problems adding better support for rendering, even with the cost of some cpu usage.
    if Olaf is doing the IDE he could integrate everything anyway. all components and the form need to be rendered. so i dont see the problem that we have events for that. we have paint event and its almost that.

  26. #306
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Vb6 , the Future, and what I have discovered

    @Sitten Spynne
    historically the way COM/VB6 Implements delegates is by using Interfaces (IComparable) or Events.

    edit: The standard method of calling function pointers in VB6 nowadays is leveraging DispCallFunc().

    Personally I'm not in favor of adding generics to the language. I'm more of a purist I guess.
    Last edited by DEXWERX; Feb 1st, 2018 at 02:54 PM.

  27. #307
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by DEXWERX View Post
    @Sitten Spynne
    historically the way COM/VB6 Implements delegates is by using Interfaces or Events.

    edit: The standard method of calling function pointers in VB6 nowadays is leveraging DispCallFunc().

    Personally I'm not in favor of adding generics to the language. I'm more of a purist I guess.
    Yes, I think a lot of motivation for adding more delegate syntax sugar in .NET came from dealing with events and event handlers. In .NET they're an even weirder type of delegate called a "multicast delegate", each event is more like "a list of subs that will be executed in serial when this event is raised". I suspect DispCallFunc() is similar to a StackOverflow post I saw discussing an API trick.

    I agree on generics. They were needed in .NET because the type system is very strict and didn't allow for late binding in a meaningful way. What I know of the VB6 type system tells me generics would add a lot of trouble and very little value. I used the generic syntax from .NET because I didn't feel like trying to design a different one, but I think a system of delegates that "feels" more VB6 would be more permissive. Still, to make a method that expects a delegate, it's convenient to be able to describe via the parameter type at least how many parameters the delegate takes.
    Last edited by Sitten Spynne; Feb 1st, 2018 at 02:47 PM.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  28. #308
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Sitten Spynne View Post
    Yes, I think a lot of motivation for adding more delegate syntax sugar in .NET came from dealing with events and event handlers. In .NET they're an even weirder type of delegate called a "multicast delegate", each event is more like "a list of subs that will be executed in serial when this event is raised". I suspect DispCallFunc() is similar to a StackOverflow post I saw discussing an API trick.

    I agree on generics. They were needed in .NET because the type system is very strict and didn't allow for late binding in a meaningful way. What I know of the VB6 type system tells me generics would add a lot of trouble and very little value. I used the generic syntax from .NET because I didn't feel like trying to design a different one, but I think a system of delegates that "feels" more VB6 would be more permissive. Still, to make a method that expects a delegate, it's convenient to be able to describe via the parameter type at least how many parameters the delegate takes.
    makes sense. the += delegate form is basically how Javascript handles events.
    Multicast is also built into COM/VB6 event subscription system (IConnectionPoint etc).
    The nice thing about piggybacking on COM is it can be cross process.
    I think .NET also created an IComparable interface for generic/Object comparisons. I believe this pre-dates delegates.

  29. #309
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by baka View Post
    Olaf want us to involve ourselves, and give suggestions. language wise, I don't want to change VB6 that much, but I would like some new commands/built-in functions.
    Olaf did say we need to be os independent, and my suggestions mostly are to avoid using API at all, or subclassing (that also need API).
    to make VB6 good enough is also to make it fast and have a nice set of graphic commands. tons of discussion in the past is about how to make VB6 a good choice for making games or tools using custom guis, and most of the time is that VB6 is slow and we need to use dx or something else external to speed things up. GDI is good, but API again.
    So Im not sure what you want me to suggest? the new IDE should be 1:1 of VB6 + more. thats how I envision it, why restrict it to be simple as VB6 when we can add more features, and why be scared to add a robust and fast graphic set of commands? no, without that Im not that interested, theres other basic out there that I could start working with that gives me better graphic support.

    also, cpu/gpu hungry programs and usually about graphics. so, i dont see any problems adding better support for rendering, even with the cost of some cpu usage.
    if Olaf is doing the IDE he could integrate everything anyway. all components and the form need to be rendered. so i dont see the problem that we have events for that. we have paint event and its almost that.
    I don't think there is anything wrong with that... the thing to keep in mind is that there will be three classes of features: Language, Library, and IDE... although, you can probably combine Library and IDE into a singular "tool" category, it might be better to keep them separated.

    This is where these projects can get themselves into trouble. by blurring the lines between those three different sets of functions/features. They really do need to be kept as three different lists. There may be some cross over between the IDE and the language lists, where a change in the language necessitates a change to the IDE, but a change to a library shouldn't necessitate a change to VB the language.

    So, for instance, the event of mouse leaving a picturebox. That's not a language feature. That's a library feature. That's something that the library that implements the PictureBox has to do, not part of the VisualBasic lexicon. That's actually something that probably could be done now. It doesn't need to wait for VB-NG. That's all I'm saying - just be cognizant of the request being made and whether it is truly a language addition, or a library feature.

    I didn't address the Twip/Pixel suggestion, but I will now. Maybe that's something that could be an IDE option feature. Set your options so that the default ScaleMode is Pixel... someone else can use Twips. Hmmm.... maybe that should be a project setting... I could see a problem where two developers with conflicting settings could cause chaos. OK, so make it a project setting. So when a new item is added, it sets the ScaleMode automatically. Again though, this would be a feature/function of the IDE, not specific to the VB language.

    The paint event is just that an event... it's raised by the component in the library... but it's still not part of the fundamental VB language. If the component can raise it, VB can catch it, to do so doesn't require any change to the language.

    Does that make sense? See the distinction?

    I'm not saying that your suggestions don't have merit, because they probably do, but for matters of what people want to see from VB-NG, the lines between the lists need to be clear and distinct, lest the waters get muddied and then Olaf has to reject things, people get all bent out of shape, words are had, punches thrown, and the next thing you know Shaggy is having to start a kickstarter campaign to raise bail money. And I think he has better things to do like counting fish in a barrel.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  30. #310
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Vb6 , the Future, and what I have discovered

    Delegates can be implemented on IDispatch and future code can look like this
    Code:
    Dim oDelegate As Object
    Set oDelegate = DelegateOf(obj.MyMethod)
    ...
    result = oDelegate(1, 2, "three")
    Last line calls default method on IDispatch interface. `DelegateOf` operator creates a small trampoline object that calls `MyMethod` on `obj` instance instead. I suppose `DelegateOf` operator can work for routines in .bas modules too. It will be like a "managed" version of `AddressOf` operator -- on release will manage trampoline memory that needs to be deallocated.

    cheers,
    </wqw>

  31. #311
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Eduardo- View Post
    The problem is the existing code.

    Now Dim a, b, c as Integer means that a is Variant, b is Variant and c is Integer.
    With that new rule, a is Integer, b is Integer and c is Integer.

    If the code flow enters some part where a = "hello", it will fail. Perhaps it never happens to you when you test it, but it happens to final users.

    IMO it's too late now to change that.
    The way I wanted to introduce all of Niyas indeed very "cheap to implement" features (as DexWerx already commented),
    already in version 1.0, is the way the FreeBasic guys solved that (without the need to give an explicit: 'Option LazyTyping ' or something)

    Variable- and Array-Initializers are available in the C-Compiler already, so that will translate very well -
    and what Eduardo rightfully pointed out, was solved by the FreeBasic-guys this way (by "inverse notation").

    If you type (as you are currently accustomed to):
    Code:
    Dim a, b, c As Integer
    Then the compiler will behave entirely backwards-compatible (a and b being Variants, c being a 16Bit-Integer, as before in "the old compiler").

    Though if you want to be more "lazy", you can write the Type first, followed by the "List of Symbolnames" (without the type-specifier):
    Code:
    Dim As Integer a, b, c  '<- all of these symbols would be recognized as 16Bit-Integers
    
    'alternatively, with Initializers:
    Dim As Integer a=1, b=2, c=3  '<- all of these symbols would be recognized as 16Bit-Integers, initialized with the values 1, 2, 3
    
    'alternatively, also with Initializers, but explicit Type-assignments again (as used to) for each single symbol-name:
    Dim a As Integer = 1, b As Integer = 2, c As Integer = 3  '<- explicitely typed 16Bit-Integers, initialized with the values 1, 2, 3
    
    'and of course the old "shorthands" would work as well (with or without value-initializers)
    Dim a% = 1, b% = 2, c% = 3  '<- explicitely typed 16Bit-Integers, initialized with the values 1, 2, 3
    These two different kinds of Typespecifyer-Placement would be "detectable without making mistakes" by the parser:
    - the "lazy guys" would get what they want
    - the "conservative guys" can still type it, as they are used to

    When I first saw that "free switchable way of type-specifier placments" in FreeBasic, I was a bit "what the heck"?
    But after only a few days I barely noticed it anymore (though still typing my types as before in VB6, when writing FreeBasic-code).

    It's IMO a nice way to solve the problem of "keeping up backwards-compatibility", and still offering an alternative way for
    "switchers from other languages" (where typespecifiers are usually on the "right side" ... meaning "to the left of the symbol" ) .

    Olaf
    Last edited by Schmidt; Feb 1st, 2018 at 10:18 PM.

  32. #312
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Vb6 , the Future, and what I have discovered

    I agree that we need 100% backward language compatibility, and then extend from there. Here's a few little "boring" things on my wishlist.:

    New operators:

    +=
    Add value on right to variable on left. So MyVar += 10 instead of MyVar = MyVar + 10

    -=
    Same as above, but for subtraction.

    ++
    Increment a variable by 1. E.g. MyVar++ instead of MyVar = MyVar + 1

    --
    Same as above, but for subtraction.

    &=
    Append value on right as string to variable on left. e.g. MyVar &= "Append me" instead of MyVar = MyVar & "Append Me".

    Of course the old methods of doing the same would still be possible.

    I think bitwise operators would be useful too.

    Some way to represent binary number would be good, so like &H and &O for hex and octal, we could also have &B for binary. e.g. &B01010101

    I second the motion for initializing variables at Dim-time. I think Dim MyFlag As Long = -1 is nicer than the two liner.

    I'd like a "this" keyword for events that refers back to the object that raised the event. Not sure if this is possible except as a late bound object though which would limit its usefulness (probably wouldn't bother in this case), but it would be nice if "this" took on the full object type.

    So instead of:

    Code:
    Private Sub List1_Click()
       If Me.List1.Tag = Me.List1.ListIndex Then Exit Sub
    
       Select Case Me.List1.ListIndex
       Case Is 0 to 4
          ' Do Something
       Case Else
          ' Do Something Else
       End Select
    
       Me.List1.Tag = Me.List1.ListIndex
    End Sub
    We could have:

    Code:
    Private Sub List1_Click()
       If This.Tag = This.ListIndex Then Exit Sub
    
       Select Case This.ListIndex
       Case Is 0 to 4
          ' Do Something
       Case Else
          ' Do Something Else
       End Select
    
       This.Tag = This.ListIndex
    End Sub
    I'd also like a "return" keyword for functions (it would have to have a different name since Return is reserved for Gosub...Return). It would hold a reference to the function return variable and behave exactly the same as typing out the full function name to set return values, pass to other methods, etc... Again not sure if this would be possible for the same reasons as the "this" keyword.

    For example, instead of:

    Code:
    Function ThisIsMyNiceDescriptiveFunctionName(ByVal MyVar As Long) As Long
       ThisIsMyNiceDescriptiveFunctionName = MyVar / 10
       If ThisIsMyNiceDescriptiveFunctionName > 100 Then
          ThisIsMyNiceDescriptiveFunctionName = 100
       ElseIf ThisIsMyNiceDescriptiveFunctionName < 10 Then
          ThisIsMyNiceDescriptiveFunctionName = 10 
       End If
    End Function
    We could have:

    Code:
    Function ThisIsMyNiceDescriptiveFunctionName(ByVal MyVar As Long) As Long
       Return = MyVar / 10
       If Return > 100 Then
          Return = 100
       ElseIf Return < 10 Then
          Return = 10 
       End If
    End Function
    Besides being shorter and (imho) easier to read, if you have to change a function name you only have to do it in one spot.

    Lastly, maybe Try...Catch...Finally? I've been using it (or similar, I think it is Try...Except...Finally) in Pascal a bit, and I find there are some situations where it is really handy. Especially for working with APIs that require you to perform cleanup of resources, but even for things where you might frequently expect errors and want to handle them close to the error line, then cleanup and move on.

  33. #313
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Schmidt View Post
    Code:
    Dim As Integer a, b, c  '<- all of these symbols would be recognized as 16Bit-Integers
    
    'alternatively, with Initializers:
    Dim As Integer a=1, b=2, c=3  '<- all of these symbols would be recognized as 16Bit-Integers, initialized with the values 1, 2, 3
    Oh I like that

  34. #314
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Schmidt View Post
    Code:
    Dim As Integer a, b, c  '<- all of these symbols would be recognized as 16Bit-Integers
    
    Olaf
    Quote Originally Posted by jpbro View Post
    Oh I like that
    I do too... it's probably cleaner than what I was thinking which was along these lines:
    Code:
    Dim a, b, c ALL As Integer  '<- all of these symbols would be recognized as 16Bit-Integers
    
    Essentially by adding All as keyword that would trigger all variables to the left as that type.

    Olaf, quick question, with the format you proposed, would it still be possible to mixed types on the same line? Something tells me no, but it's not loud enough for me to believe that.

    With the All kw, I'd see it like this:

    Code:
    Dim a, b, c All As Integer, FirstName, LastName All As String, SomeVar
    Talk about reading like an English sentence!

    With that, I'd end up with three integers, two strings and one variant.
    I wouldn't be opposed to either method.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  35. #315
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by DEXWERX View Post
    I think .NET also created an IComparable interface for generic/Object comparisons. I believe this pre-dates delegates.
    Yes, and this is another good example of how delegates are a bit more flexible than OO concepts.

    If you're using someone else's type, you can't modify the source code, and they didn't implement IComparable, that's that. The only way you can use that type with an API expecting IComparable is if you use the Decorator pattern to wrap it. Worse, sometimes the people who implemented IComparable picked comparison logic you didn't agree with. There wasn't a good way to create multiple ways to compare the objects.

    So there was also IComparer. This let you write a type yourself to compare types where you couldn't add your own IComparable implementation. You could also write multiples so you could have different comparison behaviors. This was pretty nice, but not all APIs across the framework deal with both. And if you're implementing an API yourself, you have to remember to provide support for both, which is a teeny bit more work.

    So the Comparison delegate is a good new arrival, it's as flexible as IComparer but you don't necessarily have to implement a host of different comparer types. And if you only need one kind of comparison in one specific context, you don't even have to bother with a named function.

    Unfortunately this creates a problem common throughout .NET: some APIs use IComparable. Others use IComparer. Others use the delegate. Sometimes MS updates APIs to use delegates. Other times they don't. So you have to learn all three techniques.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  36. #316
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Vb6 , the Future, and what I have discovered

    i definitely like Olaf/FreeBasic's and tg's variations.

  37. #317
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: Vb6 , the Future, and what I have discovered

    One thing that could be useful, and I think that it is implemented in .Net, is: when a condition within an If clause is False, if there are other AND's conditions after it not to waste time evaluating every one needlessly.

    Unfortunately, perhaps very few programs but may be some could change the behaviour changing that.

    In .Net I think they added a new keyword, IFF.

  38. #318
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Eduardo- View Post
    One thing that could be useful, and I think that it is implemented in .Net, is: when a condition within an If clause is False, if there are other AND's conditions after it not to waste time evaluating every one needlessly.

    Unfortunately, perhaps very few programs but may be some could change the behaviour changing that.

    In .Net I think they added a new keyword, IFF.
    this was debated at some point - due to the fact that some VB4/5/6 code rely on the non-short circuit (eager) evaluation. .NET ended up going with OrElse/AndAlso for backward compatibility.

    For reference C's logical operaters (&& ||) are short circuited. VB however uses binary operators, so direct translation to C would also be compatible using the binary operators (& | ). (correct me, i may be wrong)
    Last edited by DEXWERX; Feb 1st, 2018 at 05:26 PM.

  39. #319
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Eduardo- View Post
    One thing that could be useful, and I think that it is implemented in .Net, is: when a condition within an If clause is False, if there are other AND's conditions after it not to waste time evaluating every one needlessly.

    Unfortunately, perhaps very few programs but may be some could change the behaviour changing that.

    In .Net I think they called it IFF.
    Idiomatically VB .NET developers tend to say we got more logical comparison operators, these would be cheap to add to "VB7".

    x() AndAlso y() uses short-circuiting. It evaluates x(), and if it returns False it won't evaluate y(). Same with x() OrElse y(), it won't evaluate y() if x() evaluates to False.

    The functions If() and IIf() exist in VB .NET but are confusing as heck, particularly since "If" is a keyword.

    I can write:
    Code:
    IIf(True, Foo(), Bar())
    Both Foo() and Bar() will be executed, and the function returns whatever Foo() returns. (Also note I didn't have to use the return value.) This is scary if you're trying to, say, avoid a divide-by-zero:
    Code:
    Dim result = IIf(bottom <> 0, top / bottom, 0) ' Kaboom!
    If() is sort of confusing because it is NOT a function, it is a language keyword with function-like syntax. If you don't assign its result to something the compiler gets confused and thinks you meant an If..Then statement. If it were a function, it could NOT short-circuit, because part of binding parameters involves evaluating expressions. I guess the compiler's rewriting it:
    Code:
    Dim result = If(bottom <> 0, top / bottom, 0) ' Returns 0
    I don't personally use either one, partially because I never went to look up why the heck there are two and why one has a funky name.

    One neat use is as a "null coalescing operator", which has some interesting comparisons in C#. Maybe you do something based on a name input, but it's not always there:
    Code:
    Dim textLength = If (strName Is Nothing, 0, strName.Length)
    C# has a special operator for that, you could write:
    Code:
    var textLength = (strName ?? "").Length;
    It was expanded recently to be a bit more useful:
    Code:
    var textLength = strName?.Length;
    That "?." operator has a sense of, "If the thing to my left is Nothing, return the default value for the type this expression will evaluate to." It chains:
    Code:
    var textLength = forms?.Item("mainForm")?.txtName?.Text.Length
    That returns 0 if any object in the chain is Nothing. I made fun of that particular example often when it was coming out, but it's a pretty useful operator in the end.

    That said, as far as I can tell in VB6 Len(Nothing) evaluates to 0 without an error anyway so it's a poor example, but sometimes we aren't so lucky.

    OH, also, new idea: For Each loops.

    When we want to look at everything in an array, you write:
    Code:
    For i As Integer = 0 To UBound(_array)
        Dim item As ??? = _array(i)
        ' Do stuff
    Next
    For Each loops smooth that over:
    Code:
    For Each item As ??? In _array
        ' Do stuff
    Next
    .NET adds a lot of rules for supporting For Each loops for things that aren't arrays but "look like" collections, but all in all as a syntax sugar it's nice. It explodes if you try to change the array from within the loop, but that was true of For loops anyway, right?
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  40. #320
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Vb6 , the Future, and what I have discovered

    Quote Originally Posted by Sitten Spynne View Post
    OH, also, new idea: For Each loops.

    When we want to look at everything in an array, you write:
    Code:
    For i As Integer = 0 To UBound(_array)
        Dim item As ??? = _array(i)
        ' Do stuff
    Next
    For Each loops smooth that over:
    Code:
    For Each item As ??? In _array
        ' Do stuff
    Next
    .NET adds a lot of rules for supporting For Each loops for things that aren't arrays but "look like" collections, but all in all as a syntax sugar it's nice. It explodes if you try to change the array from within the loop, but that was true of For loops anyway, right?
    We have For Each in COM/VB6 per IEnumerable. The caveat is that Item has to be a Variant.
    It also works for Intrinsic Type arrays.

    my codebank post for supporting For Each on a custom collection. --> http://www.vbforums.com/showthread.p...hout-a-typelib

Page 8 of 18 FirstFirst ... 567891011 ... 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