By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

What does var$ mean?

P: n/a
I've been looking at code that handles string manipulation and I keep
seeing variable names, and function names, too, followed by a '$'.
I've also found a variable followed by a '%' symbol, but I've only
seen that once. Can someone please explain this for me? I haven't
been able to find anything about it.

thanks, --thelma

Nov 13 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Hi Thelma

These suffixes are type declaration characters.
The $ at the end of the name is a way of declaring the variable As String.
The % at the end of the name declares the variable As Integer.

Early versions of BASIC used special characters at the end of the variable name to declare the data type. For example, the ampersand makes this variable a Long:
Dim Quantity&

This arcane style is still supported, but is less readable. One case where type declaration characters may be useful is with literal values. It is more efficient to compare two values of the same type, so you may want to code:

If Len(strMyString) = 0& Then

Since Len() returns a Long and the zero alone would be an Integer, using the type declaration character means VBA does not have to convert the Integer into a Long to perform the comparison each time this line is executed.

VBA itself uses the type declaration character in some string functions. For example, there are two functions for choosing the beginning characters from a string: Left$() returns a String, and Left() returns a Variant. Choosing the function that returns the correct type will be slightly more efficient.
I will incur the wrath of this community and post in HTML so as to include a table showing the type declaration characters and other info about the field types:

Type
Size
Range
JET Type
Initial Value
Decl Char
Prefix

Boolean
1-bit (effectively)
True/False
Yes/No
False

bool
(f, bln)

Byte
8-bit, unsigned whole number
0 to 255
Number (Byte)
0

byte

Integer
16-bit, signed whole number
-32768 to 32767
Number (Integer)
0
%
int

Long
32-bit, signed whole number
-2,147,483,648 to 2,147,483,647
Number (Long Integer)
0
&
lng

Single
32-bit, signed floating-point
3.402823E38 to -1.401298E-45;
1.401298E-45 to 3.402823E38
Number (Single)
0
!
sng

Double
64-bit, signed floating-point number
-1.79769313486231E308 to
-4.94065645841247E-324; 4.94065645841247E-324 to 1.79769313486232E308
Number (Double)
0
#
dbl

Currency
64-bit, signed fixed-point
-922,337,203,685,477.5808 to 922,337,203,685,477.5807
Currency
0
@
cur

Decimal (subtype)
96-bit signed scalable number.
+/-79,228,162,514,264,337,593,543,950,335 to +/-0.0000000000000000000000000001
Number (Decimal)
0

dec

Date
64-bit signed floating-point
January 1 100 to
December 31 9999
Date/Time
Dec. 30 1899

date (dtm)

String
Depends on length
Variable-length: approx. 2 billion
Fixed-length: up to 64k characters
Text
""
$
str
stf

Object
Address (32-bit)
sound, Word document, text box, printer, device, etc.
OLE Object
Nothing

obj

Variant

Any of the above (except fixed-length string), Empty, Null, Error, Nothing, DataObject, User-defined type

Empty

var


--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Thelma Lubkin" <th****@alpha2.csd.uwm.edu> wrote in message news:d8**********@uwm.edu...
I've been looking at code that handles string manipulation and I keep
seeing variable names, and function names, too, followed by a '$'.
I've also found a variable followed by a '%' symbol, but I've only
seen that once. Can someone please explain this for me? I haven't
been able to find anything about it.

thanks, --thelma

Nov 13 '05 #2

P: n/a

"Thelma Lubkin" <th****@alpha2.csd.uwm.edu> wrote in message
news:d8**********@uwm.edu...
I've been looking at code that handles string manipulation and I keep
seeing variable names, and function names, too, followed by a '$'.
I've also found a variable followed by a '%' symbol, but I've only
seen that once. Can someone please explain this for me? I haven't
been able to find anything about it.

thanks, --thelma

(Try looking in the VBA Help File.)

Data Type Declaration Characters:

$ (String)

@ (Currency)

% (Integer)

! (Single)

# (Double)

& (Long)
Nov 13 '05 #3

P: n/a
Allen Browne <Al*********@SeeSig.Invalid> wrote:
: Hi Thelma

: These suffixes are type declaration characters.
: The $ at the end of the name is a way of declaring the variable As String.
: The % at the end of the name declares the variable As Integer.
<snip>

: If Len(strMyString) = 0& Then
You have given me a clear and comprehensive explanation of these
symbols, but I'm not yet completely unconfused. I find code like
the function below (from a visual basic tutorial by James Laferriere)
Since he has explicitly defined all of his variables, why does he
still refer to them w/ the end-declaration characters? ...and if
he insists that everything must be explicitly announced in every
way, then why doesn't he put the $ suffix after EveryOtherCap when he
assigns to it? ..or is it now a matter of style, and I'm just
quibbling?

thanks for all your help,
--thelma

Public Function EveryOtherCap(ByRef sInput As String) As String

Dim i As Integer, sCurrentChar As String
For i% = 1 To Len(sInput$)
sCurrentChar$ = Mid(sInput$, i%, 1) 'function
If i% Mod 2 = 0 Then
Mid(sInput$, i%, 1) = LCase(sCurrentChar$) 'statement
Else
Mid(sInput$, i%, 1) = UCase(sCurrentChar$)
End If
Next i%

EveryOtherCap = sInput$

End Function
: Allen Browne - Microsoft MVP. Perth, Western Australia.
: Tips for Access users - http://allenbrowne.com/tips.html
: Reply to group, rather than allenbrowne at mvps dot org.
Nov 13 '05 #4

