473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Function Parameters

Hello All,

Is it possible to force a function argument to fall with a range of
values ?

For example:

I have a function which searches a database table and accepts a query
type argument which I would like to be either 1 or 0.

Public Function IsFound(iQueryType As Integer, sName As String)

Can I do this and if so what would be the syntax..
Thanks In Advance

Nov 21 '05 #1
6 1375
hharry,

If the arguments can only be 1 or 0 then I would use a boolean.
Public Function IsFound(iQueryType As Boolean, sName As String)

"hharry" <pa*********@nyc.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello All,

Is it possible to force a function argument to fall with a range of
values ?

For example:

I have a function which searches a database table and accepts a query
type argument which I would like to be either 1 or 0.

Public Function IsFound(iQueryType As Integer, sName As String)

Can I do this and if so what would be the syntax..
Thanks In Advance

Nov 21 '05 #2
"hharry" <pa*********@nyc.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Is it possible to force a function argument to fall with a range of
values ?
That's what coding is for ... ;-)
I have a function which searches a database table and accepts a
query type argument which I would like to be either 1 or 0.


In this particular case, you could /suggest/ values by using an Enum,
as in

Public Enum QueryType
[Type0] = 0
[Type1] = 1
End Enum

Public Function IsFound( _
ByVal eaType as QueryType _
, ByVal sName As String _
) as ??? ' Option Strict On /please/

But that *doesn't* guarantee that you're /always/ going to get one
of those values - since Enums are boiled down to Integers at compile
time, you could /still/ get some awkward .. Soul who manages to foist
the value 37 on your poor, defenceless Function. So you code
"defensively" :

Public Function IsFound( _
ByVal eaType as QueryType _
, ByVal sName As String _
) as ??? ' Option Strict On /please/

If Not [Enum].IsDefined(GetType(QueryType), eaType) Then
Throw New ArgumentException( ...
End If

' Do the real work here

End Function

HTH,
Phill W.
Nov 21 '05 #3
As Pipo mentioned, if the parameter is going to have only 2 values, you are
better off making the parameter a boolean type. In general, if you need fixed
values, you should use enums.

Enum QueryType
Type1=1
Type2
Type3
Type4
End Enum

Public Function IsFound(iQueryType As QuertyType, sName as String)

hope that helps..
Imran.

Hello All,

Is it possible to force a function argument to fall with a range of
values ?

For example:

I have a function which searches a database table and accepts a query
type argument which I would like to be either 1 or 0.

Public Function IsFound(iQueryType As Integer, sName As String)

Can I do this and if so what would be the syntax..

Thanks In Advance


Nov 21 '05 #4
Thanks All,

I am going with the BOOLEAN option.

Nov 21 '05 #5
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> schrieb:
Public Enum QueryType
[Type0] = 0
[Type1] = 1
End Enum


You don't need square brackets here... :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #6
Imran,
As Pipo mentioned, if the parameter is going to have only 2 values, you
are better off making the parameter a boolean type. However! I would recommend an Enum with 2 values instead of Boolean, if the
values of the Enum are more descriptive then simply True & False.

For example

Public Enum Direction
Forward = 0
Backward = 1
End Enum

Public Sub Move(ByVal dir As Direction)
...
End Sub
Move(Direction.Forward)

verses:

Move(True)

I hope you will agree that "Move(Direction.Forward)" is more obvious what is
going to happen then "Move(True)"...

Although I will admit I probably use a boolean more then I use 2 value
Enums... :-)

Just a thought
Jay

"Imran Koradia" <no****@microsoft.com> wrote in message
news:19**********************@news.microsoft.com.. . As Pipo mentioned, if the parameter is going to have only 2 values, you
are better off making the parameter a boolean type. In general, if you
need fixed values, you should use enums.

Enum QueryType
Type1=1
Type2
Type3
Type4
End Enum

Public Function IsFound(iQueryType As QuertyType, sName as String)

hope that helps..
Imran.

Hello All,

Is it possible to force a function argument to fall with a range of
values ?

For example:

I have a function which searches a database table and accepts a query
type argument which I would like to be either 1 or 0.

Public Function IsFound(iQueryType As Integer, sName As String)

Can I do this and if so what would be the syntax..

Thanks In Advance


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
1
by: John Miles | last post by:
Hi -- This is a bit of an implementation-specific problem, but I'd like to post it here to see if there's a general answer within the auspices of the language. I'm developing a high(er)-level...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
6
by: simon | last post by:
Always when I need data reader in my programs, I simply have functions, which creates it for me: Dim rdr As SqlDataReader dim sql as string sql="myStoredProcedure" rdr =...
3
by: Bryan Parkoff | last post by:
Do C/C++ Compiler allow function to contain more than 8 parameters? I checked MS Visual C++ 6.0 that it can only limit 8 parameters, but most C/C++ Compiler can limit maximum 256 parameters. Can...
64
by: Morgan Cheng | last post by:
Hi All, I was taught that argument valuse is not supposed to be changed in function body. Say, below code is not good. void foo1(int x) { x ++; printf("x+1 = %d\n", x); } It should be...
2
by: Maxwell_Smart | last post by:
Is there a way for a function to refer to itself generically? I'd like to use such a thing (should it exist) for convenience and consistency, not functionality. For example: Function...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
4
by: Tony Lownds | last post by:
(Note: PEPs in the 3xxx number range are intended for Python 3000) PEP: 3107 Title: Function Annotations Version: $Revision: 53169 $ Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec...
16
by: arne | last post by:
Hi all, imagine I call a function, but omit one of the parameters, like: foo.c: void foo( int a, int b ) { /* do something with a and b */ return; }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.