|
| Author |
Message |
Henning
Joined: 04 Oct 2007 Posts: 247
|
Posted: Thu Feb 21, 2008 3:59 am Post subject: Bool Function default |
|
|
Hi grp,
Is it safe to assume the default for the following is always False?
Function IsShoe(nr As Integer) As Boolean
/Henning
Archived from group: microsoft>public>vb>general>discussion |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Wed Feb 20, 2008 7:15 pm Post subject: Re: Bool Function default |
|
|
Henning wrote:
> Is it safe to assume the default for the following is always False?
> Function IsShoe(nr As Integer) As Boolean
Given the langauge is dead, yeah. If MSFT were still updating it, no safe bets
there.
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Jeff Johnson
Joined: 04 Oct 2007 Posts: 1327
|
Posted: Wed Feb 20, 2008 10:23 pm Post subject: Re: Bool Function default |
|
|
"Henning" wrote in message $0$93305$57c3e1d3@news3.bahnhof.se...
> Is it safe to assume the default for the following is always False?
> Function IsShoe(nr As Integer) As Boolean
I would say it's safe to say this:
Dim flag As Boolean
will always result in flag having a value of False if it's not otherwise
set. I personally don't think of FUNCTIONS ever having "default values." |
|
| Back to top |
|
 |
Saga
Joined: 04 Oct 2007 Posts: 809
|
Posted: Wed Feb 20, 2008 9:39 pm Post subject: Re: Bool Function default |
|
|
I say that it is not safe, given the info that you have provided.
For example:
Function IsShoe(nr As Integer) As Boolean
if nr = 3 then
IsShoe = true
end if
End Function
Above the function result is set toTrue only if nr is 3 which means that
is nr 3 then IsShoe is not initialized and is therefore assumed to be False, but...
Function IsShoe(nr As Integer) As Boolean
IsShoe = (nr = 3)
End Function
The above always sets IsShoe accordingly, but here again...
Function IsShoe(nr As Integer) As Boolean
IsShoe = true
if nr = 3 then
IsShoe = false
end if
End Function
The above, by default sets IsShoe to True and only sets it to False if nr is 3.
(No relation to the first two)
Unless you know how the function behaves, I would say it is not safe to assume any
kind of default value.
Regards,
Saga
--
"Henning" wrote in message $0$93305$57c3e1d3@news3.bahnhof.se...
> Hi grp,
>
> Is it safe to assume the default for the following is always False?
> Function IsShoe(nr As Integer) As Boolean
>
> /Henning
> |
|
| Back to top |
|
 |
Henning
Joined: 04 Oct 2007 Posts: 247
|
Posted: Thu Feb 21, 2008 4:54 am Post subject: Re: Bool Function default |
|
|
Hmmm, you all seem to share the same opinion.
I'm adding some features to en old app, when I stopped on this one when I
saw there is no Set to False. It has worked ok for several years now, but I
couldn't resist to ask. I usually nowadays always set a value to Functions.
The complete function is as:
Function IsShoe(nr As Integer) As Boolean
If nr > 1999 And nr < 3000 Then
IsShoe = True
ElseIf nr > 4499 And nr < 4600 Then
IsShoe = True
End If
End Function
Sooo, I will add IsShoe = False as the first statement.
Thanks all
/Henning
"Saga" skrev i meddelandet @TK2MSFTNGP02.phx.gbl...
>I say that it is not safe, given the info that you have provided.
>
> For example:
>
> Function IsShoe(nr As Integer) As Boolean
>
> if nr = 3 then
> IsShoe = true
> end if
>
> End Function
>
> Above the function result is set toTrue only if nr is 3 which means that
> is nr 3 then IsShoe is not initialized and is therefore assumed to be
> False, but...
>
> Function IsShoe(nr As Integer) As Boolean
>
>
> IsShoe = (nr = 3)
>
> End Function
>
> The above always sets IsShoe accordingly, but here again...
>
>
> Function IsShoe(nr As Integer) As Boolean
>
>
> IsShoe = true
>
> if nr = 3 then
> IsShoe = false
> end if
>
> End Function
>
> The above, by default sets IsShoe to True and only sets it to False if nr
> is 3.
> (No relation to the first two)
>
> Unless you know how the function behaves, I would say it is not safe to
> assume any
> kind of default value.
>
> Regards,
> Saga
> --
>
>
> "Henning" wrote in message
> $0$93305$57c3e1d3@news3.bahnhof.se...
>> Hi grp,
>>
>> Is it safe to assume the default for the following is always False?
>> Function IsShoe(nr As Integer) As Boolean
>>
>> /Henning
>>
>
> |
|
| Back to top |
|
 |