P: n/a
GoJo4 <na**@nada.com> wrote:

: "Thelma Lubkin" <th****@alpha2.csd.uwm.edu> wrote in message
: news:d8**********@uwm.edu...
:> I've been looking at code that handles string manipulation and I keep
:> seeing variable names, and function names, too, followed by a '$'.
:> I've also found a variable followed by a '%' symbol, but I've only
:> seen that once. Can someone please explain this for me? I haven't
:> been able to find anything about it.
:>
:> thanks, --thelma
:>
: (Try looking in the VBA Help File.)

: Data Type Declaration Characters:

: $ (String)

: @ (Currency)

: % (Integer)

I did look, but since I didn't know that they were
'type declaration characters', I didn't find
this list--looking up '$' isn't very helpful.
So thanks for finding it for me.
--thelma
Nov 13 '05 #5

P: n/a
Thelma, I am equally confused by this author's style. It serves no useful
purpose at all to add the type declaration suffix in the code when it was
not declared with the suffix. Surely that does nothing but obfuscate the
code.

I suggest you ignore his style, and use the common approach of using the AS
in the Dim statement, and not using the type declaration suffixes.

The only time I use these suffixes personally is for literal values, e.g.:
If Me.InvoiceAmount < 0@ Then ...

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Thelma Lubkin" <th****@alpha2.csd.uwm.edu> wrote in message
news:d8**********@uwm.edu...
Allen Browne <Al*********@SeeSig.Invalid> wrote:
: Hi Thelma

: These suffixes are type declaration characters.
: The $ at the end of the name is a way of declaring the variable As
String.
: The % at the end of the name declares the variable As Integer.
<snip>

: If Len(strMyString) = 0& Then
You have given me a clear and comprehensive explanation of these
symbols, but I'm not yet completely unconfused. I find code like
the function below (from a visual basic tutorial by James Laferriere)
Since he has explicitly defined all of his variables, why does he
still refer to them w/ the end-declaration characters? ...and if
he insists that everything must be explicitly announced in every
way, then why doesn't he put the $ suffix after EveryOtherCap when he
assigns to it? ..or is it now a matter of style, and I'm just
quibbling?

thanks for all your help,
--thelma

Public Function EveryOtherCap(ByRef sInput As String) As String

Dim i As Integer, sCurrentChar As String
For i% = 1 To Len(sInput$)
sCurrentChar$ = Mid(sInput$, i%, 1) 'function
If i% Mod 2 = 0 Then
Mid(sInput$, i%, 1) = LCase(sCurrentChar$) 'statement
Else
Mid(sInput$, i%, 1) = UCase(sCurrentChar$)
End If
Next i%

EveryOtherCap = sInput$

End Function

Nov 13 '05 #6

P: n/a
When one asks a question how does one know if the answer is adequate?
One can try the solution; if it works reasonably quickly without error
it's likely to be adequate.

How does was one know if the answer is efficient and current? This is
much more difficult. Often someone who asks a question does not have
the experience or knowledge required to make such a judgement.

Here in CDMA it's quite common to see a questionner choose the least
satisfactory answer among several posted, thanking only its poster with
a comment like, "Worked like a charm!".

Answers here are not vetted. Regulars may or may not be inclined to
point out inadequacies in answers.

In the end, each of us is responsible for what we take from here, or
any public source. In my opinion, much more than half the code posted
here in CDMA is neither efficient nor current. CAVEAT EMPTOR.

This uncertainty is heightened because newsgroups and their posters
change over time. The beginner of 2001 may be the expert of 2005.

Recently I saw a post about ADO and schema. It was quite clever. It
came from a person who posted only a few months ago, "I don't do ADO".
I was impressed.

Nov 13 '05 #7

P: n/a
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in
news:42**********************@per-qv1-newsreader-01.iinet.net.au:
I will incur the wrath of this community and post in HTML so as to
include a table


I include tables in posts not infrequently and have never once felt
the need to post in HTML.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8

P: n/a
"ly******@yahoo.ca" <ly******@yahoo.ca> wrote in
news:11*********************@g47g2000cwa.googlegro ups.com:
In the end, each of us is responsible for what we take from here,
or any public source. In my opinion, much more than half the code
posted here in CDMA is neither efficient nor current. CAVEAT
EMPTOR.


If it's not efficient, that's a valid criticism.

But current?

That's complete lunacy.

If we went by currency, we would have retired you 10 years ago,
Lyle, since you're quite an old model.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9

P: n/a
Allen Browne wrote:

.... some html

This is great. It's nicely organized and I can read and understand it
easily. We have a gazillion bytes of binaries using up bandwidth every
day; why not some html here?
Are there really people using Access without high speed connections? If
there is one, should we go just text for him/her?

Yeah, yeah I know ... it's a usenet law, request, custom whatever. But
it could be changed.

--
--
Lyle

DAO: Data Access Objects. This is actually native to Microsoft Access
(more specifically, the Jet database that is at the heart of Access).
There are a lot of applications written in VB and Access that use this
technology. Too bad! This object model can be considered clunky, slow,
and just plain outdated (believe me, I'm being nice and not saying what
I really think). It's still the fastest way to access things if you're
using a Jet (Access) database but, if you're using this technology to
access SQL Server, I would suggest putting some serious effort into
migrating away from it as soon as possible. Microsoft was calling DAO a
"legacy" model more than a year before the end of the Office 97
lifecycle. They want people to stop using it, and I have to agree with them.

Robert Vieira
Professional SQL Server 2000 Programming p. 25
(Wrox)
Nov 13 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.