PC Review


Reply
Thread Tools Rate Thread

Declaring a variable

 
 
mcescher
Guest
Posts: n/a
 
      21st Aug 2008
Hi All,

I was looking at some code on Dev Ashish's site, and one function was
declared differently than I had seen before.

Function Lpad(MyValue$, MyPadCharacter$, MyPaddedLength%)
<<some vba code here>>
End Function

I understand the code, but I'm wondering about the declaration.

Is "MyValue$" the same as "MyValue AS String"?

Does the % then specify an integer?

Is there a list of other character declarations?

Does that work with a regular dim statement?
i.e. DIM strMyString$, intMyInteger%

Thanks so much,
Chris M.
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      21st Aug 2008
It's an ancient way of declaring variables, so ancient that it doesn't
include all data types.

There are 5 type-declaration symbols that I'm aware of:

! - Single
# - Double
$ - String
% - Integer
& - Long

(no Date, Boolean, Currency or Double.)

Dim strMyString$, intMyInteger%

is identical to

Dim strMyString As String, intMyInteger As Integer


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"mcescher" <(E-Mail Removed)> wrote in message
news:94788162-001b-48ae-be0e-(E-Mail Removed)...
> Hi All,
>
> I was looking at some code on Dev Ashish's site, and one function was
> declared differently than I had seen before.
>
> Function Lpad(MyValue$, MyPadCharacter$, MyPaddedLength%)
> <<some vba code here>>
> End Function
>
> I understand the code, but I'm wondering about the declaration.
>
> Is "MyValue$" the same as "MyValue AS String"?
>
> Does the % then specify an integer?
>
> Is there a list of other character declarations?
>
> Does that work with a regular dim statement?
> i.e. DIM strMyString$, intMyInteger%
>
> Thanks so much,
> Chris M.



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      21st Aug 2008
"mcescher" <(E-Mail Removed)> wrote in message
news:94788162-001b-48ae-be0e-(E-Mail Removed)...
> Hi All,
>
> I was looking at some code on Dev Ashish's site, and one function was
> declared differently than I had seen before.
>
> Function Lpad(MyValue$, MyPadCharacter$, MyPaddedLength%)
> <<some vba code here>>
> End Function
>
> I understand the code, but I'm wondering about the declaration.
>
> Is "MyValue$" the same as "MyValue AS String"?
>
> Does the % then specify an integer?


Yes. It's a "type declaration character".

> Is there a list of other character declarations?


Here's one:

http://support.microsoft.com/kb/191713

> Does that work with a regular dim statement?
> i.e. DIM strMyString$, intMyInteger%


Yes. But it's a discouraged practice.

One place where the type declaration characters come in handy -- when you're
programming for absolute maximum run-time efficiency -- is in the
specification of numeric literals, where you want to avoid any unnecessary
conversions. For example

Dim sngMyVar As Single
' ...
sngMyVar = 1!

Observe this in the Immediate Window:

?typename(1)
Integer
?typename(1.0)
Double
?typename(1!)
Single
?typename(1@)
Currency


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      21st Aug 2008
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:(E-Mail Removed)...
> It's an ancient way of declaring variables, so ancient that it doesn't
> include all data types.
>
> There are 5 type-declaration symbols that I'm aware of:
>
> ! - Single
> # - Double
> $ - String
> % - Integer
> & - Long
>
> (no Date, Boolean, Currency or Double.)



There's Currency: @


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
mcescher
Guest
Posts: n/a
 
      21st Aug 2008
On Aug 21, 2:29*pm, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:
> It's an ancient way of declaring variables, so ancient that it doesn't
> include all data types.
>
> There are 5 type-declaration symbols that I'm aware of:
>
> ! *- Single
> # - Double
> $ - String
> % - Integer
> & - Long
>
> (no Date, Boolean, Currency or Double.)
>
> Dim strMyString$, intMyInteger%
>
> is identical to
>
> Dim strMyString As String, intMyInteger As Integer
>
> --
> Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> (no e-mails, please!)
>
> "mcescher" <chris.meind...@gmail.com> wrote in message
>
> news:94788162-001b-48ae-be0e-(E-Mail Removed)...
>
>
>
> > Hi All,

>
> > I was looking at some code on Dev Ashish's site, and one function was
> > declared differently than I had seen before.

>
> > Function Lpad(MyValue$, MyPadCharacter$, MyPaddedLength%)
> > *<<some vba code here>>
> > End Function

>
> > I understand the code, but I'm wondering about the declaration.

>
> > Is "MyValue$" the same as "MyValue AS String"?

>
> > Does the % then specify an integer?

>
> > Is there a list of other character declarations?

>
> > Does that work with a regular dim statement?
> > *i.e. DIM strMyString$, intMyInteger%

>
> > Thanks so much,
> > Chris M.- Hide quoted text -

>
> - Show quoted text -


Thank you so much for your quick response. Should this be avoided?

Thanks again,
Chris M.
 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      21st Aug 2008
"Dirk Goldgar" <(E-Mail Removed)> wrote in message
news:11BC9AEA-BEE9-4F29-B8D0-(E-Mail Removed)...
> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
> news:(E-Mail Removed)...
>> It's an ancient way of declaring variables, so ancient that it doesn't
>> include all data types.
>>
>> There are 5 type-declaration symbols that I'm aware of:
>>
>> ! - Single
>> # - Double
>> $ - String
>> % - Integer
>> & - Long
>>
>> (no Date, Boolean, Currency or Double.)

>
>
> There's Currency: @


Hmm. Don't know how I missed it. Thanks, Dirk.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)



 
Reply With Quote
 
mcescher
Guest
Posts: n/a
 
      2nd Sep 2008
On Aug 21, 3:41*pm, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:
> "Dirk Goldgar" <d...@NOdataSPAMgnostics.com.invalid> wrote in message
>
> news:11BC9AEA-BEE9-4F29-B8D0-(E-Mail Removed)...
>
>
>
>
>
> > "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
> >news:(E-Mail Removed)...
> >> It's an ancient way of declaring variables, so ancient that it doesn't
> >> include all data types.

>
> >> There are 5 type-declaration symbols that I'm aware of:

>
> >> ! *- Single
> >> # - Double
> >> $ - String
> >> % - Integer
> >> & - Long

>
> >> (no Date, Boolean, Currency or Double.)

>
> > There's Currency: @

>
> Hmm. Don't know how I missed it. Thanks, Dirk.
>
> --
> Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> (no private e-mails, please)- Hide quoted text -
>
> - Show quoted text -


Thanks to all who replied.

Chris M.
 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      2nd Sep 2008
"Linq Adams via AccessMonster.com" <u28780@uwe> wrote in message
news:899b2322f43ab@uwe...
> Hey, who you calling "ancient?" I grew up writing code like that, back
> when
> "basic" wasn't "visual," hard drives were 20 mbs and Bill's operating
> systems
> actually came with an operator's manual!



Wow, you're a newbie, aren't you?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: declaring variable Göran Andersson Microsoft C# .NET 0 14th Jun 2008 12:04 AM
Declaring a Variable =?Utf-8?B?R2FyeSBEb2xsaXZlcg==?= Microsoft Access Form Coding 3 18th Sep 2007 02:26 PM
Declaring a tab name as a variable =?Utf-8?B?dGltbXVsbGE=?= Microsoft Excel Programming 2 25th Jan 2007 05:16 AM
re: Declaring A Variable Gordon Durgha Microsoft VB .NET 1 16th Mar 2004 07:12 AM
Declaring a variable? pgoodale Microsoft Excel Programming 2 2nd Jan 2004 03:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:35 PM.