Results 1 to 2 of 2

Thread: Help! Sub-procedure to Function

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    6

    Help! Sub-procedure to Function

    Hi im supposed to put a button in a worksheet, such that when you click the button, the main code(for this question) will be executed.
    Option Explicit
    'Writen by Jada Al-Aswad


    Sub A5Q1a(ByVal NG As Single, ByVal LG As String)
    If (NG >= 90) Then
    LG = "A"
    ElseIf (NG >= 60) Then
    LG = "B"
    Else
    LG = "C"
    End If

    End Sub

    Sub A5Q1Main()
    Dim StudentNG As Single
    Dim StudentLG As String
    Dim StudentName As String

    StudentLG = "F"
    StudentNG = 52 'Please replace this NG by your first two digits of your student #
    StudentName = "Jada Al-Aswad" 'Please replace this Name by your name

    Call A5Q1a(StudentNG, StudentLG)

    MsgBox ("The final grade of " & StudentName & ": " _
    & StudentNG & " => " & StudentLG)
    End Sub



    Apparently there's a mistake here but i have no idea what it is.. this program is to to write a program to convert your numeric grade (NG) to letter grade (LG). The input is your NG and the output is your LG. Then i have to change the sub-procedure to a function to solve the same problem. Suppose the input is NG, and the return value of the function is LG.

    HELPP

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help! Sub-procedure to Function

    lg should be passed byref

    to make into function
    vb Code:
    1. function lg(ng as single) as string
    2. 'your code
    3. ' must set value for lg
    4. end function
    difference for function is that it should return something to the caller, either a value, as in this case, or success /failure of the function
    studentlg = lg(studentng)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width