Re: question(s) about declaring variables



"95isalive" <admin@xxxxxxxxxxxxx> wrote in message
news:eYKepayeFHA.3836@xxxxxxxxxxxxxxxxxxxxxxx
>
> Now that makes perfect sense.
> Also, mixing types in one Dim statement is something that never entered my
> mind.

fwiw, personal choice here.... I always use the "As String" format, never
the dollar sign and never declare more than one variable per line. When I
get sample code that has a bunch of variables declared on a single line or
use that ancient variable declaration syntax, if I plan on keeping that
sample, I break those lines up and add the correct variable types. One
declaration per line and "As Type" syntax improves readability far beyond
the few keystrokes you may save by taking shortcuts. Multiple declarations
on a single line makes it harder to spot a specific declaration when
browsing code.

Another thing I "clean up" in sample code that I want to keep is... single
line If/Then statements and I get rid of any multi-statement lines (like A =
5:B = 10). Those colons should've died with VB1 imo.... another thing that
drives me nuts is....

Dim A As String:A = "test"

That has the colon and the developer is trying to "fool" people into
thinking the variable is initialized while declaring it. Just another way to
introduce a bug and make things harder to read imo. Just plain nasty code
that'll change as soon as it hits my screen. Code like that doesn't even
save a keystroke but it sure makes it harder to read/maintain.

So... in the long run, it's all up to you... no changes in functionality....
but, expect your code to look completely different once it hits my PC and
I've decided to keep the "snip" <g>... one more thing I can live without
forever is people that align their "As Type" statements... like...

Dim A As String
Dim Bvar As Integer

....etc. That makes me do a search/replace of all occurances of 2 spaces in a
row. Too much work! <g> One space is all we need.

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..


.



Relevant Pages

  • Re: Can anyone tell me
    ... Function MyFuncLong, String, Double, Long, String ... Actually I quite like that second one, it's quite descriptive and clear and doesn't require any additional typing (over using byref params (assuming you use the byref keyword which is a very good idea)) :-) ... Another syntax possibility would be to not use Return as the way to return your variables; rather, use a Returns declarative statement immediately after the Function declaration (this would serve as the implied Dim statement for the variables being used to return values from the function (much like the "As " declaration on the end of VB functions. ...
    (microsoft.public.vb.general.discussion)
  • Re: public static or static public
    ... Petra Neumann wrote: ... > I just came across some sample code where a variable has been defined as: ... declaration is not significant. ... Ray ...
    (comp.lang.java)