msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bool Function default
Goto page Previous  1, 2
 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions
Author Message
Henning



Joined: 04 Oct 2007
Posts: 247

PostPosted: Fri Feb 22, 2008 9:22 pm    Post subject: Re: Bool Function default Reply with quote

Not me, M$ did Wink
It is directly copied from MSDN Help...

/Henning

"Saga" skrev i meddelandet @TK2MSFTNGP02.phx.gbl...
> 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
>>>>
>>>
>>>
>>
>>
>
>

Archived from group: microsoft>public>vb>general>discussion
Back to top
View user's profile Send private message
"Rick Rothstein \



Joined: 04 Feb 2008
Posts: 37

PostPosted: Tue Feb 26, 2008 5:08 pm    Post subject: Re: Bool Function default Reply with quote

>> 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

Well, if it is readability you are after, perhaps this one-liner will meet
the bill...

IsShoe = Abs(nr - 2499.5 + 2050 * (nr > 3000)) 3000)

What do you think?

Rick
Back to top
View user's profile Send private message
Henning



Joined: 04 Oct 2007
Posts: 247

PostPosted: Wed Feb 27, 2008 2:36 am    Post subject: Re: Bool Function default Reply with quote

"Rick Rothstein (MVP - VB)" skrev i
meddelandet @TK2MSFTNGP02.phx.gbl...
>>> 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
>
> Well, if it is readability you are after, perhaps this one-liner will meet
> the bill...
>
> IsShoe = Abs(nr - 2499.5 + 2050 * (nr > 3000)) 3000)
>
> What do you think?
>
> Rick
Did it again!!

At least I guess it could be faster than If..Then..Else, wich in turn is
faster than Select Case.

/Henning
Back to top
View user's profile Send private message
Larry Serflaten



Joined: 04 Oct 2007
Posts: 2644

PostPosted: Tue Feb 26, 2008 7:58 pm    Post subject: Re: Bool Function default Reply with quote

"Rick Rothstein (MVP - VB)" wrote
> >> All in one line:

> Well, if it is readability you are after, perhaps this one-liner will meet
> the bill...
>
> IsShoe = Abs(nr - 2499.5 + 2050 * (nr > 3000)) 3000)
>
> What do you think?

I'm thinking I'm glad I don't have to read your writing. That penmanship is terrible!


LFS
Back to top
View user's profile Send private message
"Rick Rothstein \



Joined: 04 Feb 2008
Posts: 37

PostPosted: Tue Feb 26, 2008 9:48 pm    Post subject: Re: Bool Function default Reply with quote

>> Well, if it is readability you are after, perhaps this one-liner will
>> meet
>> the bill...
>>
>> IsShoe = Abs(nr - 2499.5 + 2050 * (nr > 3000)) 3000)
>>
>> What do you think?
>
> I'm thinking I'm glad I don't have to read your writing. That penmanship
> is terrible!
>
>

What??!!? That looks pretty "neat" to me.

Rick

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group