VBA

Moderators: PavlinII
Number of threads: 1614
Number of posts: 3000

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with VB Functions Posted by Superwoman on 22 Nov 2004 at 9:35 AM
Hi if anyone can help me with these 4 functions I woud be very grateful.
Have to write functions as well as make program run in Visual Basic.


A. Write a private function that takes 2 surnames as arguments, and returns 1 if the
surnames are equal, or 0 if unequal. Be careful to match cases.



B. Write a public function named IsInRange(), which takes one numeric argument, and
returns a Boolean value depending on whether that arguments value is within the inclusive
range 100 to +100.


C. Write a function which takes 2 integer arguments (say p and q), and returns 1 if p is a
factor of q, otherwise returns 0. For example, if the functions arguments were (4, 20) then
the function would return 1 because 4 is a factor of 20.


D. Write a function that takes hours worked and rate of pay as arguments, and returns the
amount due. Using this function, create a program whose purpose is to calculate and
display the total pay (i.e. the amount due) to an employee after that employee has entered
his/her name, payroll number, and other necessary details through text boxes.

Thanks Very Much
Report
Re: Help with VB Functions Posted by PavlinII on 1 Dec 2004 at 1:23 PM
: Hi if anyone can help me with these 4 functions I woud be very grateful.
: Have to write functions as well as make program run in Visual Basic.
:
:
: A. Write a private function that takes 2 surnames as arguments, and returns 1 if the
: surnames are equal, or 0 if unequal. Be careful to match cases.
:
:
:
: B. Write a public function named IsInRange(), which takes one numeric argument, and
: returns a Boolean value depending on whether that arguments value is within the inclusive
: range 100 to +100.
:
:
: C. Write a function which takes 2 integer arguments (say p and q), and returns 1 if p is a
: factor of q, otherwise returns 0. For example, if the functions arguments were (4, 20) then
: the function would return 1 because 4 is a factor of 20.
:
:
: D. Write a function that takes hours worked and rate of pay as arguments, and returns the
: amount due. Using this function, create a program whose purpose is to calculate and
: display the total pay (i.e. the amount due) to an employee after that employee has entered
: his/her name, payroll number, and other necessary details through text boxes.
:
: Thanks Very Much
:

Private Function IsFactor(ByVal p As Integer, ByVal q As Integer) As Boolean
    IsFactor = (q = Fac(p))
End Function

Private Function Fac(ByVal Num As Integer) As Long
Dim i As Integer
    If Num < 0 Then Exit Function
    Fac = 1
    For i = 1 To Num
        Fac = Fac * i
    Next i
End Function

Private Function CompareSurnames(ByVal Sur1 As String, ByVal Sur2 As String) As Integer
    CompareSurnames = IIf(StrComp(Sur1, Sur2, vbBinaryCompare) = 0, 0, 1)
End Function

Public Function IsInRange(ByVal ValueToTest As Long) As Boolean
    IsInRange = (ValueToTest <= 100 And ValueToTest >= -100)
End Function

Private Function GetAmountDue(ByVal Hours As Single, ByVal RateOfPay As Single) As Single
    GetAmountDue = Hours * RateOfPay
End Function

this should work..
And next time you should TRY to write this youself.

Pavlin II[/size]

Don't take life too seriously anyway you won't escape alive from it!





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.