Henning
Joined: 04 Oct 2007 Posts: 247
|
Posted: Thu Feb 21, 2008 5:02 am Post subject: Re: Bool Function default |
|
|
Sorry about this all, if I weren't so lazy I could have searched MSDN first.
Now I did.
If no value is assigned to name, the procedure returns a default value: a
numeric function returns 0, a string function returns a zero-length string
(""), and a Variant function returnsEmpty. A function that returns an object
reference returns Nothing if no object reference is assigned to name (using
Set) within the Function.
The following example shows how to assign a return value to a function named
BinarySearch. In this case, False is assigned to the name to indicate that
some value was not found.
Function BinarySearch(. . .) As Boolean
.. . .
' Value not found. Return a value of False.
If lower > upper Then
BinarySearch = False
Exit Function
End If
.. . .
End Function
/Henning"Saga" skrev i meddelandet @TK2MSFTNGP02.phx.gbl...
>I say that it is not safe, given the info that you have provided.
>
> For example:
>
> Function IsShoe(nr As Integer) As Boolean
>
> if nr = 3 then
> IsShoe = true
> end if
>
> End Function
>
> Above the function result is set toTrue only if nr is 3 which means that
> is nr 3 then IsShoe is not initialized and is therefore assumed to be
> False, but...
>
> Function IsShoe(nr As Integer) As Boolean
>
>
> IsShoe = (nr = 3)
>
> End Function
>
> The above always sets IsShoe accordingly, but here again...
>
>
> Function IsShoe(nr As Integer) As Boolean
>
>
> IsShoe = true
>
> if nr = 3 then
> IsShoe = false
> end if
>
> End Function
>
> The above, by default sets IsShoe to True and only sets it to False if nr
> is 3.
> (No relation to the first two)
>
> Unless you know how the function behaves, I would say it is not safe to
> assume any
> kind of default value.
>
> Regards,
> Saga
> --
>
>
> "Henning" wrote in message
> $0$93305$57c3e1d3@news3.bahnhof.se...
>> Hi grp,
>>
>> Is it safe to assume the default for the following is always False?
>> Function IsShoe(nr As Integer) As Boolean
>>
>> /Henning
>>
>
> |
|
| Back to top |
|
 |
Bob Butler
Joined: 04 Oct 2007 Posts: 1081
|
Posted: Wed Feb 20, 2008 7:59 pm Post subject: Re: Bool Function default |
|
|
"Henning" wrote in message $0$93305$57c3e1d3@news3.bahnhof.se...
> Hmmm, you all seem to share the same opinion.
>
> I'm adding some features to en old app, when I stopped on this one when I
> saw there is no Set to False. It has worked ok for several years now, but
> I couldn't resist to ask. I usually nowadays always set a value to
> Functions.
> The complete function is as:
> Function IsShoe(nr As Integer) As Boolean
> If nr > 1999 And nr < 3000 Then
> IsShoe = True
> ElseIf nr > 4499 And nr < 4600 Then
> IsShoe = True
> End If
> End Function
>
> Sooo, I will add IsShoe = False as the first statement.
It doesn't hurt but doesn't do anything either. The default is False.
>> Function IsShoe(nr As Integer) As Boolean
>> IsShoe = true
>> if nr = 3 then
>> IsShoe = false
>> end if
>> End Function
>>
>> The above, by default sets IsShoe to True and only sets it to False if nr
>> is 3.
The default value for the function is still False; the code explicitly
overrides the default to return True unless the test passes but no matter
how you look at it the default has not changed. |
|
| Back to top |
|
 |
