call a function and return with a value

# Thread: call a function and return with a value

1. Senior Member
Join Date
Dec 1969
Posts
213

## call a function and return with a value

I want to call a Function from one Sub and get a value from another. How is this accomplished. I understand how to pass values to one another but not how to pass one value to one and return the new value to the old. EX:<BR><BR>Public Sub Test()<BR> Test2(str)<BR>Final = str<BR>end Sub<BR><BR>Public sub Test2(byVal str as integer)<BR>dim str2 as integer<BR><BR>str2 = str + 4<BR>&#039;How do I Return this new value back to Sub Test<BR><BR>end sub<BR>

2. Senior Member
Join Date
Dec 1969
Posts
896

## RE: call a function and return with a value

You have to make your subs into functions so that they can return something... subs can&#039;t do that... so try this<BR><BR>dim MonkeyNumber as integer = Test(3)<BR>&#039; MonkeyNumber will now = 7<BR><BR>Public Function Test(byval q as integer) as integer<BR> dim i as integer = test2(q)<BR>end function<BR><BR>public function Test2(byval i as integer) as integer<BR> return (i + 4)<BR>end function

3. Senior Member
Join Date
Dec 1969
Posts
896

## ooops

make that line in test() = to <BR><BR>return(test2(q))<BR><BR>duh.

4. Senior Member
Join Date
Dec 1969
Posts
213

## RE: call a function and return with a value

In VB it should be written like this??&#039;<BR><BR> Public Sub Test()<BR> Dim str, str2 As Integer<BR> str2 = Add(str)<BR><BR> End Sub<BR> Public Sub Add(ByVal str As Integer)<BR>str = 6<BR><BR> End Sub<BR><BR>Error message says that Add(str) does not produce a value??<BR>why not??

5. Senior Member
Join Date
Dec 1969
Posts
213

## RE: call a function and return with a value

thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•