PC Review


Reply
Thread Tools Rate Thread

How does this function works?

 
 
Jay
Guest
Posts: n/a
 
      12th Jan 2009
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
 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      12th Jan 2009
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" <(E-Mail Removed)> wrote in message
news:FE54A247-03A5-42EC-A325-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      12th Jan 2009
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
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:FE54A247-03A5-42EC-A325-(E-Mail Removed)...
>> 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

>
>



 
Reply With Quote
 
Jay
Guest
Posts: n/a
 
      12th Jan 2009
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
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:FE54A247-03A5-42EC-A325-(E-Mail Removed)...
> >> 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

> >
> >

>
>
>

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      12th Jan 2009
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" <(E-Mail Removed)> wrote in message
news:7223ADF8-08DF-441E-915E-(E-Mail Removed)...
> 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
>> news:(E-Mail Removed)...
>> > 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" <(E-Mail Removed)> wrote in message
>> > news:FE54A247-03A5-42EC-A325-(E-Mail Removed)...
>> >> 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
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
Jay
Guest
Posts: n/a
 
      12th Jan 2009
Thanks Peter thats all I need to know. Anyway that code was'nt my work Im
trying to understand how and why he does that.

Thanks you and regards,
Jay

"Peter T" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:7223ADF8-08DF-441E-915E-(E-Mail Removed)...
> > 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
> >> news:(E-Mail Removed)...
> >> > 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" <(E-Mail Removed)> wrote in message
> >> > news:FE54A247-03A5-42EC-A325-(E-Mail Removed)...
> >> >> 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
> >> >
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how AVG function works Randy Starkey Microsoft Excel Discussion 4 10th Oct 2007 07:43 PM
Creating a Macros function but co9ntent of function only works in a sub plz help Alexandre Brisebois (www.pointnetsolutions.com) Microsoft Excel Discussion 6 20th Jul 2005 06:26 PM
Dedupe Function works/works not Tom Bock Microsoft Excel Worksheet Functions 5 17th Mar 2004 08:41 PM
DLL function works from VB6 and not from VB.NET - HELP! James Radke Microsoft VB .NET 18 21st Nov 2003 01:15 AM
Javascript function works but C# function doesn't execute Jim Hammond Microsoft ASP .NET 2 14th Nov 2003 08:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:06 AM.