How does this function works?
Let me re-phrase Bob's light hearted comment and direct it to you.
The code is badly written. As posted it has is no context. It is not
possible for anyone to understand what it is supposed to do, how it does it,
or how to use it. At least not without a lot of effort, second guessing
what's intended and correcting it.
If you are looking at it only as a learning exercise it serves no useful
purpose.
Concerning ByRef, all is explained in VBA Help. Following should show the
difference between ByRef and ByVal
Sub test()
Dim apple As Long, pear As Long, vResult
apple = 3: pear = 5
vResult = foo(apple, pear)
Debug.Print vResult, apple; pear ' 16, 6 5
' notice ByRef apple returns changed but ByVal pear is unchanged
End Sub
Function foo(ByRef a As Long, ByVal b As Long)
a = a * 2
b = b * 2
foo = a + b
End Function
Regards,
Peter T
"Jay" wrote in message
...
Guys, I'd just like to know how does a function works using the code below
as
an example coz it is difficult to show its result without any context. So
here's specifically is the thing I wanna know:
- if you use this function to other procedures and declare a variable in
it,
does these byref variable be computed first in this function before being
used by other procedure?
Thanks for the help.
jay
"Bob Phillips" wrote:
I am disappointed with you Tim.
Given a piece of badly written code with absolutely no context, you fail
to
understand what it does, how it does it, and how to use it.
--
__________________________________
HTH
Bob
"Tim Williams" <timjwilliams at gmail dot com wrote in message
...
Use it for what ?
It's clearly only a small part of something bigger (and that is some
odd
coding style....) - what part is giving you a problem?
Tim
"Jay" wrote in message
...
Hi Guys!
Can anyone help me how does this one works and how to use this
function?
Thanks,
Jay
Function VTest(ByRef AMsg As String, ByRef AMsW As Double, ByRef AMsX
As
Integer, _
ByRef AMsY As Integer, ByRef AMsZ As Integer, ByRef AMsH As
Integer,
ByRef AMsT As Variant)
'Verify ActiveCell and ActiveSheet Selection
'Used by Procedures - Months, Distribute, & Produce
Dim Tmp As Variant, Tmi As Integer
VTest = WWks()
If VTest Then Exit Function
AMsP = AMsk
If IsNumeric(Expression:=ActiveCell.Value) Then
AMsW = ActiveCell.Value
If IsNumeric(AMsW) Then
GoTo Rtest
Else
GoTo Erxis
End If
Else
GoTo Erxis
End If
Erxis:
AMsD = AMsP & AMsg & Chr(13) & Chr(10) & Chr(13) & Chr(10) & AMsc
Beep
Beep
Tmp = vbOKOnly + vbCritical
ARep = MsgBox(prompt:=AMsD, Buttons:=Tmp, Title:=" SELECTION
ERROR")
Erxi2:
VTest = True
Exit Function
Rtest:
If ActiveCell.Row = 17 Then GoTo Erxi2
AMsX = ActiveCell.Column
AMsY = ActiveCell.Row
AMsH = 0
If AMsg = MSP Then
Tmp = Application.Lookup(AMsX, vrEITab)
If Tmp < AMsX Then GoTo Erxis
If AMsX = 5 Then
VTest = False
Exit Function
End If
End If
AMsP = AMso
AMsH = Int((AMsX - AMsZ) / 4)
If AMsX < AMsZ Or AMsX Range("MaxReqCol").Value Then GoTo Erxis
Tmp = Application.Lookup(AMsY, AMsT)
' If Tmp < AMsY Then GoTo Erxis
VTest = False
End Function 'Vtest
|