Results 1 to 33 of 33

Thread: [RESOLVED] Break through the limitations of VB6-Type

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Resolved [RESOLVED] Break through the limitations of VB6-Type

    Is there a simple and elegant way to achieve the definition of the following structure (Type)?

    Module1.bas
    Code:
    Public Type ABC
        nMember = 123
        sMember = "Hello World"
        oMember = New Class1
        oCollection = New Collection
    End Type
    
    Public Sub Test_Struct()
        Dim tyABC As ABC
        
        Msgbox tyABC.sMember
    End Sub

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Break through the limitations of VB6-Type

    Use a Class instead of an UDT if you want to set default values automatically (use Class_Initialize).

  3. #3
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Break through the limitations of VB6-Type

    That wasn't really called for, Eduardo. Have some class.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Yes, similar operations can be achieved with classes. However, we can put hundreds of Types in a Module, but we cannot put hundreds of classes in one file.

    In addition, I have been looking for a way to make the collection properties of a Class have ReadOnly feature, for example:
    Code:
    Public Type ABC
        nMember = 123
        sMember = "Hello World"
        oMember = New Class1
        oCollection = New Collection
    
        Const ABC_TYPE = "VB7-Type"
        ReadOnly oList = Module2.GetItemCollection()
    
    End Type
    Last edited by SearchingDataOnly; Feb 15th, 2021 at 10:14 PM.

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Break through the limitations of VB6-Type

    Making read-only properties is very easy, just do not add the property let method.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Code:
    Public Property Get ItemList() as Collection
    
    End Property
    In my opinion, when the ItemList has the ReadOnly property, the ItemList will not allow the AddNewItem and RemoveItem operations to be performed, it is not even allowed to modify the properties of the item members in the collection.

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

    Re: Break through the limitations of VB6-Type

    u could save the definition.
    in my project I have almost 65k of data that I load and fill all the UDT

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by baka View Post
    u could save the definition.
    in my project I have almost 65k of data that I load and fill all the UDT
    Yes, I do this currently, but this method is too cumbersome.

  9. #9
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Break through the limitations of VB6-Type

    Could you describe your planned usecase in more detail?

    Olaf

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

    Re: Break through the limitations of VB6-Type

    what do u mean by cumbersome?

    open file for binary as #f
    get #f,, tyABC
    close #f

    done. quite easy.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by SearchingDataOnly View Post
    Code:
    Public Property Get ItemList() as Collection
    
    End Property
    In my opinion, when the ItemList has the ReadOnly property, the ItemList will not allow the AddNewItem and RemoveItem operations to be performed, it is not even allowed to modify the properties of the item members in the collection.
    A ReadOnly property is one where you can only get the value and not set it. If the property is type Collection then that means that you can get the existing Collection but you cannot assign a new Collection to the property. It says absolutely nothing about what you can and cannot do to the Collection once you have got it from the property. If you were to get the property value and assign it to a variable, then use that variable to add and remove items, how exactly would you be prevented from doing so? Rather than go by your opinion, you ought to test what actually happens and go by that.

    FYI, I use VB.NET and not VB6 but I find it hard to believe that VB6 is any different in this regard.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by Schmidt View Post
    Could you describe your planned usecase in more detail?

    Olaf
    I need to encapsulate several thousand constants of Scintilla, I borrowed the encapsulation method of ScintillaNET. The C# code is like this:

    Code:
    namespace ScintillaNET
    {
        /// <summary>
        /// A style definition in a <see cref="Scintilla" /> control.
        /// </summary>
        public class Style
        {
            #region Css
    
            /// <summary>
            /// Style constants for use with the <see cref="Lexer.Css" /> lexer.
            /// </summary>
            public static class Css
            {
                /// <summary>
                /// Default (whitespace) style index.
                /// </summary>
                public const int Default = NativeMethods.SCE_CSS_DEFAULT;
    
                /// <summary>
                /// Tag style index.
                /// </summary>
                public const int Tag = NativeMethods.SCE_CSS_TAG;
    
                /// <summary>
                /// Class style index.
                /// </summary>
                public const int Class = NativeMethods.SCE_CSS_CLASS;
    
                /// <summary>
                /// Pseudo class style index.
                /// </summary>
                public const int PseudoClass = NativeMethods.SCE_CSS_PSEUDOCLASS;
    
                /// <summary>
                /// Unknown pseudo class style index.
                /// </summary>
                public const int UnknownPseudoClass = NativeMethods.SCE_CSS_UNKNOWN_PSEUDOCLASS;
    
                /// <summary>
                /// Operator style index.
                /// </summary>
                public const int Operator = NativeMethods.SCE_CSS_OPERATOR;
    
                /// <summary>
                /// Identifier style index.
                /// </summary>
                public const int Identifier = NativeMethods.SCE_CSS_IDENTIFIER;
    
                /// <summary>
                /// Unknown identifier style index.
                /// </summary>
                public const int UnknownIdentifier = NativeMethods.SCE_CSS_UNKNOWN_IDENTIFIER;
    
                /// <summary>
                /// Value style index.
                /// </summary>
                public const int Value = NativeMethods.SCE_CSS_VALUE;
    
                /// <summary>
                /// Comment style index.
                /// </summary>
                public const int Comment = NativeMethods.SCE_CSS_COMMENT;
    
                /// <summary>
                /// ID style index.
                /// </summary>
                public const int Id = NativeMethods.SCE_CSS_ID;
    
                /// <summary>
                /// Important style index.
                /// </summary>
                public const int Important = NativeMethods.SCE_CSS_IMPORTANT;
    
                /// <summary>
                /// Directive style index.
                /// </summary>
                public const int Directive = NativeMethods.SCE_CSS_DIRECTIVE;
    
                /// <summary>
                /// Double-quoted string style index.
                /// </summary>
                public const int DoubleString = NativeMethods.SCE_CSS_DOUBLESTRING;
    
                /// <summary>
                /// Single-quoted string style index.
                /// </summary>
                public const int SingleString = NativeMethods.SCE_CSS_SINGLESTRING;
    
                /// <summary>
                /// Identifier style 2 index.
                /// </summary>
                public const int Identifier2 = NativeMethods.SCE_CSS_IDENTIFIER2;
    
                /// <summary>
                /// Attribute style index.
                /// </summary>
                public const int Attribute = NativeMethods.SCE_CSS_ATTRIBUTE;
    
                /// <summary>
                /// Identifier style 3 index.
                /// </summary>
                public const int Identifier3 = NativeMethods.SCE_CSS_IDENTIFIER3;
    
                /// <summary>
                /// Pseudo element style index.
                /// </summary>
                public const int PseudoElement = NativeMethods.SCE_CSS_PSEUDOELEMENT;
    
                /// <summary>
                /// Extended identifier style index.
                /// </summary>
                public const int ExtendedIdentifier = NativeMethods.SCE_CSS_EXTENDED_IDENTIFIER;
    
                /// <summary>
                /// Extended pseudo class style index.
                /// </summary>
                public const int ExtendedPseudoClass = NativeMethods.SCE_CSS_EXTENDED_PSEUDOCLASS;
    
                /// <summary>
                /// Extended pseudo element style index.
                /// </summary>
                public const int ExtendedPseudoElement = NativeMethods.SCE_CSS_EXTENDED_PSEUDOELEMENT;
    
                /// <summary>
                /// Media style index.
                /// </summary>
                public const int Media = NativeMethods.SCE_CSS_MEDIA;
    
                /// <summary>
                /// Variable style index.
                /// </summary>
                public const int Variable = NativeMethods.SCE_CSS_VARIABLE;
            }
    
            #endregion Css
        }
    }
    My VB6 code is like this:

    Module: Lexer.bas
    Code:
    Public Type Lexer_Cpp
        Default As Long
        Comment As Long
        CommentLine As Long
        CommentDoc As Long
        Number As Long
        Word As Long
        String_ As Long
        Character As Long
        Uuid As Long
        Preprocessor As Long
        Operator As Long
        Identifier As Long
        StringEol As Long
        Verbatim As Long
        Regex As Long
        CommentLineDoc As Long
        Word2 As Long
        CommentDocKeyword As Long
        CommentDocKeywordError As Long
        GlobalClass As Long
        StringRaw As Long
        TripleVerbatim As Long
        HashQuotedString As Long
        PreprocessorComment As Long
        PreprocessorCommentDoc As Long
        UserLiteral As Long
        TaskMarker As Long
        EscapeSequence As Long
    End Type
    Class: Style.cls
    Code:
    '=== #Region Cpp ===
    
    '--- <summary>
    '--- Style constants for use with the <see cref="Lexer.Cpp" /> lexer.
    '--- </summary>
    Friend Property Get Cpp() As Lexer_Cpp
        With Cpp
            '--- <summary>
            '--- Default (whitespace) style index.
            '--- </summary>
            .Default = NativeMethods.SCE_C_DEFAULT
        
            '--- <summary>
            '--- Comment style index.
            '--- </summary>
            .Comment = NativeMethods.SCE_C_COMMENT
        
            '--- <summary>
            '--- Line comment style index.
            '--- </summary>
            .CommentLine = NativeMethods.SCE_C_COMMENTLINE
        
            '--- <summary>
            '--- Documentation comment style index.
            '--- </summary>
            .CommentDoc = NativeMethods.SCE_C_COMMENTDOC
        
            '--- <summary>
            '--- Number style index.
            '--- </summary>
            .Number = NativeMethods.SCE_C_NUMBER
        
            '--- <summary>
            '--- Keyword style index.
            '--- </summary>
            .Word = NativeMethods.SCE_C_WORD
        
            '--- <summary>
            '--- Double-quoted string style index.
            '--- </summary>
            .String_ = NativeMethods.SCE_C_STRING
        
            '--- <summary>
            '--- Single-quoted string style index.
            '--- </summary>
            .Character = NativeMethods.SCE_C_CHARACTER
        
            '--- <summary>
            '--- UUID style index.
            '--- </summary>
            .Uuid = NativeMethods.SCE_C_UUID
        
            '--- <summary>
            '--- Preprocessor style index.
            '--- </summary>
            .Preprocessor = NativeMethods.SCE_C_PREPROCESSOR
        
            '--- <summary>
            '--- Operator style index.
            '--- </summary>
            .Operator = NativeMethods.SCE_C_OPERATOR
        
            '--- <summary>
            '--- Identifier style index.
            '--- </summary>
            .Identifier = NativeMethods.SCE_C_IDENTIFIER
        
            '--- <summary>
            '--- Unclosed string EOL style index.
            '--- </summary>
            .StringEol = NativeMethods.SCE_C_STRINGEOL
        
            '--- <summary>
            '--- Verbatim string style index.
            '--- </summary>
            .Verbatim = NativeMethods.SCE_C_VERBATIM
        
            '--- <summary>
            '--- Regular expression style index.
            '--- </summary>
            .Regex = NativeMethods.SCE_C_REGEX
        
            '--- <summary>
            '--- Documentation comment line style index.
            '--- </summary>
            .CommentLineDoc = NativeMethods.SCE_C_COMMENTLINEDOC
        
            '--- <summary>
            '--- Keyword style 2 index.
            '--- </summary>
            .Word2 = NativeMethods.SCE_C_WORD2
        
            '--- <summary>
            '--- Comment keyword style index.
            '--- </summary>
            .CommentDocKeyword = NativeMethods.SCE_C_COMMENTDOCKEYWORD
        
            '--- <summary>
            '--- Comment keyword error style index.
            '--- </summary>
            .CommentDocKeywordError = NativeMethods.SCE_C_COMMENTDOCKEYWORDERROR
        
            '--- <summary>
            '--- Global class style index.
            '--- </summary>
            .GlobalClass = NativeMethods.SCE_C_GLOBALCLASS
        
            '--- <summary>
            '--- Raw string style index.
            '--- </summary>
            .StringRaw = NativeMethods.SCE_C_STRINGRAW
        
            '--- <summary>
            '--- Triple-quoted string style index.
            '--- </summary>
            .TripleVerbatim = NativeMethods.SCE_C_TRIPLEVERBATIM
        
            '--- <summary>
            '--- Hash-quoted string style index.
            '--- </summary>
            .HashQuotedString = NativeMethods.SCE_C_HASHQUOTEDSTRING
        
            '--- <summary>
            '--- Preprocessor comment style index.
            '--- </summary>
            .PreprocessorComment = NativeMethods.SCE_C_PREPROCESSORCOMMENT
        
            '--- <summary>
            '--- Preprocessor documentation comment style index.
            '--- </summary>
            .PreprocessorCommentDoc = NativeMethods.SCE_C_PREPROCESSORCOMMENTDOC
        
            '--- <summary>
            '--- User-defined literal style index.
            '--- </summary>
            .UserLiteral = NativeMethods.SCE_C_USERLITERAL
        
            '--- <summary>
            '--- Task marker style index.
            '--- </summary>
            .TaskMarker = NativeMethods.SCE_C_TASKMARKER
        
            '--- <summary>
            '--- Escape sequence style index.
            '--- </summary>
            .EscapeSequence = NativeMethods.SCE_C_ESCAPESEQUENCE
        End With
    End Property
    '=== #EndRegion Cpp =============================================================================
    If we can directly define initial values or constants in VB6-Type, then things will be much simpler, and the structure of the code will be simpler and clearer. E.g:

    Code:
    Public Type Lexer_Cpp
        Default = 1	'       'Or Const Default = 1
        Comment = 2         ' Or Const Comment = 2
        CommentLine  = 3    ' Or Const Comment = 3
        ...
        ...
    End Type
    Note: There are thousands of constants stored in NativeMethods.bas.
    Last edited by SearchingDataOnly; Feb 16th, 2021 at 01:54 AM.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by SearchingDataOnly View Post
    I need to encapsulate several thousand constants of Scintilla, I refer to the encapsulation method of ScintillaNET. The C# code is like this:

    Code:
    namespace ScintillaNET
    {
        /// <summary>
        /// A style definition in a <see cref="Scintilla" /> control.
        /// </summary>
        public class Style
        {
            #region Css
    
            /// <summary>
            /// Style constants for use with the <see cref="Lexer.Css" /> lexer.
            /// </summary>
            public static class Css
            {
                /// <summary>
                /// Default (whitespace) style index.
                /// </summary>
                public const int Default = NativeMethods.SCE_CSS_DEFAULT;
    
                /// <summary>
                /// Tag style index.
                /// </summary>
                public const int Tag = NativeMethods.SCE_CSS_TAG;
    
                /// <summary>
                /// Class style index.
                /// </summary>
                public const int Class = NativeMethods.SCE_CSS_CLASS;
    
                /// <summary>
                /// Pseudo class style index.
                /// </summary>
                public const int PseudoClass = NativeMethods.SCE_CSS_PSEUDOCLASS;
    
                /// <summary>
                /// Unknown pseudo class style index.
                /// </summary>
                public const int UnknownPseudoClass = NativeMethods.SCE_CSS_UNKNOWN_PSEUDOCLASS;
    
                /// <summary>
                /// Operator style index.
                /// </summary>
                public const int Operator = NativeMethods.SCE_CSS_OPERATOR;
    
                /// <summary>
                /// Identifier style index.
                /// </summary>
                public const int Identifier = NativeMethods.SCE_CSS_IDENTIFIER;
    
                /// <summary>
                /// Unknown identifier style index.
                /// </summary>
                public const int UnknownIdentifier = NativeMethods.SCE_CSS_UNKNOWN_IDENTIFIER;
    
                /// <summary>
                /// Value style index.
                /// </summary>
                public const int Value = NativeMethods.SCE_CSS_VALUE;
    
                /// <summary>
                /// Comment style index.
                /// </summary>
                public const int Comment = NativeMethods.SCE_CSS_COMMENT;
    
                /// <summary>
                /// ID style index.
                /// </summary>
                public const int Id = NativeMethods.SCE_CSS_ID;
    
                /// <summary>
                /// Important style index.
                /// </summary>
                public const int Important = NativeMethods.SCE_CSS_IMPORTANT;
    
                /// <summary>
                /// Directive style index.
                /// </summary>
                public const int Directive = NativeMethods.SCE_CSS_DIRECTIVE;
    
                /// <summary>
                /// Double-quoted string style index.
                /// </summary>
                public const int DoubleString = NativeMethods.SCE_CSS_DOUBLESTRING;
    
                /// <summary>
                /// Single-quoted string style index.
                /// </summary>
                public const int SingleString = NativeMethods.SCE_CSS_SINGLESTRING;
    
                /// <summary>
                /// Identifier style 2 index.
                /// </summary>
                public const int Identifier2 = NativeMethods.SCE_CSS_IDENTIFIER2;
    
                /// <summary>
                /// Attribute style index.
                /// </summary>
                public const int Attribute = NativeMethods.SCE_CSS_ATTRIBUTE;
    
                /// <summary>
                /// Identifier style 3 index.
                /// </summary>
                public const int Identifier3 = NativeMethods.SCE_CSS_IDENTIFIER3;
    
                /// <summary>
                /// Pseudo element style index.
                /// </summary>
                public const int PseudoElement = NativeMethods.SCE_CSS_PSEUDOELEMENT;
    
                /// <summary>
                /// Extended identifier style index.
                /// </summary>
                public const int ExtendedIdentifier = NativeMethods.SCE_CSS_EXTENDED_IDENTIFIER;
    
                /// <summary>
                /// Extended pseudo class style index.
                /// </summary>
                public const int ExtendedPseudoClass = NativeMethods.SCE_CSS_EXTENDED_PSEUDOCLASS;
    
                /// <summary>
                /// Extended pseudo element style index.
                /// </summary>
                public const int ExtendedPseudoElement = NativeMethods.SCE_CSS_EXTENDED_PSEUDOELEMENT;
    
                /// <summary>
                /// Media style index.
                /// </summary>
                public const int Media = NativeMethods.SCE_CSS_MEDIA;
    
                /// <summary>
                /// Variable style index.
                /// </summary>
                public const int Variable = NativeMethods.SCE_CSS_VARIABLE;
            }
    
            #endregion Css
        }
    }
    My VB6 code is like this:

    Module: Lexer.bas
    Code:
    Public Type Lexer_Cpp
        Default As Long
        Comment As Long
        CommentLine As Long
        CommentDoc As Long
        Number As Long
        Word As Long
        String_ As Long
        Character As Long
        Uuid As Long
        Preprocessor As Long
        Operator As Long
        Identifier As Long
        StringEol As Long
        Verbatim As Long
        Regex As Long
        CommentLineDoc As Long
        Word2 As Long
        CommentDocKeyword As Long
        CommentDocKeywordError As Long
        GlobalClass As Long
        StringRaw As Long
        TripleVerbatim As Long
        HashQuotedString As Long
        PreprocessorComment As Long
        PreprocessorCommentDoc As Long
        UserLiteral As Long
        TaskMarker As Long
        EscapeSequence As Long
    End Type
    Class: Style.cls
    Code:
    '=== #Region Cpp ===
    
    '--- <summary>
    '--- Style constants for use with the <see cref="Lexer.Cpp" /> lexer.
    '--- </summary>
    Friend Property Get Cpp() As Lexer_Cpp
        With Cpp
            '--- <summary>
            '--- Default (whitespace) style index.
            '--- </summary>
            .Default = NativeMethods.SCE_C_DEFAULT
        
            '--- <summary>
            '--- Comment style index.
            '--- </summary>
            .Comment = NativeMethods.SCE_C_COMMENT
        
            '--- <summary>
            '--- Line comment style index.
            '--- </summary>
            .CommentLine = NativeMethods.SCE_C_COMMENTLINE
        
            '--- <summary>
            '--- Documentation comment style index.
            '--- </summary>
            .CommentDoc = NativeMethods.SCE_C_COMMENTDOC
        
            '--- <summary>
            '--- Number style index.
            '--- </summary>
            .Number = NativeMethods.SCE_C_NUMBER
        
            '--- <summary>
            '--- Keyword style index.
            '--- </summary>
            .Word = NativeMethods.SCE_C_WORD
        
            '--- <summary>
            '--- Double-quoted string style index.
            '--- </summary>
            .String_ = NativeMethods.SCE_C_STRING
        
            '--- <summary>
            '--- Single-quoted string style index.
            '--- </summary>
            .Character = NativeMethods.SCE_C_CHARACTER
        
            '--- <summary>
            '--- UUID style index.
            '--- </summary>
            .Uuid = NativeMethods.SCE_C_UUID
        
            '--- <summary>
            '--- Preprocessor style index.
            '--- </summary>
            .Preprocessor = NativeMethods.SCE_C_PREPROCESSOR
        
            '--- <summary>
            '--- Operator style index.
            '--- </summary>
            .Operator = NativeMethods.SCE_C_OPERATOR
        
            '--- <summary>
            '--- Identifier style index.
            '--- </summary>
            .Identifier = NativeMethods.SCE_C_IDENTIFIER
        
            '--- <summary>
            '--- Unclosed string EOL style index.
            '--- </summary>
            .StringEol = NativeMethods.SCE_C_STRINGEOL
        
            '--- <summary>
            '--- Verbatim string style index.
            '--- </summary>
            .Verbatim = NativeMethods.SCE_C_VERBATIM
        
            '--- <summary>
            '--- Regular expression style index.
            '--- </summary>
            .Regex = NativeMethods.SCE_C_REGEX
        
            '--- <summary>
            '--- Documentation comment line style index.
            '--- </summary>
            .CommentLineDoc = NativeMethods.SCE_C_COMMENTLINEDOC
        
            '--- <summary>
            '--- Keyword style 2 index.
            '--- </summary>
            .Word2 = NativeMethods.SCE_C_WORD2
        
            '--- <summary>
            '--- Comment keyword style index.
            '--- </summary>
            .CommentDocKeyword = NativeMethods.SCE_C_COMMENTDOCKEYWORD
        
            '--- <summary>
            '--- Comment keyword error style index.
            '--- </summary>
            .CommentDocKeywordError = NativeMethods.SCE_C_COMMENTDOCKEYWORDERROR
        
            '--- <summary>
            '--- Global class style index.
            '--- </summary>
            .GlobalClass = NativeMethods.SCE_C_GLOBALCLASS
        
            '--- <summary>
            '--- Raw string style index.
            '--- </summary>
            .StringRaw = NativeMethods.SCE_C_STRINGRAW
        
            '--- <summary>
            '--- Triple-quoted string style index.
            '--- </summary>
            .TripleVerbatim = NativeMethods.SCE_C_TRIPLEVERBATIM
        
            '--- <summary>
            '--- Hash-quoted string style index.
            '--- </summary>
            .HashQuotedString = NativeMethods.SCE_C_HASHQUOTEDSTRING
        
            '--- <summary>
            '--- Preprocessor comment style index.
            '--- </summary>
            .PreprocessorComment = NativeMethods.SCE_C_PREPROCESSORCOMMENT
        
            '--- <summary>
            '--- Preprocessor documentation comment style index.
            '--- </summary>
            .PreprocessorCommentDoc = NativeMethods.SCE_C_PREPROCESSORCOMMENTDOC
        
            '--- <summary>
            '--- User-defined literal style index.
            '--- </summary>
            .UserLiteral = NativeMethods.SCE_C_USERLITERAL
        
            '--- <summary>
            '--- Task marker style index.
            '--- </summary>
            .TaskMarker = NativeMethods.SCE_C_TASKMARKER
        
            '--- <summary>
            '--- Escape sequence style index.
            '--- </summary>
            .EscapeSequence = NativeMethods.SCE_C_ESCAPESEQUENCE
        End With
    End Property
    '=== #EndRegion Cpp =============================================================================
    If we can directly define initial values or constants in VB6-Type, then things will be much simpler, and the structure of the code will be simpler and clearer. E.g:

    Code:
    Public Type Lexer_Cpp
        Default = 1	'       'Or Const Default = 1
        Comment = 2         ' Or Const Comment = 2
        CommentLine  = 3    ' Or Const Comment = 3
        ...
        ...
    End Type
    I'd be tempted to use an Enum for that. I'd have been tempted to in C# too.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by jmcilhinney View Post
    I'd be tempted to use an Enum for that. I'd have been tempted to in C# too.
    There are thousands of constants. If they can be encapsulated, the structure of the code will be simpler and clearer.

    Note: There are thousands of constants stored in NativeMethods.bas.
    Last edited by SearchingDataOnly; Feb 16th, 2021 at 12:36 AM.

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by SearchingDataOnly View Post
    There are thousands of constants. If they can be encapsulated, the structure of the code will be simpler and clearer.
    Are you implying that an Enum would not achieve that?

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by jmcilhinney View Post
    Are you implying that an Enum would not achieve that?
    This is similar to whether you want to put thousands of files in the same directory, or you want to put them in different directories by category. In addition, there are many files belonging to different categories but with the same name.
    Last edited by SearchingDataOnly; Feb 16th, 2021 at 12:59 AM.

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

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by jmcilhinney View Post
    Are you implying that an Enum would not achieve that?
    Are you implying that in vb6 you can declare an Enum consisting of strings?
    I was under the impression, that an Enum-Variable is basically a Long
    Code:
    Public Enum MyEnum
      Member1
      Member2
      Member3
    End Enum
    
    Dim varEnum As MyEnum <-- This is basically a Long!
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

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

  18. #18
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by Zvoni View Post
    Are you implying that in vb6 you can declare an Enum consisting of strings?
    No, but at least 90% of all these const-defs are integer-values -
    and therefore can be represented by an Enum-Def perfectly (including initializers).

    For example, when the OP posted this concrete UDT-Def here:
    Code:
    Public Type Lexer_Cpp
        Default As Long
        Comment As Long
        CommentLine As Long
        CommentDoc As Long
        Number As Long
        Word As Long
        String_ As Long
        Character As Long
        Uuid As Long
        Preprocessor As Long
        Operator As Long
        Identifier As Long
        StringEol As Long
        Verbatim As Long
        Regex As Long
        CommentLineDoc As Long
        Word2 As Long
        CommentDocKeyword As Long
        CommentDocKeywordError As Long
        GlobalClass As Long
        StringRaw As Long
        TripleVerbatim As Long
        HashQuotedString As Long
        PreprocessorComment As Long
        PreprocessorCommentDoc As Long
        UserLiteral As Long
        TaskMarker As Long
        EscapeSequence As Long
    End Type
    Then the above could be perfectly represented in an Enum (with Initializer-Values) -
    since the UDT-Members are all Longs.

    Olaf

  19. #19
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by SearchingDataOnly View Post
    I need to encapsulate several thousand constants of Scintilla
    I would create TLB for that case. Nested categories. Easy to use.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by Dragokas View Post
    I would create TLB for that case. Nested categories. Easy to use.
    Thank you for your suggestion, Dragokas.

    My development environment often switches between multiple computers. If I use TLB, when the TLB changes, I need to re-create the TLB and re-register the TLB for VB6-IDE on multiple computers. This is very cumbersome.
    In addition, if each project requires 1-2 TLBs, when multiple projects need to be developed and maintained, the management and upgrade of TLBs are troublesome.

    So I always avoid using TLB.

    If RC6 can provide some ways to simplify the generation and deployment of TLB (register for VB6-IDE), then I might consider trying TLB.

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

    Re: Break through the limitations of VB6-Type

    u can put the TLB in the same folder as the project. I work on multiple computers and it will always register correctly on its own. I have 5 TLB.
    once compiled, u dont need the TLB anymore, u know that right?

  22. #22
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Break through the limitations of VB6-Type

    Can you explain what is the problem?
    Is it that you don't like to have too many constants declared on a single unique file? Or that they are not well organized into groups? (Are all used or just some are used and others unused?))
    Or is it that you would like to have them declared just in the place where they are used? (in how many places are each constant used, one or more than one place?)
    Or is it that you don't like to have in Intellisense too many contants that are barely needed globaly?

    I think if you explain the problem may be someone can help with a solution.

  23. #23

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by baka View Post
    u can put the TLB in the same folder as the project. I work on multiple computers and it will always register correctly on its own. I have 5 TLB.
    once compiled, u dont need the TLB anymore, u know that right?
    I know that once the compilation is complete, the binary file does not need a TLB. TLB is mainly used in VB6-IDE.

    When the new TLB is not compatible with the old TLB, VB6-IDE sometimes cannot automatically register the new TLB. At this time, I need to clear the old TLB and then re-register the new TLB. When I test those code snippets with TLB in vbForums, I often encounter this situation. So I don't like TLB very much, just like you don't like registering third-party DLLs.

  24. #24

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by Eduardo- View Post
    Can you explain what is the problem?
    Is it that you don't like to have too many constants declared on a single unique file? Or that they are not well organized into groups? (Are all used or just some are used and others unused?))
    Or is it that you would like to have them declared just in the place where they are used? (in how many places are each constant used, one or more than one place?)
    Or is it that you don't like to have in Intellisense too many contants that are barely needed globaly?

    I think if you explain the problem may be someone can help with a solution.
    My purpose is that I hope to see VB6 has more possibilities in software design patterns.

  25. #25
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by SearchingDataOnly View Post
    My purpose is that I hope to see VB6 has more possibilities in software design patterns.
    I repeat: explain a clear and specific objective of what you are asking

    To say "My purpose is that I hope to see VB6 has more possibilities in software design patterns" is like saying nothing. (and it makes no sense anyway, because VB6 was made in 1998 and now is what it is, cannot change).

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

    Re: Break through the limitations of VB6-Type

    u just place the new TLB in the same folder as the project.
    so, if u have

    myTLB version 1.0 in your folder, the IDE will use that when u open the project
    if replace myTLB with version 1.1 in your folder, the IDE will use that, since the old one is replaced.
    the IDE will look into your project folder for that particular TLB.
    so, u only register one time, and point the TLB to your own project folder.
    in another computer, the IDE will register the TLB on the project folder automatically.
    thats how I have been doing for years.

    if by chance the IDE tells u its wrong, u just redo it, look into the project folder and point on that "new" version 1.1 TLB.

    when working on multiple computers u need to zip the project and upload right? so u only need to update one time, and its mandatory at least one time anyway.
    its a couple of minutes work.

    anyway. I would use a load/save method anyway.
    I would even have a small project, that the only purpose is to assign values on the UDT and save it on hd.
    the main project, will just have a "load" and fill all the values automatically using binary load.
    Last edited by baka; Feb 16th, 2021 at 11:43 AM.

  27. #27

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by Eduardo- View Post
    I repeat: explain a clear and specific objective of what you are asking

    To say "My purpose is that I hope to see VB6 has more possibilities in software design patterns" is like saying nothing. (and it makes no sense anyway, because VB6 was made in 1998 and now is what it is, cannot change).
    I've posted the code on Post#12. That is just a code snippet of Lexer_Cpp, there are actually more than 100 code snippets similar to Lexer_Cpp, such as Lexer_Html, Lexer_Javascript, Lexer_Fortran, Lexer_Lisp, Lexer_VisualBasic, etc. In other words, I need to classify thousands of constants, and then call these classified constants like the member variables of Type or Class.

    Due to too many constants, I'm now writing a CodeGenerator to generate dozens of remaining code fragments similar to Lexer_Cpp.
    Last edited by SearchingDataOnly; Feb 16th, 2021 at 11:46 AM.

  28. #28
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by SearchingDataOnly View Post
    I've posted the code on Post#12. That is just a code snippet of Lexer_Cpp, there are actually more than 100 code snippets similar to Lexer_Cpp, such as Lexer_Html, Lexer_Javascript, Lexer_Fortran, Lexer_Lisp, Lexer_VisualBasic, etc. In other words, I need to classify thousands of constants, and then call these classified constants like the member variables of Type or Class.
    Still, what is the problem? The project is big, and...?

  29. #29

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    I still need to think about how to make my question clearer. I don't know if Olaf understands my question.
    Last edited by SearchingDataOnly; Feb 16th, 2021 at 11:52 AM.

  30. #30
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: Break through the limitations of VB6-Type

    SearchingDataOnly, as about TLB, it's up to you surely.

    I'll just share my experience related to cases when for some reason TLB is failed to (re)-register automatically on the developer environment machine.

    There are 2 options:
    1) In .vbp remove the version number. Example:
    Code:
    Reference=*\G{F9015E81-CAAC-45C0-94E8-42B7DA5D7558}#4.7#0#oleexp.tlb#OLEEXP
    replace with:
    Code:
    Reference=*\G{F9015E81-CAAC-45C0-94E8-42B7DA5D7558}##0#oleexp.tlb#OLEEXP
    And run project elevated.
    Otherwise, VB project could use the old registration.
    I have a batch file doing it automatically when I push sources on Github.
    However, I think there will be no problem if you recompile TLB without changing the version.

    2) RegTLib, allowing to register as admin or as a limited user.
    I also have that one in my batch file, doing the registration for me and open my project as elevated without UAC.

    Good luck with making a code generator !
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  31. #31

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by baka View Post
    u just place the new TLB in the same folder as the project.
    so, if u have

    myTLB version 1.0 in your folder, the IDE will use that when u open the project
    if replace myTLB with version 1.1 in your folder, the IDE will use that, since the old one is replaced.
    the IDE will look into your project folder for that particular TLB.
    so, u only register one time, and point the TLB to your own project folder.
    in another computer, the IDE will register the TLB on the project folder automatically.
    thats how I have been doing for years.

    if by chance the IDE tells u its wrong, u just redo it, look into the project folder and point on that "new" version 1.1 TLB.

    when working on multiple computers u need to zip the project and upload right? so u only need to update one time, and its mandatory at least one time anyway.
    its a couple of minutes work.

    anyway. I would use a load/save method anyway.
    I would even have a small project, that the only purpose is to assign values on the UDT and save it on hd.
    the main project, will just have a "load" and fill all the values automatically using binary load.
    Thank you baka. I don't use TLB in my own projects, but I often encounter TLB when testing other people's projects. TLB is a very effective way to expand VB6-Types, maybe I'll consider using TLB in my projects in the future. I like to explore any possible solution and choose the one that suits me best.

    Quote Originally Posted by Eduardo- View Post
    Still, what is the problem? The project is big, and...?
    Thank you Eduardo. Regarding the constants problem, I've solved it through the code generator. The problem in post#1 may need to wait until the new VB6 compiler is released before it may be resolved.

  32. #32

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by Dragokas View Post
    SearchingDataOnly, as about TLB, it's up to you surely.

    I'll just share my experience related to cases when for some reason TLB is failed to (re)-register automatically on the developer environment machine.

    There are 2 options:
    1) In .vbp remove the version number. Example:
    Code:
    Reference=*\G{F9015E81-CAAC-45C0-94E8-42B7DA5D7558}#4.7#0#oleexp.tlb#OLEEXP
    replace with:
    Code:
    Reference=*\G{F9015E81-CAAC-45C0-94E8-42B7DA5D7558}##0#oleexp.tlb#OLEEXP
    And run project elevated.
    Otherwise, VB project could use the old registration.
    I have a batch file doing it automatically when I push sources on Github.
    However, I think there will be no problem if you recompile TLB without changing the version.

    2) RegTLib, allowing to register as admin or as a limited user.
    I also have that one in my batch file, doing the registration for me and open my project as elevated without UAC.

    Good luck with making a code generator !
    Very useful experience, I'ill definitely use it in the future. Thank you very much, Dragokas.
    Last edited by SearchingDataOnly; Feb 17th, 2021 at 02:14 AM.

  33. #33
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Break through the limitations of VB6-Type

    Quote Originally Posted by SearchingDataOnly View Post
    Thank you Eduardo. Regarding the constants problem, I've solved it through the code generator.
    After you have it working, I would consider to modify the original design and convert the code that currently handles 100+ different files types into a single general purpose file type handler with the data for the different formats (file types) stored somewhere in the program as just data and not specific constants/procedures/methods/etc.

    (I'm saying this without being familiar with the code more than what you posted here, so maybe I'm ignoring too much and what I'm saying is wrong)

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