By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,877 Members | 1,109 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,877 IT Pros & Developers. It's quick & easy.

Why a data after the parameter list?

P: n/a
Hello

When creating a function or sub procedure what purpose does the data type
declaration outside of the parameter list after the parenthesis on the end
serve?
for example Public Sub mypgm(Byval fld1 as integer) as string
Sep 19 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
=?Utf-8?B?d2lubGlu?= <wi****@verizon.comwrote in
news:3B**********************************@microsof t.com:
When creating a function or sub procedure what purpose does the data
type declaration outside of the parameter list after the parenthesis
on the end serve?
for example Public Sub mypgm(Byval fld1 as integer) as string
The line above is invalid because sub procedures don't return anything.

Functions on the otherhand return data, and it's used to declare the type
of data being returned.
Sep 19 '07 #2

P: n/a
It's the return value of the function. Your example is illegal
syntax, since a Sub does not return a value.

Correct syntax would be:
Public Function MyPgm(ByVal fld1 As Integer) As String

The function MyPgm returns a String.

On Wed, 19 Sep 2007 08:12:02 -0700, winlin <wi****@verizon.comwrote:
>Hello

When creating a function or sub procedure what purpose does the data type
declaration outside of the parameter list after the parenthesis on the end
serve?
for example Public Sub mypgm(Byval fld1 as integer) as string
Sep 19 '07 #3

P: n/a
On Sep 19, 11:12 am, winlin <win...@verizon.comwrote:
Hello

When creating a function or sub procedure what purpose does the data type
declaration outside of the parameter list after the parenthesis on the end
serve?
for example Public Sub mypgm(Byval fld1 as integer) as string
It's purpose is to allow a method to return a value after it is
finished processing.

For Example:

////////////////////
Public Function IsUserValid(ByVal userName As String) As Boolean
If (the user is valid) Then
Return True
Else
Return False
End If
End Function

Public Sub Foo()
Dim isValid As Boolean = IsUserValid("Seth Rowe")
If isValid Then
MsgBox("Seth Rowe is a Valid User")
Else
MsgBox("Seth Rowe is not a Valid User")
End If
End Sub
///////////////////

The code to check whether a given name is a valid user has been
encapsulated into the IsUserValid method. Any other method can now
pass in a string to this function and will receive a boolean value
from the method that will indicate whether the user is, or isn't,
valid. Other examples are methods that might construct an object, such
as a DataTable. In general, the constructed DataTable will be created
in the method and returned as a return value (Public Function
BuildDT() As DataTable).

Thanks,

Seth Rowe

Sep 19 '07 #4

P: n/a
Winlin,

Looking at the other answers shows that it has a lot of possibilities.
Forget VB6 that was time consuming finding itself the correct type.

However beside the answers you got already, don't forget overloading. By
telling te types you can create more methods, with almost the same code.

Cor

"winlin" <wi****@verizon.comschreef in bericht
news:3B**********************************@microsof t.com...
Hello

When creating a function or sub procedure what purpose does the data type
declaration outside of the parameter list after the parenthesis on the end
serve?
for example Public Sub mypgm(Byval fld1 as integer) as string
Sep 20 '07 #5

P: n/a
However beside the answers you got already, don't forget overloading. By
telling te types you can create more methods, with almost the same code.
I don't think overloading applies here as you can't overload based on
return type.

Thanks,

Seth Rowe
Sep 20 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.