CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Bang

  1. #1
    Join Date
    Aug 2000
    Posts
    265

    Bang

    I've seen the ! (bang) in several snippets of code. What does it do? What are the rules for using it?


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Bang

    You can use bang to access the field in the recordset

    rs!Field

    the same you can get as

    rs.("Field")

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Aug 2000
    Location
    KY
    Posts
    766

    Re: Bang

    please note that the ! in recordset is not a good practise. It is a holdover from dao and ADO is slower to resolve this. In fact, for performance reasons you should always use a with to access multiple fields for example

    with rs
    .fields(fld1)
    .fields(fld2)
    end with






    an undocumented feature of ADO is to use

    with rs
    .collect(fld1)
    .collect(fld2)
    end with



    I know, I know. It does not show up in intellisense, try it, it works 30% faster


    TANSTAAFL - There ain't no such thing as a free lunch

  4. #4
    Join Date
    Dec 1999
    Location
    Texas
    Posts
    96

    Re: Bang

    Actually, the bang is not exclusive to the Recordset object(s). The bang serves as a collection lookup. That is why rs!customerId will not cause an error, but will instead search the Fields collection for a field name customerId (of course this is only an example and your code will error if you use the example with a recordset that does not have this field). Try it yourself:

    Dim colTest as new Collection
    '
    colTest.Add 15, "apples"
    colTest.Add 30, "oranges"
    colTest.Add 50, "banannas"
    '
    MsgBox colTest!apples & ", " & colTest!oranges & ", " & colTest!bannanas



    As we all know, the Collection object does not have the properties apples, oranges or banannas it is simply looking for a matching item in the collection.

    This proves quite deceiving as it appears that the object has a property named apples and it does not.

    Hope this is helpful,
    Rippin


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

Featured