locked
What is a ! operator RRS feed

  • Question

  • What does the ! mean in the following code snippet?

    Availability is a table in an access database
    Family and Model are column headers in the table
    cmbFamily and cmbModel are combo boxes.

                If Availability!family = cmbFamily.Text Then
                    cmbModel.Items.Add(Availability!model)
                End If
    The idea is to add the models of as aircraft family to a combobox(cmbModel) using a selection from another combobox(cmbFamily). 
    If you're not living on the edge, you're taking up too much room
    Wednesday, August 5, 2009 11:29 AM

Answers

  • In database code like this, ! means "field." So Availability!PPICode means to take the PPICode field from the Availability table.

    So "modelName = Availability!PPICode" takes the value in the PPICode field for the current record and puts it in the modelName variable.
    And "cmdModel.Items.Add(Availability!model)" adds the current record's model field value to the cmdModel ListBox (or whatever that control is).


    Rod Stephens, Visual Basic MVP

    Beginning Database Design Solutions
    http://www.amazon.com/exec/obidos/ASIN/0470385499/vbhelper/

    Visual Basic 2008 Programmer's Reference
    http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/

    • Marked as answer by Miller_a Wednesday, August 5, 2009 1:27 PM
    Wednesday, August 5, 2009 1:02 PM
  • Access used to use this type of notation for referencing fields in a table.  I don't know if it is still available in the most recent version of Access (I never really cared for it).  The ! was called a "bang".

    Assuming "rsAvailability" is a recordset for the "Availability" table it would be the same as writing:
    modelName = rsAvailibility("PPIcode")
    • Marked as answer by Miller_a Wednesday, August 5, 2009 1:27 PM
    Wednesday, August 5, 2009 1:10 PM

All replies

  • modelName = Availability!PPIcode
    The ! also pops up here in the code.

    Availability is a table same as before, PPIcode is a column in the table.

    What does the ! do, is it a way of bringing the PPI code and putting it in place of the modelName?


    If you're not living on the edge, you're taking up too much room
    Wednesday, August 5, 2009 12:19 PM
  • In database code like this, ! means "field." So Availability!PPICode means to take the PPICode field from the Availability table.

    So "modelName = Availability!PPICode" takes the value in the PPICode field for the current record and puts it in the modelName variable.
    And "cmdModel.Items.Add(Availability!model)" adds the current record's model field value to the cmdModel ListBox (or whatever that control is).


    Rod Stephens, Visual Basic MVP

    Beginning Database Design Solutions
    http://www.amazon.com/exec/obidos/ASIN/0470385499/vbhelper/

    Visual Basic 2008 Programmer's Reference
    http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/

    • Marked as answer by Miller_a Wednesday, August 5, 2009 1:27 PM
    Wednesday, August 5, 2009 1:02 PM
  • Access used to use this type of notation for referencing fields in a table.  I don't know if it is still available in the most recent version of Access (I never really cared for it).  The ! was called a "bang".

    Assuming "rsAvailability" is a recordset for the "Availability" table it would be the same as writing:
    modelName = rsAvailibility("PPIcode")
    • Marked as answer by Miller_a Wednesday, August 5, 2009 1:27 PM
    Wednesday, August 5, 2009 1:10 PM
  • This operator is one of those many ancient 'features' in VB that either should have been phased out or will be soon.
    You should use the alternative given by 'Miller_a' or risk the wrath of your fellow developers.

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Wednesday, August 5, 2009 2:34 PM
  • David,

    Which one is the 'ancient feature' that i should be avoiding?

    Using the Bangs ! or the rsAvailability("PPIcode")?

    Cordialement,
    A confused novice

    If you're not living on the edge, you're taking up too much room
    Wednesday, August 5, 2009 3:09 PM
  • I see both forms (and some others) quite often. I'd be surprised if Microsoft removed this. It's been around for too long and would be considered a "breaking change." They tend to avoid those and there's no real reason for them to remove it.

    I tend to avoid ! but I doubt it's going away any time soon.

    Rod

    Rod Stephens, Visual Basic MVP

    Beginning Database Design Solutions
    http://www.amazon.com/exec/obidos/ASIN/0470385499/vbhelper/

    Visual Basic 2008 Programmer's Reference
    http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/
    Wednesday, August 5, 2009 3:27 PM
  • Ok thanks for clearing that up.
    If you're not living on the edge, you're taking up too much room
    Wednesday, August 5, 2009 3:32 PM
  • VB has numerous syntax features that are considered by many to be long obsolete, although perhaps Rod S. is right about them not going away soon:

    - The 'bang' operator (doesn't provide any real advantage or clarity)
    - Old style 'Declare' statements
    - The 'Call' keyword
    - The 'REM' comment format
    - Old style type specifiers (e.g., Dim SomeString& instead of Dim SomeString As String).
    - The old-style function return mechanism (using the method name to assign values and no explicit 'Return').
    - 'On Error'

    All of these could have been phased out when VB.NET came out a few years ago, since there were numerous breaking changes anyway and all of the above could have been taken care of by the upgrade wizard anyway (except for 'On Error' - the upgrade of this to Try/Catch can be notoriously difficult).

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Wednesday, August 5, 2009 3:44 PM
  • I agree. On Error has some features that Try Catch doesn't have but the others should have been removed.

    (Also Goto! I've heard people argue that it has a place but I have yet to see a really convincing example.)

    Rod

    Rod Stephens, Visual Basic MVP

    Beginning Database Design Solutions
    http://www.amazon.com/exec/obidos/ASIN/0470385499/vbhelper/

    Visual Basic 2008 Programmer's Reference
    http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/
    Wednesday, August 5, 2009 4:38 PM
  • Give me a little while longer playing with .NET and i'll be in that conversation. (I've been working for 6weeks in my new job)


    If you're not living on the edge, you're taking up too much room
    Thursday, August 6, 2009 8:10 AM