Results 1 to 36 of 36

Thread: [RESOLVED] Type Mismatch problem regarding an If Else statement

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2021
    Posts
    5

    Resolved [RESOLVED] Type Mismatch problem regarding an If Else statement

    Hi! I'm trying to create a form wherein the Then statement will only run if both variables are not empty (both has text) while if any of each is otherwise, it will open a warning. My problem is that it says type mismatch whenever I fill both (or either of it).

    Code:
    Private Sub Command1_Click()
    
    Dim V, B, Msgxyza as String, x As New form2
    
    If V And B <> Empty Then
    Open "C:\Documents\logs.txt" For Append As #1
    Print #1, "Username: " & V & " " & "ID: " & B
    Close #1
    Unload Me
    x.Show
    Else
    Msgxyza = MsgBox("Please input the needed information", vbOKOnly + vbExclamation, "Warning!")
    End If
    
    End Sub

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,878

    Re: Type Mismatch problem regarding an If Else statement

    The proper syntax would be
    Code:
    If V<>"" and B<>"" then

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2021
    Posts
    5

    Re: Type Mismatch problem regarding an If Else statement

    Thank you!

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

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    ...and V and B are not Strings, but Variants
    and just reading that code-snippet i have no idea how V and B can be anything else than empty
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2021
    Posts
    5

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Zvoni View Post
    ...and V and B are not Strings, but Variants
    I kind of understand that, but will there be any differences if I only use string? I ran it with string and it worked perfectly. I'm honestly sorry if I sound dumb here as I started learning this language only recently.

    Quote Originally Posted by Zvoni View Post
    and just reading that code-snippet i have no idea how V and B can be anything else than empty
    Regarding that, I assigned both variables to a text box and each has no text until the user inputs anything; hence making it possible to not be empty. Please enlighten me if I misunderstood your statement. Thanks

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,580

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by zhyr View Post
    I kind of understand that, but will there be any differences if I only use string? I ran it with string and it worked perfectly. I'm honestly sorry if I sound dumb here as I started learning this language only recently.
    Possibly.... strings are not variants and variants are not strings. Variants can contain anything, integers, stirngs, objects... so by not being explicit in what the variable holds, you're opening yourself up to potential issues down the road.

    Regarding that, I assigned both variables to a text box and each has no text until the user inputs anything; hence making it possible to not be empty. Please enlighten me if I misunderstood your statement. Thanks
    Code:
    Dim V, B, Msgxyza as String, x As New form2
    
    If V And B <> Empty Then
    Open "C:\Documents\logs.txt" For Append As #1
    That was the code you posted... obviously from your comment you cut out some code... which can be a problem because it cut out some information. You may no have thought it important, but sometimes it is. In this case, knowing how the variant variable was being filled might have helped.

    -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??? *

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,244

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    As stated elsewhere, I like Variants, but I strictly reserve their use for cases where they're needed. If an explicit type will get the job done, that is absolutely what I'll do, and it's what should be done in this case.

    And, truth be told, there was just too much wrong with the OP's code for me to comment. The following line was just very nasty to my eyes, especially knowing that V and B were Variants:

    Code:
    
    If V And B <> Empty Then
    
    zhyr, sorry if I've offended. Welcome to VBForums. I do hope you stick around.
    Last edited by Elroy; Nov 25th, 2021 at 02:48 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,878

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by zhyr View Post
    I kind of understand that, but will there be any differences if I only use string?
    Actually you are not using strings though you should be.

    Code:
    Dim V, B, Msgxyza as String, x As New form2
    is the same as
    Code:
    Dim V as variant, B as variant, Msgxyza as String, x As New form2
    To get them as strings you need to use
    Code:
    Dim V  as String, B  as String, Msgxyza as String, x As New form2

  9. #9
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,244

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    I feel a bit compelled to explain a bit why I'm so harsh about the If V And B <> Empty Then line of code.

    First, Empty is a specific value that a Variant can take on, and it's actually the same as a completely initialized variant, as VT_EMPTY=0. Here's a link that enumerates all the different types a Variant can hold.

    Now, your B <> Empty can cause even more problems. Empty is a special condition of a Variant, and, as such, can sometimes be difficult to detect. For instance, put Set B = Me just before your test, and you'll get a runtime error on your B <> Empty line. And there are other problematic situations you can run into with that type of test. And, that's why we've got the IsEmpty() function. Using that function never generates an error, and more truthfully tells us whether or not a Variant has been initialized (or subsequently assigned to Empty). And just as a further FYI, the Empty built-in value is the way we un-initialize a Variant.

    Ok, on to the next problem. We've got to keep our order-of-operations straight in our expressions. The B <> Empty will be evaluated first, and then the And operator will be executed. When we execute an And operator, both sides are implicitly typecast to either an Integer or a Long (typically a Long, unless both sides are already Integers or Booleans, where Booleans are just special cases of Integers). So, B <> Empty, if it doesn't error, will reduce to a Boolean. And then, there's the issue of what type V is (within the Variant). Whatever type it is, it'll typically be typecast to a Long, almost as if it had a CLng() wrapper on it. So, it's not at all clear what that And is going to do.

    And here's an interesting situation ... what if we assign V as V = "asdf" before we test that line. Since "asdf" can't be typecast (with CLng) to a Long, again, we get an error.

    -----------

    So, bottom line, we need to think through exactly what we'd like to do, and decide if Variants are absolutely needed, and then code up clear-and-concise code that does what we want. In this case, we probably don't want Variants.

    p.s. I soooo wish that Option Explicit didn't allow implicit Variant declarations!!!!
    (LaVolpe's project scanner does check for that though, and I'm quite thankful for that.)
    Last edited by Elroy; Nov 25th, 2021 at 04:00 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2021
    Posts
    5

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    To DataMiser,

    Quote Originally Posted by DataMiser View Post
    To get them as strings you need to use
    Code:
    Dim V  as String, B  as String, Msgxyza as String, x As New form2
    I didn't actually realize that until now! In this version however, do I not have any other choice but to declare them one by one? In some cases where I would need to declare multiple variables of the same type, it would be kind of inefficient. I browsed the internet for ways but the only solution I came up to is joining them together with commas (which is what I did, but clearly is wrong).

    This is what I reffered to.
    Name:  declaringv.jpg
