Results 1 to 9 of 9

Thread: [RESOLVED] Two Usages I'm Not Familiar With - Need Explanation

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    897

    Resolved [RESOLVED] Two Usages I'm Not Familiar With - Need Explanation

    1)
    Code:
    Wiadev.Properties!Name.Value
    What is the "!" point doing?
    If one uses a "." after properties "Name" is not an option

    2)
    Code:
    With ![Horizontal Resolution]
    The [ ] around variable make it an Escape Name
    ' If the name used is a reserved word OR Not properly formatted (e.g. has spaces)
    ' This overrides any deficiencies.

    FWIW:
    There is a string Const defined as HorizontalResolution {note no space}
    So is it finding that string constant and then converting it to an Single ?
    However, when I create a dummy variable (tried both Single, and variant) and
    assign it to the dummy variable (sngTest = ![Horizontal Resolution], to find its value
    I error.

    However doing this
    sngTest = Wiadev.Items(1).Properties![Horizontal Resolution]
    gives me the value contained in the property horizontal resolution.


    Explanation Please on usage and how I can obtain the value in [Horizontal Resolution]?
    Last edited by vb6forever; Jun 21st, 2024 at 11:11 AM.

  2. #2
    Fanatic Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    586

    Re: Two Usages I'm Not Familiar With - Need Explanation

    ChatGPT response

    1. Using ! in Wiadev.Properties!Name.Value

    The ! operator is used to access members of collections or objects, especially when dealing with dynamic collections like properties or fields in a recordset. Here, Wiadev.Properties!Name.Value is accessing a property called Name within the Properties collection of the Wiadev object.

    If you used a dot after Properties (Wiadev.Properties.Name), it would not work because Name is not a direct member of the Properties object but rather a member of the collection held by Properties.

    2. Using [] to Escape Names
    The [] brackets are used to escape names that are either reserved words or contain characters not typically allowed in identifiers (like spaces).

    Explanation of the Code and Usage
    With ![Horizontal Resolution]

    The [Horizontal Resolution] syntax is used to access a property that has spaces in its name.

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,343

    Re: Two Usages I'm Not Familiar With - Need Explanation

    > What is the "!" point doing?

    This is the "bang" operator. It's roughly translated from !Key to .Item("Key") i.e. Wiadev.Properties!Name.Value is quivalent to Wiadev.Properties.Item("Name").Value.

    Or if I have to be precise obj!Key calls default property with string parameter equal to "Key" i.e. default property might not be Item for certain collections (it can be arbitrarily named).

    Extending the above explanation the ![Horizontal Resolution] syntax is just .Item("Horizontal Resolution") i.e. the key as a string contains spaces or other symbols which are not valid for identifiers in the language i.e. can use obj.Item("100km") and obj![100km] but cannot use obj!100km directly as naked 100km is not a valid identifier in VB6 (starts with a digit).

    cheers,
    </wqw>

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    897

    Re: Two Usages I'm Not Familiar With - Need Explanation

    AAraya and wqweto

    THANKS both for taking your time and explanation.

    While ChatGPT alludes to it (IMHO), wqweto explanation made it clear (at least to me).
    Should of made the connection between DAO "!" and what's going on here. Oh Well!
    My original post took care of [].

    ================================================
    FollowOn
    ================================================
    This Wia has me really confused.
    This is what I have that works (Dilettante's code)
    Code:
        Set WiaRootItem = Wiadev.Items(1)      'Root\Top item of the device.
        With WiaRootItem.Properties
             With ![Current Intent]
    If one types "Wiadev.Items(1). '{.} note period they can get .Properties.Item
    However the Set "WiaRootItem.Properties. '{.} Item does Not comes up
    But obviously it is there as ![Current Intent] works
    Last edited by vb6forever; Jun 21st, 2024 at 12:36 PM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    897

    Re: Two Usages I'm Not Familiar With - Need Explanation

    I don't recall VB not making this linkage with "Set objects" and/or nested "With", but that may be the issue.

  6. #6
    Hyperactive Member
    Join Date
    Jan 2018
    Posts
    286

    Re: Two Usages I'm Not Familiar With - Need Explanation

    As you saw, it doesn't have to be named Item:

    Quote Originally Posted by wqweto View Post
    Or if I have to be precise obj!Key calls default property with string parameter equal to "Key" i.e. default property might not be Item for certain collections (it can be arbitrarily named).

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    897

    Re: Two Usages I'm Not Familiar With - Need Explanation

    ahenry - Thanks for responding.

    I picked up on wqweto's (and which you emphasize) quote.
    I.e. A string used with a Key, Item, or anything else can be "arbitrarily named".
    To my knowledge this has always been the case.
    I.e. obj! uses the Default for whatever.

    The above is DAO comparable to:

    !fldMem versus .Fields(fldMemo)

    =====================
    1)
    =======================
    From what I can tell, in using this format, the object browser DOES NOT recognize it.
    So its a PITA, as you don't know where your at in the tree.

    So how one navigates between {dot} usage versus {bang} usage EASILY is the question?

    =======================
    2)
    =======================
    While I get the usage of ![Horizontal Resolution] and the fact [Horizontal Resolution] is
    in effect, a string without blanks, where my confusion is coming in, is that the [Horizontal Resolution]string represents a Const ((WIA_IPS_XRES)), BUT no Const with that name is defined
    anywhere in the program (i can find).

    So when an value assignment is made to:
    ![Horizontal Resolution].Value = 300

    which is really:
    ![6147].Value = 300

    VB5/6 (to my knowledge) does not bring in a header file like C/C++.
    If it has that ability (unknown to me), I could not find one in the VBP file or elsewhere.

    How does the system (compiler) know that this string is 6147 (WIA_IPS_XRES), since [Horizontal Resolution] is NOT defined anywhere as Const [Horizontal Resolution] = 6147?
    Last edited by vb6forever; Jun 21st, 2024 at 08:20 PM.

  8. #8
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,736

    Post Re: Two Usages I'm Not Familiar With - Need Explanation

    Quote Originally Posted by vb6forever View Post
    However doing this
    sngTest = Wiadev.Items(1).Properties![Horizontal Resolution]
    gives me the value contained in the property horizontal resolution.

    Explanation Please on usage and how I can obtain the value in [Horizontal Resolution]?
    [Horizontal Resolution] is not a constant, it's the Name of a Property. You can enumerate all properties to see what they are:

    Code:
    Dim Prop As Property
    For Each Prop In Wiadev.Items(1).Properties
        Debug.Print Prop.Name, Prop.Value
    Next Prop
    It should print "Horizontal Resolution" among the list of other properties. This "!" bang operator is just a syntax shortcut. If it adds to your confusion then don't use it.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    897

    Re: Two Usages I'm Not Familiar With - Need Explanation

    VanGoghGaming: Thanks for responding.

    This "!" bang operator is just a syntax shortcut. If it adds to your confusion then don't use it.
    I agree. But doing some testing this AM, I've narrowed down where my confusion is coming from.

    1) Initially I thought the PropertyId is the item index. But that appears NOT to be the case.
    Code:
    This Fails where the PropertyID for [Horizontal Resolution] = 6147
    
    Dim a As Long
    Wiadev.Items(1).Properties.Item(6147).Value = 150
    a = Wiadev.Items(1).Properties.Item(6147).Value
    Debug.Print Wiadev.Items(1).Properties.Item(6147).Value
    Using Item and the Name for the Item as the Index (ignoring Bang usage, works)
    I get Bang is taking the place of Item
    Code:
    This Works!
    
    Dim s As String
    s = "Horizontal Resolution"
    
    Wiadev.Items(1).Properties.Item([s]).Value = 150
    a = Wiadev.Items(1).Properties.Item(s).Value
    Debug.Print Wiadev.Items(1).Properties.Item(s).Value
    ----------------
    Question
    ----------
    So what is the PropertyID used for (if anything), and how does one use it with Wia?

    HOW DUMB can I be!!
    The Item Index needs to be a string.
    So the PropertyID works if the Item Index is made a string.

    Code:
    'This Works
    
    Dim s As String
    s = "6147"
       
    Wiadev.Items(1).Properties.Item(s).Value = 150
    Debug.Print Wiadev.Items(1).Properties.Item(s).Value
    a = Wiadev.Items(1).Properties.Item(s).Value
    Last edited by vb6forever; Jun 22nd, 2024 at 11:01 AM.

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