Consulting

Results 1 to 3 of 3

Thread: Basic code help1!!!

  1. #1

    Unhappy Basic code help1!!!

    I am a complete noob so at vba so can you help make these psudocode into a vba code thanks.

    Public function MostImpPupilID()
    Initialise high score to 0
    Initialise Low score to 21
    Initialise score difference to 0



    Connect Pupil and scores tables to recordsets
    Find the first pupil in the pupil in the pupil’s recordset with the required year group

    If no student found in the year group
    Display error message
    Else
    Loop until no matching pupil in year group found
    Find the first result matching the current pupil id
    If no student result found
    Display error message
    Else
    Loop until no more result for current pupil is found
    If result is higher than the highest sciore
    Ser highest score to result
    End if
    Find next result for the Current pupil
    Loop
    If highest score – lowest score is > previous score difference
    Set previous score difference to highest score – lowest score
    Set MostImpStudentID to current student ID
    Reset highest score to 0
    Reset lowest score to 21
    End if
    End if
    Find next pupil in the current year group
    Loop
    End if
    End function

    Public function BestAvePupilid()
    Declare rspupil As Recordset
    Declare rsScore As Recodset
    Start with the total score value of 0
    Start with a counter value of 0
    Connect rsPupil to tbl_pupil_information
    Connect rsScore to tbl_test_information


    Find the first pupil in the rsPupil with the required year group
    If no pupil found in the year group
    Display error message
    Else
    Loop until no matching pupils in year group found
    Find the first result matching the current pupil id
    If no pupil result found
    Display error message
    Else
    Loop until current pupil ID is not found in result
    Add test result to total
    Add one to counter
    Loop
    End if
    Find next result for current pupil
    Divide the total score by the counter
    If the current average is higher than the previous average
    Set the previous average score to the current average
    Set BestaAvePupilId to current pupil ID
    Reset the total score to 0
    Reset the total score to 0
    Ed if
    Fin the next pupil in the required year group
    Loop
    End if
    End function
    Last edited by SamT; 03-05-2014 at 07:38 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    hey, lightichigo, welcome to VBAX.

    I took the VBA Tags out because the formatting algorithm they use requires using at least a semblance to VBA in the "Code".

    Here at VBAX, we stress teaching and learning, not "doing for," so I am first going to point you to the place to start.

    It's obvious that you understand some programing so I don't think you will need too much.

    Variables should be explicitly declared and you can force this by typing "Option Explicit" as the first line of code on any code "Page." You can use the VBA Menu >> Tools >> Options >> Editor and marking "Require Variable Declaration." Personally, have all options checked except drag and drop.

    Declaring some variables:

    Dim VarA As String
    Dim varb As Long
    Dim VARC As Object
    Dim varD As Variant 'Any of the above

    Their initial values are as you would suspect, except for Variants:

    VarA = "" 'Empty string
    varb = 0 'zero
    VARC = Nothing 'A very special object. I think, I warranty will be corrected if wrong
    varD = Null 'unassigned

    After that, except for objects, a simple assignment for their values:

    VarA = "Some String goes here"
    varb = 3
    Set VARC = Workbooks("Book1") 'A Collection (Object) Item Name
    varD = 13 + 29
    'and
    Set varD = Worksheets(1)
    'A Collection Item Index


    The easiest way to use help, IMO, is to place the cursor in or adjacent to a VBA word in the Code Pane, and press F1.

    To open the VB Editor, press Alt+F11
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Tutor
    Joined
    Mar 2014
    Posts
    210
    Location
    This looks like it would be better served with a few queries in a macro and zero vba code.

Posting Permissions

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