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

Multiple function return types

P: n/a
Hello,

I am trying to write a function that will return the value to be stored from
any control based on the control's type. So for text boxes and labels it
would return the text value, for list boxes the ListIndex, for combos maybe
the Items data etc. with several possible return types (string, int etc).
My function (that does not work) is:

Public Function SaveValue(ByVal ctrlIn As Control) As VariantType

If (TypeOf ctrlIn Is TextBox) Then
SaveValue = ctrlIn.Text
End If

If (TypeOf ctrlIn Is Label) Then
SaveValue = ctrlIn.Text
End If

If (TypeOf ctrlIn Is ComboBox) Then
Dim cbTemp As ComboBox = CType(ctrlIn, ComboBox)
SaveValue = cbTemp.SelectedIndex
End If

End Function

I played with variant type thinking it might work - but cannot get the
function to perform as I want. Any ideas? Thanks.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Return Type Object


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Mike Hoff" <mi**@home.com> wrote in message
news:10*************@corp.supernews.com...
Hello,

I am trying to write a function that will return the value to be stored from any control based on the control's type. So for text boxes and labels it
would return the text value, for list boxes the ListIndex, for combos maybe the Items data etc. with several possible return types (string, int etc).
My function (that does not work) is:

Public Function SaveValue(ByVal ctrlIn As Control) As VariantType

If (TypeOf ctrlIn Is TextBox) Then
SaveValue = ctrlIn.Text
End If

If (TypeOf ctrlIn Is Label) Then
SaveValue = ctrlIn.Text
End If

If (TypeOf ctrlIn Is ComboBox) Then
Dim cbTemp As ComboBox = CType(ctrlIn, ComboBox)
SaveValue = cbTemp.SelectedIndex
End If

End Function

I played with variant type thinking it might work - but cannot get the
function to perform as I want. Any ideas? Thanks.

Nov 21 '05 #2

P: n/a
Thanks - works perfectly!

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Return Type Object


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Mike Hoff" <mi**@home.com> wrote in message
news:10*************@corp.supernews.com...
Hello,

I am trying to write a function that will return the value to be stored

from
any control based on the control's type. So for text boxes and labels it would return the text value, for list boxes the ListIndex, for combos

maybe
the Items data etc. with several possible return types (string, int etc). My function (that does not work) is:

Public Function SaveValue(ByVal ctrlIn As Control) As VariantType

If (TypeOf ctrlIn Is TextBox) Then
SaveValue = ctrlIn.Text
End If

If (TypeOf ctrlIn Is Label) Then
SaveValue = ctrlIn.Text
End If

If (TypeOf ctrlIn Is ComboBox) Then
Dim cbTemp As ComboBox = CType(ctrlIn, ComboBox)
SaveValue = cbTemp.SelectedIndex
End If

End Function

I played with variant type thinking it might work - but cannot get the
function to perform as I want. Any ideas? Thanks.


Nov 21 '05 #3

P: n/a
Glad to be of help

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Mike Hoff" <mi**@home.com> wrote in message
news:10*************@corp.supernews.com...
Thanks - works perfectly!

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Return Type Object


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Mike Hoff" <mi**@home.com> wrote in message
news:10*************@corp.supernews.com...
Hello,

I am trying to write a function that will return the value to be
stored
from
any control based on the control's type. So for text boxes and labels

it would return the text value, for list boxes the ListIndex, for combos

maybe
the Items data etc. with several possible return types (string, int etc). My function (that does not work) is:

Public Function SaveValue(ByVal ctrlIn As Control) As VariantType

If (TypeOf ctrlIn Is TextBox) Then
SaveValue = ctrlIn.Text
End If

If (TypeOf ctrlIn Is Label) Then
SaveValue = ctrlIn.Text
End If

If (TypeOf ctrlIn Is ComboBox) Then
Dim cbTemp As ComboBox = CType(ctrlIn, ComboBox)
SaveValue = cbTemp.SelectedIndex
End If

End Function

I played with variant type thinking it might work - but cannot get the
function to perform as I want. Any ideas? Thanks.



Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.