Getting the value from another function (1 Viewer)

gstylianou

Registered User.
Local time
Today, 16:26
Joined
Dec 16, 2013
Messages
357
Hi, how can i get the value from another public function in the following example?

Public Function GetValuesFromForm() As Boolean
Dim X As String
Dim y As String

If 100+10=110 then
x=True
Else
x=False
End if

GetValuesFromForm=X

y=GetValuesFromForm()

End Function

I tried into another Public Function to get the result of the x like the following example and i'm getting the following error

If GetValuesFromForm = True Then
MsgBox "1"
End If

Sorry about my basic knowledge of vba..
 

Attachments

  • vba error.JPG
    vba error.JPG
    17.1 KB · Views: 52

gstylianou

Registered User.
Local time
Today, 16:26
Joined
Dec 16, 2013
Messages
357
Why not just say:- y = x?
its the same...the issue its not that.....The problem is how can i get this result from another public function
 

ebs17

Well-known member
Local time
Today, 15:26
Joined
Feb 7, 2020
Messages
1,946
You get caught up in your awkwardness.
Code:
Public Function fTest() As Boolean
   If 110 = 110 Then
      fTest = True
   Else
      fTest = False
   End If
End Function

Sub call_Test()
   If fTest = True Then MsgBox "hello"
End Sub

Dim X As String ... What is the purpose of the variable? In addition, the data type String does not correspond to the defined data type Boolean of the function return.
The function name should talk about what the function does.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:26
Joined
May 21, 2018
Messages
8,529
If the function getvaluefroform is in a form's module it is not exposed outside the class without referring to an instance of the class. This is likely why you get that error. That error means it does not see the function with the name getvaluesfromform.
This error also happens with typos.
Y = getvalfromfrm
Will fail since no function with that name exists.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:26
Joined
May 21, 2018
Messages
8,529
If a function is on a form's module you have to go through the instaniation of the form.
y = Forms!SomeFormName.GetValueFromForm()
For this example that design makes no sense, but this is common for other classes.
 

Users who are viewing this thread

Top Bottom