Function return value

Hello, Experts!
Let say I have function like

    Function newStr(ByVal str As String)
        Dim str_double As String
        Dim str_tripple As String

        str_double = str & str
        str_tripple = str & str & str
        Return str_double
        Return str_tripple
    End Function

How to call this function on a page, and be able to see the str_double and str_tripple?

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub


Thanks for any help.
bogdemAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KudzullcCommented:
bogdem,
Private Function newStr(ByVal str As String)
        Dim str_double As String
        Dim str_tripple As String

        str_double = str & str
        str_tripple = str & str & str
        Return str_double
        Return str_tripple
    End Function


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

newStr(MsgBox(str_double & " is Double the Fun" & vbCrLf & str_tripple & " is even better!"))

End Sub

Try that!

gl,
Lucas
0
KudzullcCommented:
Ha, rather this!  doh!

Private Function newStr(ByVal str As String)
        Dim str_double As String
        Dim str_tripple As String

        str_double = str & str
        str_tripple = str & str & str
        Return str_double
        Return str_tripple
    End Function


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

newStr(TextBox1.Text.toString)

End Sub

Sorry was in hurry!

Lucas
0
bogdemAuthor Commented:
Empty textBox on the page.
What string are you passing to the function?

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

KudzullcCommented:
bogdem,

I am not sure if you can return two values from a function.  Try this...

Dim str_double as String
Dim str_tripple as String

Private Function newStr(ByVal str As String)
        str_double = str & str
        str_tripple = str & str & str
End Function


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim test as string = "apple"
newStr(test)
MsgBox(str_double & " is Double the Fun" & vbCrLf & str_tripple & " is even better!"))
End Sub

Sorry for the number of posts with bad code...  :-/

Lucas
0
YZlatCommented:
I'd use a Sub instead of a function since you can't have two return statements:

 Sub newStr(ByVal str As String,ByVal str_double as string, ByVal str_tripple as string )
        str_double = str & str
        str_tripple = str & str & str
 End Sub

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          Dim str_double As String
        Dim str_tripple As String
        newStr(str,str_double,str_tripple)
         MsgBox(str_double & " is Double the Fun" & vbCrLf & str_tripple & " is even better!"))
    End Sub
0
bogdemAuthor Commented:
Here is what I have

Partial Class _Default
    Inherits System.Web.UI.Page



    Sub newStr(ByVal str As String, ByVal str_double As String, ByVal str_tripple As String)


        str_double = str & str
        str_tripple = str & str & str

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim str_double As String
        Dim str_tripple As String
        Dim str As String = "Hello "
        newStr(str, str_double, str_tripple)
        Response.Write("double " & str_double & "<br>")
        Response.Write("tripple " & str_tripple)
    End Sub
End Class


NO values from Sub
0
KudzullcCommented:
bogdem,
Are you trying this code for ASP?
Lucas
0
bogdemAuthor Commented:
Sorry, I'm in the wront branch :(.
Yes I'm trying it for ASP.NET
0
KudzullcCommented:
No Problem!  :)

I know very little about ASP!

gl,
Lucas
0
YZlatCommented:
Try adding two Labels:
 Label1 and Label2:

Sub newStr(ByVal str As String, ByVal str_double As String, ByVal str_tripple As String)


        str_double = str & str
        str_tripple = str & str & str

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim str_double As String
        Dim str_tripple As String
        Dim str As String = "Hello "
        newStr(str, str_double, str_tripple)
        Label1.Text="double " & str_double
        Label2.Text="tripple " & str_tripple
    End Sub
0
YZlatCommented:
change ByVal to ByRef
0
YZlatCommented:
Partial Class _Default
    Inherits System.Web.UI.Page



    Sub newStr(ByVal str As String, ByRef str_double As String, ByRef str_tripple As String)


        str_double = str & str
        str_tripple = str & str & str

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim str_double As String
        Dim str_tripple As String
        Dim str As String = "Hello "
        newStr(str, str_double, str_tripple)
        Response.Write("double " & str_double & "<br>")
        Response.Write("tripple " & str_tripple)
    End Sub
End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
farsightCommented:
Better to have 2 separate functions, each with a single well-defined purpose.
Plus, it makes the code a LOT simpler, because we don't need all those pesky variables.

    Function DoubleString(ByVal str As String) As String
        Return str & str
    End Function

    Function TrippleString(ByVal str As String) As String
        Return str & str & str
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim str As String = "Hello "

        Response.Write("double " & DoubleString(str) & "<br>")
        Response.Write("tripple " & TrippleString(str))
    End Sub

Simple, huh?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.