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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

left$ vs left??

Status
Not open for further replies.

usp004

ISP
Jul 10, 2000
46
US
I was wondering if someone could help me... I was wondering what the difference is when adding the '$' to the end of a VB function like Right or Left or Mid.... Is there a difference when you add the '$' to the end of it?

Also... I am maintaining a vb app that has variables named with a '$' and/or '%' following the variable name.. for instance:

Dim hello%
Dim hello$

Could someone explain what this means?

Thanks
 
it really doesnt make much difference in VB anymore, but back in the days of Qbasic, $ would signify a variable was a string, and I belive % might mention some numerical type, VB still uses some characters at the end like 1& I belive is making it as a Long type (of course to force long or int, you would use Cint() and CLng() now)
 
Dim hello% is the same as Dim hello as String
 
The use of %&$#! (not cussing) is just a way of making the variable declaration explicit. When [tt]Option Explicit[/tt] is declared at the module level you would normally have to declare[tt]
Dim MyInteger as Integer
Dim MyString as String[/tt]

at the beginning of each sub. Using the declaration characters you can get away with [tt]MyString$ = "Hello"[/tt] and [tt]MyInteger% = 5000[/tt].
 

Left$() returns a string
Left() returns a variant

It is my understanding that Left$() is more efficient
 
Dim x% = dim x as integer
dim x$ = dim x as string
dim x& = dim x as long
dim x# = dim x as double
and so on...
Also, you can use the variables in code with these suffixes attached, if you'd like: ie.
for i% = 0 to 10
sum& = sum& + i%
next i%

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top