Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which is better ' rs("fieldName") ' or ' rs!fieldName ' ?

Status
Not open for further replies.

Brawn

Programmer
Jul 5, 2001
73
CA
Which is better:

Code:
rs("fieldName")

or

Code:
rs!fieldName

[red]
Pros?
Cons?
[/red]
Any comments at all may be a help. Brawn

"My mind is my Shrine,
and my body the Temple around it."

-The difference between genius and stupidity is that genius has its limits-
 
Just my personal preference but I always use
rs("fieldName") as I think it makes the code easier to read as it more clearly shows the field name especially if you are not using the VB editor (no color) to view the code.
Just my opinion. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
The band operator is now technically out dated as I have read in a few places, so, I think it's best to use rs("fieldname").
 
If you are going to be programming in the .NET world you would want to start using rs.fields("FieldName").

"Newer is not always better"

Regards
 
Rumour has it that rs!FieldName is quicker.

However, if you're going to upgrade to vb.net then you should consider using rs.fields("FieldName").value.

Most likely, it's personal preference. However, I would say to pick one style and stick with it as long as possible...
 
I prefer !, it takes less typing
And
If you use ! then you can do
with rs
!Field1 = val1
!Field2 = val2
!Field3 = val3
end with

 
According to everything I have read, if you use

Me![whatever]

It is translated into

Me("whatever") at runtime


Therefore, you should use Me("whatever") when possible. Programming isn't a profession of choice.
It's a profession of calling...
"Hey Programmer, your application broke again!" [spin]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
 
ALWAYS use rs("fieldName").

Why...

If you use rs!fieldname and one of your fields is called Date, then rs!Date, will give an error. Or If you put a space in your field name like rs!field name, then that will also give an error.

I too began by using ! as it is less typing, but soon found so many errors that half my code had ! and the other half had Filed.(""). It was a big mess.

Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
On the contrary, if it does get converted at run time then it makes no difference and so using the easiest thing to type is fine.
I have just done some quick tests, and ! appears to be marginally faster, but only a few percent, so it may not be.
Francis
 
Craig,
First, you should NEVER have a field named "Date". Of course, sometimes it's already done and your stuck with it. Same goes for field names with spaces.
But you can just use brackets:
rs![Date]
rs![Batch Number]

I always use rs!FieldName. I find it easier to read and I like being able to use the With statement. It saves typing and is visually clear. Especially when you have more descriptive names for your recordset object and 10 or 20 fields.
But if the bang won't be used in the future, it might be a good idea to start writing it a compatible way now.

 
I like the rs!fieldname syntax much better. It is easier to read and can use with "with". Having said that, like most things in BG's world, it doesn't matter what I like! If .net likes the more difficult syntax, so be it. I doesn't matter that I have tons of existing code using the "!" notation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top