[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using the !

Posted on 2000-05-12
39
Medium Priority
?
179 Views
Last Modified: 2010-05-02
In ado u can use the ! as a shortcut to a field in a recordset.
ie

strName=rs!name

instead of
strName=rs.fields("Name")

what i want to know is how is this done and is there a way to implement this in my own dll.

ie:a paramater is passed and an object is added to a collection with the key being the parameter,how do i let users of my dll access the item in the collection using !

i want

dim obj as new mydll.classname

obj.Go "Test" 'this adds to a collection
              'as well as other stuff

strSomething = obj!test


is this possible?
0
Comment
Question by:crazyman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 9
  • 6
  • +5
39 Comments
 
LVL 2

Expert Comment

by:Ginger_Ed
ID: 2804024
The ! is from SQL and that is why it works in ado, because your just sending a SQL statement.  I don't think it is possible to get it to work with your own objects though. sorry


Ed
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2804292
Ginger_Ed,

the ! has nothing to do with SQL! It is caused by the collection.

I hope someone will have the answer on how to implement this on our own collection!
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2804337
I agree with emoreau that ! has nothing to do with SQL

And this is REALLY easy!

Add a Item property or function to your class, with one Argument (index) and declare it as Default (Procedure Attributes)

Need more details
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Expert Comment

by:mcrider
ID: 2804350
A collection using the ! is based on the key.  Here is how you do it:

Dim XX As New Collection
Private Sub Command1_Click()
    XX.Add "Hello", "Key1"
    Debug.Print XX!Key1
End Sub


Cheers!®©
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2804359
mcrider, the question goes on how do DEVELOP this, not to USE it :-)
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2804361
Hey I just made a small test and it is actually working.

Create a class (named CEmployee) containing this code:
Option Explicit

'local variable(s) to hold property value(s)
Private mvarLastName As String 'local copy
Private mvarFirstName As String 'local copy

