S
Smokey Grindle
Whats the easiest way to make a global function in VB 2005? The old way was
make a module, is that still the standard? thanks!
make a module, is that still the standard? thanks!
Whats the easiest way to make a global function in VB 2005? The old way was
make a module, is that still the standard? thanks!
Smokey Grindle said:Whats the easiest way to make a global function in VB 2005? The old way
was make a module, is that still the standard? thanks!
Smokey Grindle said:Whats the easiest way to make a global function in VB 2005? The old way
was make a module, is that still the standard?
Tom Leylan said:I will suggest it is "easy" but I'm doubtful that it is the "standard" or
(if it is at this point) that it will remain so.
http://msdn2.microsoft.com/en-us/library/7825002w(VS.80).aspx
I'd like to caution the OP against modules. As the number of public
functions increases you'll tend to want to organize them in some way,
classes do this for you in a natural way.
Perhaps as an exercise you could list (here) the names of 3 or 4 functions
which you might consider putting into a module. What are their names and
(if isn't obvious) what do they do?
Does anybody (not converting a VB6 app) uppercase strings by using UCase()
rather than String.ToUpper()? Again I ask is that so experienced
developers in every other DotNet language is confused?
I'm not advocating that everybody do what I say I'm simply offering an
opposing viewpoint. I would however tell anybody doing it in a project
that I controlled to please stop and when I've removed the reference to
the VisualBasic namespace, the code had better still compile.
when I've removed the reference to the VisualBasic namespace, the code had
better still compile.
Tom Leylan said:Hi Herfried: Let me begin by stating that I believe we disagree on
certain programming fundamentals and so opinions (yours and mine both)
should be weighed by the degree of "VB-ishness" we prefer. I don't think
I'm wrong in stating you like it and I've only actually liked VB since
VB.Net hit the scene.
The question for me usually comes down to "how does every other .Net
language manage to get along with out modules?" I'm staring at the VB
run-time library right now so perhaps you can explain (as you see it) the
reason that .ControlChars is a class and .Conversion is a module? I see
for instance a module contains ErrorToString(ByVal ErrorNumber As Integer)
As String
What is the upside to this not being a method of an Error object? What
does anybody gain by having a public function that you pass integers to?
It is a wrapper (isn't it?) for the Err.Number property. So why would
ErrorToString be used when the Err object contains the number, the
description and more?
Let's look at DateAdd( Interval, Number DateValue). One must actually
pass the date value to use along with the interval and such and it returns
a DateTime. If you have a DateTime variable anyway wouldn't .AddDays(),
.AddMonths(), .Add() and the other methods .IsLeapYear(), etc. be handy as
well? Is there a benefit to an extra set of arbitrarily named functions?
Let's see what would the code look like in C# dt.AddDays(7) what would it
look like in Python.Net, or Delphi.Net or any other .Net language? I
think dt.AddDays(7) will do it in every case. The benefit is clearly "it
doesn't matter what language you write in you can read the code." I can't
say for certain but I doubt there is an IncrementPeriod function in
Delphi.Net which takes some number of parameters but I am assured there is
DateTime.AddDays.
Does anybody (not converting a VB6 app) uppercase strings by using UCase()
rather than String.ToUpper()? Again I ask is that so experienced
developers in every other DotNet language is confused?
I'm not advocating that everybody do what I say I'm simply offering an
opposing viewpoint. I would however tell anybody doing it in a project
that I controlled to please stop and when I've removed the reference to
the VisualBasic namespace, the code had better still compile.
There are several reassons why someone might use the VB methods in favor
of the framework methods
1. the VB methods are sometimes shorter ( saves typing , and thus coding
speed )
2. The VB methods sometimes behave different as there .Net counterparts
3 The VB methods often have built in validation ( where you should write a
try catch block for the .Net counterpart )
Well about this i would say read my comments on this article and you see
my personal opinion
http://www.codeproject.com/useritems/novbruntimeref.asp?df=100&forumid=327076&exp=0
Fabio said:But you loose much more in readability and in OOP point of view.
And as said by Tom, you make your code difficult to understand to non-vb
"players".
Tom Leylan said:Hi Herfried: Let me begin by stating that I believe we disagree on
certain programming fundamentals and so opinions (yours and mine both)
should be weighed by the degree of "VB-ishness" we prefer. I don't think
I'm wrong in stating you like it and I've only actually liked VB since
VB.Net hit the scene.
The question for me usually comes down to "how does every other .Net
language manage to get along with out modules?" I'm staring at the VB
run-time library right now so perhaps you can explain (as you see it) the
reason that .ControlChars is a class and .Conversion is a module? I see
for instance a module contains ErrorToString(ByVal ErrorNumber As Integer)
As String
What is the upside to this not being a method of an Error object? What
does anybody gain by having a public function that you pass integers to?
It is a wrapper (isn't it?) for the Err.Number property. So why would
ErrorToString be used when the Err object contains the number, the
description and more?
Let's look at DateAdd( Interval, Number DateValue). One must actually
pass the date value to use along with the interval and such and it returns
a DateTime. If you have a DateTime variable anyway wouldn't .AddDays(),
.AddMonths(), .Add() and the other methods .IsLeapYear(), etc. be handy as
well? Is there a benefit to an extra set of arbitrarily named functions?
Let's see what would the code look like in C# dt.AddDays(7) what would it
look like in Python.Net, or Delphi.Net or any other .Net language? I
think dt.AddDays(7) will do it in every case. The benefit is clearly "it
doesn't matter what language you write in you can read the code." I can't
say for certain but I doubt there is an IncrementPeriod function in
Delphi.Net which takes some number of parameters but I am assured there is
DateTime.AddDays.
Does anybody (not converting a VB6 app) uppercase strings by using UCase()
rather than String.ToUpper()? Again I ask is that so experienced
developers in every other DotNet language is confused?
I'm not advocating that everybody do what I say I'm simply offering an
opposing viewpoint. I would however tell anybody doing it in a project
that I controlled to please stop and when I've removed the reference to
the VisualBasic namespace, the code had better still compile.
1. the VB methods are sometimes shorter ( saves typing , and thus coding
speed )
2. The VB methods sometimes behave different as there .Net counterparts
3 The VB methods often have built in validation ( where you should write a
try catch block for the .Net counterpart )
Well about this i would say read my comments on this article and you see
my personal opinion
In short VB is a RAD because of the shortcuts in the framework that the vb
namespace provides no need for RAD ? and want strict framework code ?
move to C# would then be my advice .
By the way i can code in both but i prefer VB as i started with VB on the
C64 on 13th years of age , but i am certainly not a C# basher VB and C#
are just 2 tools that might be prefered in different situations
OOP is a tool, not a goal.
In the latter case readability gets worse and the only way to make it
better is by importing the 'Math' class. In the case of the mathematical
functions it's absolutely irrelevant that the functions are members of a
certain class. Qualification by class name only blows up code and thus
reduces readability.
Does that really matter? There are so many things which are different in
various programming languages. You can also say that other programming
languages not providing the functionality VB provides make understinding
VB code hard to non-vb "players", which is certainly often the case in
practice. So that's only a POV.
\\\
If s IsNot Nothing AndAlso s.Length > 0 Then
...
End If
///
if I can simply write
\\\
If Len(s) > 0 Then
...
End If
///