Help with VB Functions - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help with VB Functions

SuperwomanSuperwoman Posts: 4Member
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

Comments

  • PavlinIIPavlinII Posts: 404Member
    : 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
    :

    [code]
    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[/code]
    this should work..
    And next time you should TRY to write this youself.

    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.