Jump to content

Optional parameters in public procedures


it9888
 Share

Recommended Posts

Hi all,I hope you can help me with this one. I have a public function in a web service and i need to pass some parameters in it. Some of them are optional and some are not. How do i define that some of my parameters are optional? Here's my code:

<WebMethod(Description:="")> _		Public Function ShowReservation(ByVal myusername As String, ByVal mypassword As String, ByVal MyResNo As String, ByVal FromDate As Date, ByVal ToDate As Date) As DataSet		Dim objConn As New OleDbConnection(ConfigurationSettings.AppSettings("DSN"))		Dim objDA As OleDbDataAdapter		Dim objDS As New DataSet		Dim SqlString, clientno As String		clientno = GetClientNo(myusername, mypassword)		If UserExists(myusername, mypassword) Then			SqlString = ""			SqlString = SqlString & " Select Country, ResNo, RegDate, Hirer From Res "			SqlString = SqlString & " Where ClientNo='" & clientno & "'"			If MyResNo <> "" Then				SqlString = SqlString & " And Res_No='" & MyResNo & "'"			End If			objDA = New OleDbDataAdapter(SqlString, objConn)			objDA.Fill(objDS, "Reservation")			objConn.Close()			Return objDS		End If	End Function

Tha paramateres MyResNo, FromDate ,ToDate should be optional.Any ideas? Thanxit9888

Link to comment
Share on other sites

I don't use VB, so this is just from a Google search. I don't know how helpful it'll be:

Starting with VB4, Visual Basic introduced Optional parameters. These are procedure parameters that are just what they say they are, optional. To define an Optional parameter, you use the Optional key word as shown below.
' Display a data initialized with the data from the defined record numberPublic Sub Display(Optional lRecNumber as Variant)	If IsMissing(lRecNumber) then		' <Code to display blank form	Else		' <Code here to get the defined record>	End IfEnd Sub

The IsMissing function is used to determine whether or not the Optional Variant argument was provided when the function is called. The IsMissing function will return true if no argument was passed for the Optional parameter.

src = http://www.insteptech.com/techlibrary/vbclassic/vb6_lang.htmSo my guess would be that you change your function definition to be something like this:
Public Function ShowReservation(ByVal myusername As String, ByVal mypassword As String, Optional ByVal MyResNo As String, Optional ByVal FromDate As Date, Optional ByVal ToDate As Date) As DataSet

I hope it helps!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...