Jump to content

Other way to declare Variables using Symbols

- - - - -

  • Please log in to reply
15 replies to this topic

#1
kresh7

kresh7

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 661 posts
Ok this will be a pretty small tutorial ok you know all how to declare variables in vb6 & vb .NET right
ex
Dim TheString as String
Dim Number as Integer


but did you know that you can declare a variable in a much shorter way using symbols like this


Dim TheString$ 'String
Dim TheInt% 'Integer
Dim TheSingle! 'Single
Dim TheDouble# 'Double
Dim TheLong& 'Long
Dim TheCurrency@ 'Currency

so i also commented each line so you know what symbol do what but let me write it down

% - Integer
! - Single
# - Double
& - Long
@ - Currency

Ok this is the tutorial i know realy short but i hope i can get in handle for anyone of you :D Peace out

Edited by kresh7, 18 September 2009 - 05:54 AM.

Posted Image

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I've never heard of these declaration shortcuts in VB. Very good to know! +rep

#3
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts
This was the old way of doing it (back in basic, basicA, gwbasic, qbasic, etc...)

VB tries to support legacy commands and conventions
(with minimal to no documentation) as long as it doesn't
go against it's current direction.

I'm a nostalgia buff, so good post +rep :thumbup:

#4
kresh7

kresh7

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 661 posts

debtboy said:

This was the old way of doing it (back in basic, basicA, gwbasic, qbasic, etc...)

VB tries to support legacy commands and conventions
(with minimal to no documentation) as long as it doesn't
go against it's current direction.

I'm a nostalgia buff, so good post +rep :thumbup:

Excualy i seen the first string $ declaration in a QBasic code then i was wounding what it was.After reading a little and trying in VB6 i found it out xD
Sometimes taking a deep look into source code can make you learn a lot new stuff thx for the replies to my post
Posted Image

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
That's a cool bit of info. +rep
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,248 posts
  • Programming Language:Java, C#, PHP
  • Learning:C, C++, C#, PHP, Transact-SQL, Assembly, Scheme
Very interesting. I prefer the "as" method even though it is more typing because it reads a lot easier. When I see

Dim sName$

I have to remember what $ means, where as

Dim sName As String

I don't have to remember anything. It reads easier.

#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
It is useful when declaring constants, though:

Const MyLongConst = &HFACE&
Const MyIntConst = &HFACE%

I'm not really a .NET person so I don't know if they fixed this, but this is the way it was done in 6 and VBA.
sudo rm -rf /

#8
MathX

MathX

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,001 posts
Cool! :)

Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!


#9
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
This is really cool, I never knew you could do it that way!

#10
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
I would advise against it, just because it makes your program annoying to read.
sudo rm -rf /

#11
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts

dargueta said:

I would advise against it, just because it makes your program annoying to read.
Agreed, I think one of "Basic's" goals was to be easier to read.

#12
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
If that were true then they would've used != instead of <> and allowed escape sequences in strings instead of forcing you to do this:

"Hello, World!" + vbCrLf + "New line."
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users