I assume this is also the case on particular VBA functions I have seen
with
a
suffixed type indicator?
ex:
var = Left$(....)
explicitly specifying that the Left() function should be returning a
String?
If this is the case... under what circumstances would VBA.Left() NOT
return
a string datatype? I see this fairly often (generally on Left, Right
or
Mid
functions, but my mind might be making this pattern up for me...)
I've always wondered about this, but trying to google What Does "$"
mean
in
VBA? doesn't work all that well.
--
Jack Leach
www.tristatemachine.com
"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
:
I recently took over another developers db... and am confused with a
couple
synthax usages and am hoping someone could explain what he was
doing.
he created loops similar to:
For i% = 0 To Forms.Count-1
...
Next i%
Why the %? Does it serve a purpose?
The "%" is a type-declaration character indicating that i is of the
Integer
data type. Various data types can be indicated by a type-declaration
characters tacked onto the end of a variable name (or a numeric
literal).
In a variable declaration, the type-declaration character can be used
in
place of "As <type>"; for example, these two statements are
equivalent:
Dim i As Integer
Dim i%
If you don't have Option Explicit set on in a module, then the first
use
of
a variable will define it, and so the data type may be specified by a
type-declaration character at that point:
For i% = 1 To 100
I strongly recommend that you *do* use Option Explicit, though, so
that
all
variables must be declared.
All of this goes back to the days when Basic was a very limited
language.
I
think most people would agree that it is better practice to declare
variable
types explicitly, as in
Dim I As Integer
The type-declaration characters do come in handy sometimes, though,
when
you
want to use a numeric literal and avoid any type conversion; e.g.,
Dim curAmount As Currency
curAmount = 100@ ' 100 dollars to start
Unfortunately, I can't remember off the top of my head what all the
type-delcaration characters are. I know these, but there may be
others:
% = Integer
& = Long
! = Single
# = Double
@ = Currency
$ = String
He also referred to certain variables with a $? For instance
Me.txtVal=DetailForm![txtTotalPrice$]
I am unable to locate a control named 'txtTotalPrice$' on the
specified
form, but can find one named 'txtTotalPrice'? Is there a reason for
the
$,
am I missing something?
Now that is odd. Is there perhaps a field in the form's recordsource
named
"txtTotalPrice$"? I wouldn't expect the reference you posted to work
unless
there's either a control on the form ort a field in the form's
recordsource
with that name.
It's generally considered bad practice to use special characters (like
"$",
spaces, or other punctuation) in field and object names.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)