[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Function syntax question

Dave Cullen

2/14/2011 3:25:00 AM

I work with a function, Function IsLogged(tagno).

This function's argument is an integer, but it returns a Boolean value.
It operates, but I believe its also creating an error with each access.

Code is like:
Function IsLogged(tagno)
' Do data stuff
If tagno = logged Then
IsLogged = False
Else
IsLogged = True
End If
End Function

I haven't been able to find an example of this.
Should this function's syntax be: Function(tagno) As Boolean ?
Or Function(tagno as integer) As Boolean?


7 Answers

GS

2/14/2011 3:31:00 AM

0

This should work just fine.

Function IsLogged(TagNo as Integer) As Boolean
IsLogged = (TagNo = Logged)
End Function

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup! comp.lang.basic.visual.misc


GS

2/14/2011 3:46:00 AM

0

You don't really need a function to efficiently evaluate the condition.
You could do it like this in your caller:

If (TagNo = Logged) Then...

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Dave Cullen

2/14/2011 3:49:00 AM

0


"GS" <gs@somewhere.net> wrote in message
news:ija8ib$hoa$1@news.eternal-september.org...
> You don't really need a function to efficiently evaluate the condition.
> You could do it like this in your caller:
>
> If (TagNo = Logged) Then...
>
> --
> Garry
>
> Free usenet access at http://www.eternal-sep...
> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>
>
I have it set up that way because its doing database acrobatics, and its
used in different modules.

Thank you


GS

2/14/2011 4:34:00 AM

0

Anita laid this down on his screen :
> "GS" <gs@somewhere.net> wrote in message
> news:ija8ib$hoa$1@news.eternal-september.org...
>> You don't really need a function to efficiently evaluate the condition. You
>> could do it like this in your caller:
>>
>> If (TagNo = Logged) Then...
>>
>> -- Garry
>>
>> Free usenet access at http://www.eternal-sep...
>> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>>
>>
> I have it set up that way because its doing database acrobatics, and its used
> in different modules.
>
> Thank you

Can I assume, then, that the value of 'Logged' is the result of the
dbase acrobatics? If so then <FWIW> I would be inclined to focus the
function on what the dbase acrobatics returns and handle it this way:

Sub myProc()
'do stuff
If (TagNo = IsLogged) Then...
'do more stuff
End Sub

Function IsLogged() As Integer
'do dbase stuff
IsLogged = Logged
End Function

I'd also be inclined to not use the var 'Logged' (if it's defined in
this function) and use the name of the function instead. IOW, load the
value stored in 'Logged' directly into 'IsLogged'.

HTH

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Helmut_Meukel

2/14/2011 9:31:00 AM

0

Anita wrote:
> I work with a function, Function IsLogged(tagno).
>
> This function's argument is an integer, but it returns a Boolean value.
> It operates, but I believe its also creating an error with each access.
>
> Code is like:
> Function IsLogged(tagno)
> ' Do data stuff
> If tagno = logged Then
> IsLogged = False
> Else
> IsLogged = True
> End If
> End Function
>
> I haven't been able to find an example of this.
> Should this function's syntax be: Function(tagno) As Boolean ?
> Or Function(tagno as integer) As Boolean?

Hmm,
it should be:
Function(tagno as Integer) As Boolean

Written as 'Function IsLogged(tagno)' it returns a variant and tagno
is a variant.
If the value of tagno depends on your 'database acrobatics' it may
probably be NULL not an Integer, without throwing an error!
That behavior may be even desirable, but then you must test for NULL
before executing 'If tagno = logged Then'.

Helmut.


Dave Cullen

2/14/2011 5:17:00 PM

0

"GS" <gs@somewhere.net> wrote in message
news:ijabbl$b9u$1@news.eternal-september.org...
> Anita laid this down on his screen :
>> "GS" <gs@somewhere.net> wrote in message
>> news:ija8ib$hoa$1@news.eternal-september.org...
>>> You don't really need a function to efficiently evaluate the condition.
>>> You could do it like this in your caller:
>>>
>>> If (TagNo = Logged) Then...
>>>
>>> -- Garry
>>>
>>> Free usenet access at http://www.eternal-sep...
>>> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>>>
>>>
>> I have it set up that way because its doing database acrobatics, and its
>> used in different modules.
>>
>> Thank you
>
> Can I assume, then, that the value of 'Logged' is the result of the dbase
> acrobatics? If so then <FWIW> I would be inclined to focus the function on
> what the dbase acrobatics returns and handle it this way:
>
> Sub myProc()
> 'do stuff
> If (TagNo = IsLogged) Then...
> 'do more stuff
> End Sub
>
> Function IsLogged() As Integer
> 'do dbase stuff
> IsLogged = Logged
> End Function
>
> I'd also be inclined to not use the var 'Logged' (if it's defined in this
> function) and use the name of the function instead. IOW, load the value
> stored in 'Logged' directly into 'IsLogged'.
>
> HTH
>
> --
> Garry
>
> Free usenet access at http://www.eternal-sep...
> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>
>
Al is working perfectly now.

There is no actual stored Logged value or status.
There is a temporarily logged event, with a time_on, of a voltage input of a
system interface module.
IsLgged is being used like an IsActive, IsOn, etc.

Thanks for your time.


Dave Cullen

2/14/2011 5:18:00 PM

0

"Helmut_Meukel" <Helmut_Meukel@bn-hof.invalid> wrote in message
news:ijasp6$7q3$1@news.eternal-september.org...
> Anita wrote:
>> I work with a function, Function IsLogged(tagno).
>>
>> This function's argument is an integer, but it returns a Boolean value.
>> It operates, but I believe its also creating an error with each access.
>>
>> Code is like:
>> Function IsLogged(tagno)
>> ' Do data stuff
>> If tagno = logged Then
>> IsLogged = False
>> Else
>> IsLogged = True
>> End If
>> End Function
>>
>> I haven't been able to find an example of this.
>> Should this function's syntax be: Function(tagno) As Boolean ?
>> Or Function(tagno as integer) As Boolean?
>
> Hmm,
> it should be:
> Function(tagno as Integer) As Boolean
>
> Written as 'Function IsLogged(tagno)' it returns a variant and tagno
> is a variant.
> If the value of tagno depends on your 'database acrobatics' it may
> probably be NULL not an Integer, without throwing an error!
> That behavior may be even desirable, but then you must test for NULL
> before executing 'If tagno = logged Then'.
>
> Helmut.
>
That is what I used: Function(tagno as Integer) As Boolean

Thanks Helmut