Views: 144
Size:  46.5 KB

    (BTW, please inform me anytime if I'm asking too much questions, or if it's unrelated enough to my original requests in which I'd need to create a new one.)

    To Elroy,

    Thank you. I don't really mind the way of one's delivery! As long as I'm correcting my mistakes, it's totally fine. I feel nothing but grateful to all of you that are very considerate on helping me. Your comprehensive explanation gave me what I needed to take into account.

  11. #11
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,839

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by zhyr View Post
    This is what I reffered to.
    <VB.NET Page>
    Guess they really should have named it Fred instead.

    Olaf

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

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by zhyr View Post
    In this version however, do I not have any other choice but to declare them one by one? In some cases where I would need to declare multiple variables of the same type, it would be kind of inefficient.
    And exactly because of that i declare all my variables each in its own line, and i'm making no difference which language i use (C, VB, Pascal)

    Ask yourself a question: What's more important for "efficiency"? How quick you can write code (as in: Write your declares in one line), or how long it takes you to find the error/mistake causing a bug in your code?

    Quote Originally Posted by Schmidt View Post
    Guess they really should have named it Fred instead.

    Olaf
    I call it DOT CRAP
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  13. #13
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by zhyr View Post
    I didn't actually realize that until now! In this version however, do I not have any other choice but to declare them one by one? In some cases where I would need to declare multiple variables of the same type, it would be kind of inefficient.
    You could do this:-
    Code:
    Dim v$, b$, Msgxyza$, x As New Form1
    It's ugly as hell, I know, but it's more efficient. If you're going to use VB6, you're going to have to put up with this kind of thing. I mean VB6 came out in the stone age and it's dialect is a direct descendant of QuickBasic so it's going to have a lot of things in it that don't make sense.
    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

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,878

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    You can also use the old Define statement though I can't remember it well, been over 20 years since I used it but it is still there in VB6.

    Personally, I usually dim one variable per line and also give them names that are meaningful. The only time I use a single character for a variable name is when it is a loop counter or I am just writing a quick piece of throw away code.

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

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by DataMiser View Post
    You can also use the old Define statement though I can't remember it well, been over 20 years since I used it but it is still there in VB6.
    Does anyone remember the "Rem"-Keyword?
    It still works in vb6.....
    Code:
    Sub Main()
    Rem This is a comment
    
    End Sub
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  16. #16
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by DataMiser View Post
    You can also use the old Define statement though I can't remember it well, been over 20 years since I used it but it is still there in VB6.
    You're talking about this:-
    Code:
    DefInt A-Z
    The above will default all implicit typing to Integer for all variables beginning with any letter between A and Z. You can test like this:-
    Code:
    DefInt A-D
    DefSng E-G
    Private Sub Form_Load()
        
        Dim a, b, c, d, e, f, g
        
        Debug.Print TypeName(a)
        Debug.Print TypeName(b)
        Debug.Print TypeName(c)
        Debug.Print TypeName(d)
        Debug.Print TypeName(e)
        Debug.Print TypeName(f)
        Debug.Print TypeName(g)
    End Sub
    Output:-
    Code:
    Integer
    Integer
    Integer
    Integer
    Single
    Single
    Single
    This is one of the things that was inherited from QuickBasic.
    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

  17. #17
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Zvoni View Post
    Does anyone remember the "Rem"-Keyword?
    It still works in vb6.....
    Code:
    Sub Main()
    Rem This is a comment
    
    End Sub
    This one is ancient. This predates even QuickBasic. That comes all the way from BASICA/GW-Basic.
    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

  18. #18
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,878

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Niya View Post
    This one is ancient. This predates even QuickBasic. That comes all the way from BASICA/GW-Basic.
    So does the DefInt and the $, # and other type identifiers.

  19. #19
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by DataMiser View Post
    So does the DefInt and the $, # and other type identifiers.
    Really? I wasn't aware of Def[Type] statements back then. I only became aware of it when I started programming in QuickBasic Extended a lifetime ago.
    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

  20. #20
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,878

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Niya View Post
    Really? I wasn't aware of Def[Type] statements back then. I only became aware of it when I started programming in QuickBasic Extended a lifetime ago.
    Yep. I used to use them in GWBasic back in the day. I think they may have been in Commodore Basic as well but memory is a bit more foggy on that one.

  21. #21
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,244

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by zhyr View Post
    (BTW, please inform me anytime if I'm asking too much questions, or if it's unrelated enough to my original requests in which I'd need to create a new one.)
    zhyr, you're absolutely fine. With respect to other threads, you really haven't done anything at all that's not still in the vein of your original question. In other words, compared to other threads, this one isn't off the rails at all.

    Regarding too many questions, shucks, that's what we're here for. Ask all you want. We'll enjoy the new blood in the water.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  22. #22
    Fanatic Member
    Join Date
    Jun 2012
    Posts
    981

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Niya View Post
    This one is ancient. This predates even QuickBasic. That comes all the way from BASICA/GW-Basic.
    Brings back lovely memories of coding in 1979 with the Tandy Model 1. Even used 'Electric Pencil' word processing. Fist wrote (and sold) in BASIC on cassettes, then 5.25 floppies, then Model II with 8 inch floppies, the 8 Mb hard disc A$10,000, then IBM PC, then QuickBasic, discovered VB6 much later in life... Unbeatable (Tried .NET -- No thank you. Vb6 MS's finest product. Stupid move discontinuing it.. IMHO!)
    Thanks all!

  23. #23
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by el84 View Post
    Brings back lovely memories of coding in 1979 with the Tandy Model 1. Even used 'Electric Pencil' word processing. Fist wrote (and sold) in BASIC on cassettes, then 5.25 floppies, then Model II with 8 inch floppies, the 8 Mb hard disc A$10,000, then IBM PC, then QuickBasic
    It's nothing short of amazing how far we have come.

    Quote Originally Posted by el84 View Post
    discovered VB6 much later in life... Unbeatable (Tried .NET -- No thank you. Vb6 MS's finest product. Stupid move discontinuing it.. IMHO!)
    I disagree. VB6 had too much historical baggage that was holding it back from going where Microsoft wanted to take it. Starting from scratch was the only option.
    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

  24. #24
    Fanatic Member
    Join Date
    Jun 2012
    Posts
    981

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Niya View Post
    It's nothing short of amazing how far we have come.



    I disagree. VB6 had too much historical baggage that was holding it back from going where Microsoft wanted to take it. Starting from scratch was the only option.
    Fair 'nuff. But where did users want to take it?
    Thanks all!

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

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by el84 View Post
    Fair 'nuff. But where did users want to take it?
    Nowhere.
    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

  26. #26
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,839

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Niya View Post
    VB6 had too much historical baggage that was holding it back...
    Guess it's on you to explain, how "historical baggage" (whatever that is),
    can prevent a few devs, to get to work on an existing CodeBase
    (which is maintained to this day and even produces a 64Bit-version).

    Quote Originally Posted by Niya View Post
    Starting from scratch was the only option.
    No, it wasn't - the VB7-COM-successor was already in late beta-state when they made the decision to cancel it,
    to not cannibalize their .NET-efforts.

    Besides, twinbasic is already showing you, what is possible with COM as the "base-object-model".
    (that much to your "Users are taking it nowhere")...

    When will you start looking at the whole thing objectively?
    Thought you learned something the last months (in those "other threads")?

    Olaf

  27. #27
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Schmidt View Post
    Guess it's on you to explain, how "historical baggage" (whatever that is)
    This isn't my opinion. I got that information from somewhere.. So if you want to debate this, debate it with Tim Anderson, not with me.

    Quote Originally Posted by Schmidt View Post
    Besides, twinbasic is already showing you, what is possible with COM as the "base-object-model".
    I seem to remember Wayne saying his eventual goal of multi-platform support would require an alternative object model. It cannot be based on COM.

    Quote Originally Posted by Schmidt View Post
    (that much to your "Users are taking it nowhere")...
    VB6 died like 20 years ago yet it's staunches supporters refuse to let it go. Does this sound like a group of people that want to go anywhere?

    Quote Originally Posted by Schmidt View Post
    When will you start looking at the whole thing objectively?
    A person that argues for the perseverance of the horse and carriage over the automobile is not thinking objectively. While the former might have some advantages over the latter, the progress is better overall for society. If it wasn't, we'd all still be in the stone age.

    Quote Originally Posted by Schmidt View Post
    Thought you learned something the last months (in those "other threads")?
    You proved that your RichClient library is at least as productive as .Net when it comes to common data-centric tasks. It settled one of my biggest pain points with VB6 but it doesn't mean I suddenly think VB6 is it's equal.
    Last edited by Niya; Nov 29th, 2021 at 04:04 PM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | 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

  28. #28
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,839

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Niya View Post
    This isn't my opinion. I got that information from somewhere.. So if you want to debate this, debate it with Tim Anderson, not with me.
    Never heard of this guy (and I know all the "big names", believe me).
    In short, the article is full of wrong statements.

    And what he considers "historical baggage" is apparently COM (which is still in full-swing everywhere).
    What is dead, is:
    - INDIGO
    - WCF
    - and SOAP

    What's instead still alive and kicking is:
    - COM
    - COM+
    - and MSMQ

    Besides, INDIGO was never a "Replacment of COM+" -
    it always was (as most of the .NET-stuff) - a thin wrapper around existing COM-technology (in this case COM+ and MSMQ).
    https://www.techopedia.com/definitio...rating-systems

    Indigo unifies different Microsoft transport protocols and technologies, including ASP.NET, COM+, Microsoft Message Queuing (MSMQ), Transmission Control Protocol (TCP), HTTP and User Datagram Protocol (UDP)...

    Quote Originally Posted by Niya View Post
    I seem to remember Wayne saying his eventual goal of multi-platform support would require an alternative object model. It cannot be based on COM.
    There will be no changes for COM-compatible Classes at ABI-level (the VTable-concept will work "as is").
    It's only the TypeLib-Infos which have to be duplicated (in a platform-independent format),
    to make Obj-Introspection possible (easiest way is, to just put all Enums and Class-Methods in VTable-Order into a CrLf-separated String).

    Quote Originally Posted by Niya View Post
    VB6 died like 20 years ago yet it's staunches supporters...
    Well, you answered the question already with that short snippet above yourself...
    (a language with enough supporters cannot be "considered dead")...

    And as said, there's the new TwinBasic-compiler (plus a few others "in-progress")...
    and quite a few efforts at the front of "modern, generic Class-libraries and Controls"
    (as e.g. Krools, Leandro Asciertos and my own stuff).

    Quote Originally Posted by Niya View Post
    A person that argues for the perseverance of the horse and carriage over the automobile...
    ...
    You proved that your RichClient library is at least as productive as .Net ...
    And there you have it...
    The VB6-Compiler + a few comparably tiny COM-Dlls ran circles around any .NET-example you so far came up with.

    An this will not change when we will finally replace VB6-Compiler with other, compatible Compilers in the future.

    Olaf

  29. #29
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Let's not get lost in the weeds here with road worn arguments of the past. This isn't about which is better or how great you think COM is. el84 said it was stupid discontinuing VB6 and I responded with the reason why they did it. You don't have to agree with it but this is what happened.

    The thing is you are one person, one voice. There are many voices out there and if many of them are saying the same thing. What objective person would listen to one person trying to deny the chorus of many voices. Here is another article which talks about COM. It say's this specifically:-
    In the late 1990’s as the Internet was exploding, Microsoft had just successfully fought off a full frontal assault on its market dominance by killing the Netscape Web browser with its free Internet Explorer. But Microsoft was facing a host of new challenges, including serious problems with COM, C++, DLL hell, the Web as a platform, security, and strong competition from Java, which was emerging as the go-to language for Web development.

    Microsoft’s response was .NET, an object-oriented development environment and framework that provides a highly-functional abstraction layer between the operating system and programming language.
    Here is another one. This one is kind of long so let me zoom in on the relevant parts:-
    ...and here’s the clincher: I noticed (and confirmed this with a recruiter friend) that Windows API programmers here in New York City who know C++ and COM programming earn about $130,000 a year, while typical Web programmers using managed code languages (Java, PHP, Perl, even ASP.NET) earn about $80,000 a year. That’s a huge difference, and when I talked to some friends from Microsoft Consulting Services about this they admitted that Microsoft had lost a whole generation of developers. The reason it takes $130,000 to hire someone with COM experience is because nobody bothered learning COM programming in the last eight years or so, so you have to find somebody really senior, usually they’re already in management, and convince them to take a job as a grunt programmer, dealing with (God help me) marshalling and monikers and apartment threading and aggregates and tearoffs and a million other things that, basically, only Don Box ever understood, and even Don Box can’t bear to look at them any more.
    Here's the bottom line, you love COM and think it's great yet a lot of people don't and it's not without it's problems. Pay particular attention to how he describes the experience of programming with COM starting with his comment, "God help me". Does he make it sound like people were having a pleasant experience with COM. COM wasn't the only reason Microsoft abandoned VB6 but let's not kid ourselves, it was a major contributing factor.

    One final thing, I want to interject with my own experiences with COM to say that I actually get where he is coming from. COM really is unpleasant to deal with. I've never mentioned this but just before I moved to .Net, even before I was even considering it, I tried to learn COM. I was writing one VB6 application or another and I wanted to figure out why I couldn't use CreateThread in a VB6 application to just spin up a thread whenever I wanted. This led me to multiple articles about COM's apartment threading models. I remember reading these articles multiple times leaving with more questions than answers. Throughout all of this I will never forget what kept running through my mind the entire time, "what possible reason did they have to make this so complicated while it was so simple in C". This constantly recurring thought led me to conclude that COM was an over engineered mess and I could no longer stomach the idea of wasting large amounts of time learning this overly complicated piece of technology. If C programmers weren't required to understand all this threading apartment rubbish to deal with muli-threading then why the hell should I. I could not escape that thought and saw absolutely no reason that convinced me learning anything about COM beyond the basics was anything but a waste of time. Don't even get me started on MIDL, whoa boy!

    Anyways, I had no idea at the time that history would prove me correct. When I finally moved to .Net, guess what, I didn't have to read encyclopedias about apartments in order to figure out how to deal with threads. Just like C programmers could spin up a thread with something like CreateThread, we could spin up threads just as easily now. None of COM's baggage got in the way.

    I get it, you love COM and that's fine but a lot of people don't want to deal with it if they don't have to, including me. Microsoft tried to do something about it and whether what they did was good or bad is another thing entirely but the fact remains that this was one of the reasons for the abandonment of VB6.
    Last edited by Niya; Nov 30th, 2021 at 07:13 PM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | 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

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

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Niya View Post
    ...you love COM and that's fine but a lot of people don't want to deal with it...
    It's not really about "loving or hating COM".

    What you try real hard to deliberately "misunderstand and ignore" in all these threads is,
    that COM is the leaner, better performing "Object-tech", with deterministic teardown behaviour.

    MS prefers it for that reason in all its important new tools (latest example: WebView2.dll).

    Please acknowledge these "plain to see" facts.

    If you're a C/C++ dev then yes, writing COM-Classes in these languages is not the easiest job -
    though there's tools like ATL which make it a bit easier even for these guys.

    And then there's VB6/VBA, which made (and still makes, even in 64Bit) developing
    COM-Classes (and Class-based Controls/Widgets) "as simple as can be".

    That's the sole reason why the *experienced* VB6/VBA-guys here are still sticking with the language (and IDE) -
    and why efforts are made to develop the next generation of an "COM the easy way"-compiler.

    I also have no idea why you bring up "Threading" again, when we had this discussion already -
    (VB outperforming .NET even there, when you look at the "Mandelbrot-Threaded"-discussion a few years ago).

    The only thing you left out so far in your attempts to "find something which is easier to develop in .NET",
    is "Web-based stuff" - though I'm not sure that'd be a good idea either when you do -
    (because that's what I'm primarily busy with in my normal job for the last years).

    As for this discussion (which is about to derail just another thread)...
    I replied because you made it sound like VB6 was somehow "hampered at its tech-foundation" -
    which is as wrong as can be (.NET never was the "saviour", MS avoids it in nearly all of their tools).

    MS cancelled VB6 for "plain, political reasons", and that's all there is to it -
    (two competing RAD-tools was simply "one too many"... and the "Java-Clone" won).

    Olaf

  31. #31
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Schmidt View Post
    It's not really about "loving or hating COM".

    What you try real hard to deliberately "misunderstand and ignore" in all these threads is,
    that COM is the leaner, better performing "Object-tech", with deterministic teardown behaviour.
    Thing is, you and your camp are the only ones saying this. I'm not hearing about how great COM is anywhere else.

    Quote Originally Posted by Schmidt View Post
    MS cancelled VB6 for "plain, political reasons", and that's all there is to it -
    What authoritative sources do you have to confirm this? Why should I listen to someone in a shop all the way in Germany over veteran American tech journalists and insiders with decades of experience in the industry. They say otherwise. Is there a specific reason to believe you over them?
    Last edited by Niya; Nov 30th, 2021 at 08:53 PM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | 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

  32. #32
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    You know what, let's just agree to disagree. Some people including myself think COM is an over engineered, overly complicated mess and some people like you think it's the greatest thing ever invented. I don't see either of us changing our minds on this so lets just leave it at this. History chose our side over yours and that's that. There is nothing to be gain with us arguing about something we can't change.
    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

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

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Niya View Post
    Some people including myself think COM is an over engineered, overly complicated mess
    and some people like you think it's the greatest thing ever invented.
    I don't think COM is "the greatest thing ever"...

    But I know, that it is one of the best compromises to develop lean, fast native Class-Libraries
    (and when so choosen, under an "interface-first" engineering-paradigm via typelibs).

    And I'm not alone with that opinion...

    FWIW... more people than just the chief-tech-designers at MS agree with my point of view -
    whereas your opinion that "COM is an overcomplicated mess" can be disproven outright -
    by anybody who ever used VB6-IDE and Compiler to implement Classes or UserControls
    (where all the lower-level-complexities of COM are "hidden away" under the hood of the RAD-tool).

    Olaf

  34. #34
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,027

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Schmidt View Post
    But I know, that it is one of the best compromises to develop lean, fast native Class-Libraries
    (and when so choosen, under an "interface-first" engineering-paradigm via typelibs)
    Nothing is leaner than extern "C" __declspec(dllexport). Simple, straight to the point and very easy to use and implement.

    Quote Originally Posted by Schmidt View Post
    And I'm not alone with that opinion...

    FWIW... more people than just the chief-tech-designers at MS agree with my point of view -
    whereas your opinion that "COM is an overcomplicated mess" can be disproven outright -
    by anybody who ever used VB6-IDE and Compiler to implement Classes or UserControls
    (where all the lower-level-complexities of COM are "hidden away" under the hood of the RAD-tool).
    You guys are a minority. All the movers and shakers on the cutting edge are in Python, JavaScript and C#/.Net among other things. It's everywhere on the internet. COM isn't even in the conversation. Don't believe me? Go on YouTube and tell me how many videos there are dedicated to COM programming or VB6 and compare that to how many there are on C#, Python, JavaScript or any other modern framework. Go on Reddit, Quora or StackOverflow and see what they are talking about over there. Again, I refer to the article I linked in the last post. He said COM programmers get paid enormous amounts of money because no one is bothering themselves to learn it and they are hard to come by.

    Tell me this then, if COM is so great, then why isn't the world at large paying it any mind? Are you going to tell me that politics is the reason here too?

    EDIT:

    If you want to reference someone noteworthy, check out this guy on YouTube. He is an actual former Microsoft employee that actually worked on Windows in the NT days. He is as legit as they come. He covers a wide variety of topics. He is primarily a C++ guy but do you know what other language he likes? It is C#. I can't remember which video it was but I've heard him explicitly state that he loves programming in C# on Windows. Why do I bring this up? Let me bold this part so it's clear. An actual Microsoft programmer who has actually worked on Windows and had actual access to it's source and knows how Windows actually works is not writing COM programs. I consider him a far greater authority than you and if C# and .Net is more than good enough for him, an actual Microsoft engineer who knows Windows better than any of us ever could, then it's more than good enough for the rest of us.

    Come on man. No one important cares about COM.
    Last edited by Niya; Dec 1st, 2021 at 12:03 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

  35. #35
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,838

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    Quote Originally Posted by Niya View Post

    Come on man. No one important cares about COM.
    tell that to the Navy https://slate.com/technology/2018/06...indows-xp.html

    the $130,000 is a bargain
    The reason it takes $130,000 to hire someone with COM experience is because nobody bothered learning COM programming in the last eight years or so, so you have to find somebody really senior, usually they’re already in management, and convince them to take a job as a grunt programmer, dealing with (God help me) marshalling and monikers and apartment threading and aggregates and tearoffs and a million other things that, basically, only Don Box ever understood, and even Don Box can’t bear to look at them any more.
    not bad ($130,000) for a language that is dead for 20years
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

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

    Re: [RESOLVED] Type Mismatch problem regarding an If Else statement

    I think this discussion has now run it's course, and will just start repeating itself.

    @zhyr: Don't worry about asking too many questions. There is ALWAYS more to learn. One thing to keep in mind, though, is that the goal of asking a question on a forum like this is to get a good answer. You get the best answer by getting the most eyes on the question. So, if you have a follow up question to one that you have already asked, then it would be appropriate to ask it in the same thread. However, if you think that the question is new, then you are almost always better off asking it in a new thread. That's up to you, and nobody will be upset whichever way you choose to go.

    The other point, though, as you can see from this thread, is that there are some STRONG opinions about the VB6 language and features within it. You will also see the same people arguing the same positions. Whether you find that helpful or not is up to you. There is plenty to learn from both Schmidt and Niya, and repetition aids in learning.
    My usual boring signature: Nothing

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