Ken Halter
Joined: 04 Oct 2007 Posts: 4150
|
Posted: Wed Feb 20, 2008 9:18 pm Post subject: Re: Bool Function default |
|
|
"Henning" wrote in message $0$93305$57c3e1d3@news3.bahnhof.se...
> Sorry about this all, if I weren't so lazy I could have searched MSDN
> first. Now I did.
>
> If no value is assigned to name, the procedure returns a default value: a
> numeric function returns 0, a string function returns a zero-length string
> (""), and a Variant function returnsEmpty. A function that returns an
> object reference returns Nothing if no object reference is assigned to
> name (using Set) within the Function.
> The following example shows how to assign a return value to a function
> named BinarySearch. In this case, False is assigned to the name to
> indicate that some value was not found.
>
> Function BinarySearch(. . .) As Boolean
> . . .
> ' Value not found. Return a value of False.
> If lower > upper Then
> BinarySearch = False
> Exit Function
> End If
> . . .
> End Function
ummm... not quite That function will *always* return False because
there's nothing to tell it otherwise.
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm |
|
| Back to top |
|
 |
BeastFish
Joined: 04 Oct 2007 Posts: 231
|
Posted: Thu Feb 21, 2008 12:48 am Post subject: Re: Bool Function default |
|
|
"Ken Halter" wrote in message@TK2MSFTNGP05.phx.gbl...
> "Henning" wrote in message
> $0$93305$57c3e1d3@news3.bahnhof.se...
> > Sorry about this all, if I weren't so lazy I could have searched MSDN
> > first. Now I did.
> >
> > If no value is assigned to name, the procedure returns a default value:
a
> > numeric function returns 0, a string function returns a zero-length
string
> > (""), and a Variant function returnsEmpty. A function that returns an
> > object reference returns Nothing if no object reference is assigned to
> > name (using Set) within the Function.
> > The following example shows how to assign a return value to a function
> > named BinarySearch. In this case, False is assigned to the name to
> > indicate that some value was not found.
> >
> > Function BinarySearch(. . .) As Boolean
> > . . .
> > ' Value not found. Return a value of False.
> > If lower > upper Then
> > BinarySearch = False
> > Exit Function
> > End If
> > . . .
> > End Function
>
> ummm... not quite That function will *always* return False because
> there's nothing to tell it otherwise.
That's an MSDN example? |
|
| Back to top |
|
 |
PeterD
Joined: 04 Oct 2007 Posts: 245
|
Posted: Thu Feb 21, 2008 1:55 pm Post subject: Re: Bool Function default |
|
|
On Wed, 20 Feb 2008 23:54:36 +0100, "Henning"
wrote:
>Hmmm, you all seem to share the same opinion.
>
>I'm adding some features to en old app, when I stopped on this one when I
>saw there is no Set to False. It has worked ok for several years now, but I
>couldn't resist to ask. I usually nowadays always set a value to Functions.
>The complete function is as:
>Function IsShoe(nr As Integer) As Boolean
> If nr > 1999 And nr < 3000 Then
> IsShoe = True
> ElseIf nr > 4499 And nr < 4600 Then
> IsShoe = True
> End If
>End Function
>
>Sooo, I will add IsShoe = False as the first statement.
>
>Thanks all
>/Henning
All in one line:
Function IsShoe(nr As Integer) As Boolean
IsShoe = (nr > 1999 And nr < 3000) or _
(nr > 4499 And nr < 4600)
End Function |
|
| Back to top |
|
 |
PeterD
Joined: 04 Oct 2007 Posts: 245
|
Posted: Thu Feb 21, 2008 1:56 pm Post subject: Re: Bool Function default |
|
|
On Wed, 20 Feb 2008 16:18:32 -0800, "Ken Halter"
wrote:
>"Henning" wrote in message
>$0$93305$57c3e1d3@news3.bahnhof.se...
>>
>> Function BinarySearch(. . .) As Boolean
>> . . .
>> ' Value not found. Return a value of False.
>> If lower > upper Then
>> BinarySearch = False
>> Exit Function
>> End If
>> . . .
>> End Function
>
>ummm... not quite That function will *always* return False because
>there's nothing to tell it otherwise.
Me thinks you missed the 'snipped' bits of code there! |
|
| Back to top |
|
 |