Public Property Let FirstName(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.FirstName = 5
    mvarFirstName = vData
End Property

Public Property Get FirstName() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.FirstName
    FirstName = mvarFirstName
End Property

Public Property Let LastName(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.LastName = 5
    mvarLastName = vData
End Property

Public Property Get LastName() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.LastName
    LastName = mvarLastName
End Property

Now create a form containing a command button and paste this code:
Option Explicit

Private Sub Command1_Click()
Dim colX As Collection
Dim objEmpl As CEmployee

    Set colX = New Collection
   
    Set objEmpl = New CEmployee
    objEmpl.FirstName = "Eric"
    objEmpl.LastName = "Moreau"
    colX.Add objEmpl, "ERIC"

    Debug.Print colX("ERIC").LastName
    Debug.Print colX!ERIC
End Sub

If you try it this way, you will have an error on the second Debug.Print line. The trick is to have a "Default property". I made the LastName property the default (from the Class builder utility or from Tools->Procedure attributes).
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2804430
Oh well, I misread the question...
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2804460
Happens to everybody... :-)
0
 
LVL 13

Author Comment

by:crazyman
ID: 2804475
Cool guys i didnt actually need this for anything it is just something ive always kinda wandered about.

How can u make something the default property via code not the class builder because i couldnt get that to work
0
 
LVL 13

Author Comment

by:crazyman
ID: 2804503
if u do it like collection!key then that is assuming that a record set is a collection, call me stupid but how does a collection take on extra methods and properties such as a record set?



ie .movefirst,movelast

this is a subject i would greatly like to know more about.

This is touching on all sorts of issues such as inheritance, are there any good learning sites for this?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2804511
Via code?????
Sorry, not possible.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2804545
You can use the Tools->Procedure attributes to set a property as the default one.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 2804555
If you put the cursor in the property you wish to make default, you then select tools | Procedure attributes, click the advanced button and for Procedure ID, select "Default."

MS couldn't have hidden this feature any better if they tried.
0
 
LVL 13

Author Comment

by:crazyman
ID: 2804575
cheers, i was looking for a check box or summin.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2804580
Who of you knows then how to define enumerator, so that you can have code
FOR EACH
on you class

Without looking into MSDN (be honest)
0
 
LVL 13

Author Comment

by:crazyman
ID: 2804608
So howcome if a record set is a collection it has more methods etc.. than any other collection?
How do you add these?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2804615
Use the class builder utility to create your collection. It could help you start fast!
0
 
LVL 13

Author Comment

by:crazyman
ID: 2804645
Forgive me but where do i find that?
I have never used it before
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2804649
It's an addin
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2804683
From the Add-ins menu, select "Add-in manager..."
0
 
LVL 13

Author Comment

by:crazyman
ID: 2804694
i havent got it.
where can i get it?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2804702
Which version of VB? How many lines do you see in the manager? If you see around 5 lines and you are using NT, see article Q190212.
0
 
LVL 13

Author Comment

by:crazyman
ID: 2804712
it isnt in my addin list
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2804724
Reinstall VB, choosing some Addition Tools...
0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2804782
>> Who of you knows then how to define enumerator, so that you can have code
>> FOR EACH
>> on you class
>> Without looking into MSDN (be honest)

I think you have to give your collection class a NewEnum property that returns the hidden _NewEnum property of the underlying collection. IIRC it has to be declared "As IUnknown", you have to make it hidden, and give it a rather bad documented procedure-id (which I would have to look up in the MSDN, but I think it was 4)

Am I correct? (I'll start looking in the MSDN now)
0
 
LVL 13

Author Comment

by:crazyman
ID: 2804789
when you find out can you post the code with an example please...
0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2804793
Almost dead on. The procedure-id has to be -4 (just checked), but for the rest I was correct. Guess I've done this to often %)
0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2804801
Sure, this is from "Creating Your Own Collection Class: The House of Bricks" which you can find in "Visual Basic Concepts":

----------------------------------------

Enabling For Each … Next

Along with robustness, you get For Each … Next back. Once again you can delegate all the work to the Collection object, by adding the following method:

' NewEnum must return the IUnknown interface of a
' collection's enumerator.
Public Function NewEnum() As IUnknown
   Set NewEnum = mcolEmployees.[_NewEnum]
End Function

The important thing you're delegating to the Collection object is its enumerator. An enumerator is a small object that knows how to iterate through the items in a collection. You can't write an enumerator object with Visual Basic, but because the Employees class is based on a Collection object, you can return the Collection object's enumerator — which naturally enough knows how to enumerate the items the Collection object is holding.

The square brackets around the Collection object's _NewEnum method are necessary because of the leading underscore in the method name. This leading underscore is a convention indicating that the method is hidden in the type library. You can't name your method _NewEnum, but you can hide it in the type library and give it the procedure ID that For Each … Next requires.

To hide the NewEnum method and give it the necessary procedure ID

On the Tools menu, click Procedure Attributes to open the Procedure Attributes dialog box. In Name box, select the NewEnum method.


Click Advanced to show the advanced features. Check Hide this member to make NewEnum hidden in the type library.


In the Procedure ID box, type –4 (minus four) to give NewEnum the procedure ID required by For Each … Next. Click OK.
Important   In order for your collection classes to work with For Each … Next, you must provide a hidden NewEnum method with the correct procedure ID.

0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2804902
If you want to locate the article in the MSDN (contains a lot of info on writing your own collection classes, recommended reading), do a title-only search on "creating your own collection classes". It will take you to the "House of Straw", "House of Sticks" and "House of Bricks" examples.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 2804946
Also in Books Online in Professional VB 5.0
0
 
LVL 13

Author Comment

by:crazyman
ID: 2805034
So the answer to my question is indeed that a record set is not a collection but a collection class.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2805084
a record is much more than a collection:
* navigation (MoveNext...)
* persistance (Update...)
* multicolumn (Fields collection)
* search (Find method)
0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2805099
Recordset and Collection are different things. The bang-character is a leftover from old times and office-like notations.

The fact that you can't duplicate it in VB says nothing. The recordset object (or indeed the whole ADO object-model) was not written in VB.
0
 
LVL 13

Author Comment

by:crazyman
ID: 2805154
i know it isnt a collection, what i mean is it contains a collection class(or appears to) that holds the data, the rest of the stuff if you like is wrappered around this,i was justusing this as en example of using ! with collections,nothing specific.
0
 
LVL 13

Author Comment

by:crazyman
ID: 2805174
who the hell do i give the points too?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 80 total points
ID: 2805198
Ask the community support to split points
0
 
LVL 13

Author Comment

by:crazyman
ID: 2809882
Adjusted points from 50 to 60
0
 
LVL 3

Expert Comment

by:darinw
ID: 2810163
Community Support has reduced points from 60 to 20
0
 
LVL 3

Expert Comment

by:darinw
ID: 2810164
Hello everyone,

I am reducing the points on this question to 20 to allow for a split.

You can now accept one of the comments in this thread as an answer. To award the other Experts, you must create 2 new questions in this topic area with a title of 'For ExpertName -- 10347980' using the appropriate Expert username.

Remember, the Accept Comment as Answer button is in the header of the comment.

For your convenience, you can use this link to create the new question:
http://www1.experts-exchange.com/bin/NewQForm?ta=31

darinw
Customer Service
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question