I Was wondering..what is a better way to declare a string?
Use a "M$" (for example) Or Is it better to use the
Dim M As String?
Thanks :)
Printable View
I Was wondering..what is a better way to declare a string?
Use a "M$" (for example) Or Is it better to use the
Dim M As String?
Thanks :)
I like to Dim it better, but I heard that using Left$ will run much faster than Left.
Some clarifications I would like to point out :)
Never use
Dim M$
always use
Dim M as string
those symbols are just there for backward compatibility, it is much more readable and maintainable to explictly declare the variable type.
If a future programmer wants to maintain this code, they will have a tough time because they might have never had to write VB 3 code, so these symbols will be meaningless to them....
based on my own benchmarks, the LEFT$ runs less than .1% faster than LEFT
I don't thinks so, i'm using the !@#$%& more than ever because they take so little space and I think it's easier to read too, ie when you declare a function you will have the return type directly after the function name, and all arguments are easier to overview if they aren't spread out with as string and as integer and things.
Sorry kedaman but I agree with Clunietp in this one!
I agree that for declaring variables, you should always use the "As datatype" clause. The special symbols are still in the language for backwards compatibility.
However, for functions that return string values (such as Left, Mid, Trim, Format, etc.), I believe it is preferable to use the $ at the end. Without the $, these functions return a Variant data type rather than a string, so extra conversion steps are necessary.
I too agree with Clunietp. M$, MyString$, Myint@ etc. all looks kind of like jargon when you look at the whole picture.
Hmmm, Backward compability or not, it doesn't matter, I still have a very comprimized style and I'm sorry if other's have to use my code and don't like the special characters, if anyone could make a addin so you can change between using as vartype and special chars, I would be happy
I never said that I didn't like them. I just think that you're making it look like jargon when you don't have to.
For me, it's the other way round :(