Jeff Johnson
Joined: 04 Oct 2007 Posts: 1327
|
Posted: Thu Feb 21, 2008 2:23 pm Post subject: Re: Bool Function default |
|
|
"Henning" wrote in message $0$93305$57c3e1d3@news3.bahnhof.se...
> Sooo, I will add IsShoe = False as the first statement.
Ohhhhhhhhhhhhhhhh. So what you meant was "Is it safe to assume the return
value of a function declared As Boolean is always False IF THE CODE NEVER
SETS THE NAME OF THE FUNCTION TO A VALUE?" In that case, the answer is Yes,
it's safe to assume that. |
|
| Back to top |
|
 |
Saga
Joined: 04 Oct 2007 Posts: 809
|
Posted: Thu Feb 21, 2008 1:36 pm Post subject: Re: Bool Function default |
|
|
As some one else said, I think you missed some code there because that
function as is given, is equivalent to:
Function BinarySearch(. . .) As Boolean
End Function
(I am sure that that example is missing substantial code
Saga
--
"Henning" wrote in message $0$93305$57c3e1d3@news3.bahnhof.se...
> Sorry about this all, if I weren't so lazy I could have searched MSDN first. Now I did.
>
> If no value is assigned to name, the procedure returns a default value: a numeric function returns
> 0, a string function returns a zero-length string (""), and a Variant function returnsEmpty. A
> function that returns an object reference returns Nothing if no object reference is assigned to
> name (using Set) within the Function.
> The following example shows how to assign a return value to a function named BinarySearch. In this
> case, False is assigned to the name to indicate that some value was not found.
>
> Function BinarySearch(. . .) As Boolean
> . . .
> ' Value not found. Return a value of False.
> If lower > upper Then
> BinarySearch = False
> Exit Function
> End If
> . . .
> End Function
> /Henning"Saga" skrev i meddelandet
> @TK2MSFTNGP02.phx.gbl...
>>I say that it is not safe, given the info that you have provided.
>>
>> For example:
>>
>> Function IsShoe(nr As Integer) As Boolean
>>
>> if nr = 3 then
>> IsShoe = true
>> end if
>>
>> End Function
>>
>> Above the function result is set toTrue only if nr is 3 which means that
>> is nr 3 then IsShoe is not initialized and is therefore assumed to be False, but...
>>
>> Function IsShoe(nr As Integer) As Boolean
>>
>>
>> IsShoe = (nr = 3)
>>
>> End Function
>>
>> The above always sets IsShoe accordingly, but here again...
>>
>>
>> Function IsShoe(nr As Integer) As Boolean
>>
>>
>> IsShoe = true
>>
>> if nr = 3 then
>> IsShoe = false
>> end if
>>
>> End Function
>>
>> The above, by default sets IsShoe to True and only sets it to False if nr is 3.
>> (No relation to the first two)
>>
>> Unless you know how the function behaves, I would say it is not safe to assume any
>> kind of default value.
>>
>> Regards,
>> Saga
>> --
>>
>>
>> "Henning" wrote in message
>> $0$93305$57c3e1d3@news3.bahnhof.se...
>>> Hi grp,
>>>
>>> Is it safe to assume the default for the following is always False?
>>> Function IsShoe(nr As Integer) As Boolean
>>>
>>> /Henning
>>>
>>
>>
>
> |
|
| Back to top |
|
 |
Larry Serflaten
Joined: 04 Oct 2007 Posts: 2644
|
Posted: Thu Feb 21, 2008 1:36 pm Post subject: Re: Bool Function default |
|
|
"PeterD" wrote
> All in one line:
>
> Function IsShoe(nr As Integer) As Boolean
> IsShoe = (nr > 1999 And nr < 3000) or _
> (nr > 4499 And nr < 4600)
> End Function
Something perhaps a bit more readable:
Function IsShoe(ByVal Number As Long) As Boolean
Select Case Number
Case 2000 To 2999, 4500 To 4599
IsShoe = True
Case Else
IsShoe = False
End Select
End Function |
|
| Back to top |
|
 |
Ken Halter
Joined: 04 Oct 2007 Posts: 4150
|
Posted: Thu Feb 21, 2008 2:00 pm Post subject: Re: Bool Function default |
|
|
"PeterD" wrote in message @4ax.com...
>>
>>ummm... not quite That function will *always* return False because
>>there's nothing to tell it otherwise.
>
> Me thinks you missed the 'snipped' bits of code there!
Could be... that's what I get for "butting in line", eh?
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm
|
|
| Back to top |
|
 |
|