Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling one method from another 1

Status
Not open for further replies.

Chopstik

Technical User
Oct 24, 2001
2,180
US
I am creating a single class module that contains several functions. What I'm wondering is if I call one method from another within the class whether it will return the value from the second method to the first and then that will be the value returned in the application being run. I tried doing this using a simple test and was not able to see it work, so not sure if I'm doing something wrong or if it simply is not possible. Anyone know about this? Thanks! Give me liberty, or give me pizza...
 
Maybe this will help. Start a new project and add a class module. In the class add this code

Option Explicit

Function Function1(ByVal str1 As String) As String
Function1 = Function2(" String from 1 is " & str1)
End Function

Function Function2(ByVal str2 As String) As String
Function2 = Function3(" String from 2 is " & str2)
End Function

Function Function3(ByVal str3 As String) As String
Function3 = " String from 3 is " & str3
End Function

and on the form add 3 command buttons and this code

Option Explicit
Dim c As New Class1

Private Sub Command1_Click()
Print c.Function1("Command1")
End Sub

Private Sub Command2_Click()
Print c.Function2("Command2")
End Sub

Private Sub Command3_Click()
Print c.Function3("Command3")
End Sub


and run the program. If you click on command1 it will call the 1st function which calls the 2nd function which calls the 3rd function. The 3rd function then returns to the 2nd which returns to the 1st which was called by the c.Function1 method of the command1 button.
If you click command3 only the Function3 is called. Does that make sense or help at all? If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
Actually makes a lot of sense. I also think I see where my problem was - I was calling the other method, but not necessarily returning the value. I'll test this and see what happens. Thanks! Give me liberty, or give me pizza...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top