[Year 12 SofDev] Proposed Sacs needing feedback ahead of audit

Mark Kelly kel at mckinnonsc.vic.edu.au
Wed May 21 11:00:16 EST 2008


U4O1 concentrates on software that "takes into account a networked 
information system" which can be interpreted in a variety of ways.  Some 
people read it as "networked database" and build GUI front-ends to MySQL 
databases, or tie VB to Access.

My task is a relatively simple module for a small P2P network for 
several workers to enter painting quotes and store the data in a shared 
database.

The "database" is really just a random file with STRUCTURE objects 
("TYPE" in VB6) which can be accessed from a network drive.

The catering to "networked" was just to use record locking so a record 
could not be opened by more that one user at a time.  See demo random 
file VB6 code attached.  It's simple.

Security was handled by simple ROT13 scrambling of database users' 
passwords.  Nothing elaborate.  See VB6 sample code attached.

There is, I feel, a tendency to over-complicate U4O1 and scare many 
teachers (and students) with ambitious scenarios.  I am not teaching SD 
this year, but I remember my kids last year were definitely NOT gun 
programmers, and even relatively simple techniques - like the ones 
attached - took them quite a lot of practice.

But, in the end, how you construct your course comes down to the study 
design's demands, and your own comfort zone.

Cheers
Mark

Townsley, Andrew A wrote:
> Hi,
> 
> What is the main difference between unit3 outcome 2 and unit4 outcome 1.
> On the study design they both claim to use files and portable device eg networked device. They look kind of similar. On outcome 2 unit 3 I am already using files, arrays,structures etc is this too much?
> 
> ________________________________
> 
> From: sofdev-bounces at edulists.com.au on behalf of Kevork Krozian
> Sent: Mon 5/19/2008 3:14 PM
> To: sofdev at edulists.com.au
> Subject: [Year 12 SofDev] Proposed Sacs needing feedback ahead of audit
> 
> 
> 
> Hi Folks,
> 
> Andrew Townsley has asked me to write to the list on his behalf.
>  Andrew is teaching Software Development and will be audited this year.
> He has written 2 programming SACs in need of feedback ahead of his audit. These SACs have been posted on Edulists in the password protected area http://www.edulists.com.au/sofdev/download .
> 
>  Andrew would dearly love you as a teacher of SodDev to give him any positive feedback you can directly to his address at townsley.andrew.a at edumail.vic.gov.au
> 
> He specifically wants to know :
> 
> a)   will it pass an audit  ?
> b)   is it clear enough to understand ?
> 
> and he states, " I am betting I can't use all suggested improvements.".
> 
> All comments and suggestions are welcome and would be very helpful to him
> 
> 
> With thanks
> 
> 
> 
> 
> 
> Kevork Krozian
> IT Manager , Forest Hill College
> k.krozian at fhc.vic.edu.au
> http://www.fhc.vic.edu.au <http://www.fhc.vic.edu.au/>
> Mobile: 0419 356 034
> 
>>>> "Townsley, Andrew A" <townsley.andrew.a at edumail.vic.gov.au> 17/05/2008 10:14 am >>>
> yes just announce to the lists and they can email feedback to me .
> I know I can expect responses I dont agree with and some I do.
> I just dont want to respond to every email I get due to time constraints and I wont overreact to comments I dont' agree with either.
> 
> -----Original Message-----
> From: Kevork Krozian [mailto:Kroset at novell1.fhc.vic.edu.au]
> Sent: Wed 5/14/2008 2:22 PM
> To: Townsley, Andrew A
> Subject: RE: sacs
> 
> Hi Andrew,
> 
>  Do you want me to announce it to the lists or do you want to do it (they are your sacs ) ?
> 
> Regards
> 
> 
> Kevork Krozian
> IT Manager , Forest Hill College
> k.krozian at fhc.vic.edu.au
> http://www.fhc.vic.edu.au <http://www.fhc.vic.edu.au/>
> Mobile: 0419 356 034
> 
>>>> "Townsley, Andrew A" <townsley.andrew.a at edumail.vic.gov.au> 14/05/2008 1:31 pm >>>
> Hi,
> 
> Yes feedback is fine. I just need to know
> a)will it pass an audit
> b) is it clear enough to understand.
> 
> PS I am betting I can't use all suggested improvements.
> 
> ________________________________
> 
> From: Kevork Krozian [mailto:Kroset at novell1.fhc.vic.edu.au]
> Sent: Wed 5/14/2008 10:04 AM
> To: Townsley, Andrew A
> Subject: Re: sacs
> 
> 
> 
> Hi Andrew,
> 
>  Your proposed SACs are posted on edulists under SofDev , SACs which is password protected ( passwords can be applied for from the edulists home page ).
> Do you want to invite feedback or would you like me to ask subscribers to give you feedback on your SACs ?
> 
> Regards
> 
> Kevork
> 
>>>> "Townsley, Andrew A" <townsley.andrew.a at edumail.vic.gov.au> 13/05/2008 11:39 am >>>
> Hi,
> 
> You asked for my 2 sacs to help me out.
> 
> Andrew Townsley
> 
> Important - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Early Childhood Development.
> 
> 
> 
> 
> Important - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Early Childhood Development.
> 
> 
> 
> Important - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Early Childhood Development.
> 
> _______________________________________________
> http://www.edulists.com.au <http://www.edulists.com.au/>
> IT Software Development Mailing List kindly supported by
> http://www.vcaa.vic.edu.au <http://www.vcaa.vic.edu.au/>  - Victorian Curriculum and Assessment Authority and
> http://www.vitta.org.au/vce/studies/infotech/softwaredevel3-4.html  - VITTA Victorian Information Technology Teachers Association Inc
> 
> 
> 
> Important - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Early Childhood Development.
> _______________________________________________
> http://www.edulists.com.au
> IT Software Development Mailing List kindly supported by
> http://www.vcaa.vic.edu.au - Victorian Curriculum and Assessment Authority and
> http://www.vitta.org.au/vce/studies/infotech/softwaredevel3-4.html  - VITTA Victorian Information Technology Teachers Association Inc


-- 
Mark Kelly
Manager - Information Systems
McKinnon Secondary College
McKinnon Rd McKinnon 3204, Victoria, Australia
Direct line / Voicemail: 8520 9085
School Phone +613 8520 9000
School Fax +613 95789253
kel AT mckinnonsc.vic.edu.au

Webmaster - http://www.mckinnonsc.vic.edu.au
IT Lecture notes: http://vceit.com
Moderator: IT Applications Mailing List

A conclusion is the place where you got sick of thinking.
If you Declare War - is it integer or boolean?
-------------- next part --------------
Option Explicit   'force all variables to be declared before use - avoids misspelling of variable names!
Dim encrypted, EncryptedName
Dim i As Integer
Dim u$, p$, a$   'temp variables

Private Sub Form_Load()
    'centre the form onscreen
    Me.Left = (Screen.Width / 2) - (Me.Width / 2)
    Me.Top = (Screen.Height / 2) - (Me.Height / 2)
    
    If Dir("passwords.qqq") > "" Then ' initial password list has already been created
        cmdMakeList.Enabled = False   'disable the button
    End If
    
End Sub

Private Sub cmdLogin_Click()

' validation time!

If txtUserName = "" Then            'no user name
    MsgBox "User name required!"
    txtUserName.SetFocus            'be nice and go to the box for them
    Exit Sub
ElseIf txtPassword = "" Then        'no password?
    MsgBox "Password required!"
    txtPassword.SetFocus
    Exit Sub
End If
  
' encrypt the username and password with simple ROT13 (actually, ROT2!)
' before comparing them with their stored encrypted forms

encrypted = encrypt(txtPassword)      'use a custom function to encrypt the password
EncryptedName = encrypt(txtUserName)  'use a custom function to encrypt the username

' now for the magic bit.  Open the passwords.qqq file and
' check that a matching username and password is in there.
AccessLevel = ""                   'default = no access
Open "passwords.qqq" For Input As 1     'the usernames/passwords file
While Not EOF(1) And AccessLevel = ""   'keep looking until end of file or correct login found
    Input #1, u$, p$, a$                'read encrypted username, password and access level from list
    If u$ = EncryptedName Then          'the username exists
        If p$ = encrypted Then          'password is right
            AccessLevel = Asc(a$) - 100 'work out the access level
            MsgBox "Welcome, authorised person with access level of " & AccessLevel & "!"
        End If
    End If
Wend
Close 1

If AccessLevel = "" Then
    MsgBox "Bad username or password. Access denied."
    Exit Sub
End If

txtPassword = ""

If AccessLevel > 0 Then
    ' go to the privileged form!
    frmAccess.Show
End If

End Sub

Private Sub cmdMakeList_Click()
    CommonDialog1.FileName = "passwords.qqq"
    CommonDialog1.ShowSave
    ' create initial password list
    Open "passwords.qqq" For Output As 1
    Write #1, encrypt("admin"), "GngrjcpV", Chr(9 + 100)   'access level at end
    Write #1, encrypt("user"), "OqwuG", Chr$(5 + 100)
    MsgBox "Created initial password list as passwords.qqq"
    Close 1
End Sub


Private Sub txtPassword_KeyPress(KeyAscii As Integer)
    ' check for ENTER being pressed and trigger the LOGIN button event
    If KeyAscii = 13 Then 'ENTER
        cmdLogin_Click
    End If
End Sub

Private Function encrypt(plaintext As String)
    Dim encoded As String
    Dim i As Integer
    
    For i = 1 To Len(plaintext)   'each character in password
        encoded = encoded & Chr(Asc(Mid$(plaintext, i, 1)) + 2)
    Next

    encrypt = encoded 'return it

'    MORE VERBOSELY, THIS IS HOW THE FUNCTION WORKS

'    letter = Mid$(txtPassword, i, 1)  'pull the character
'    asccode = Asc(letter)             'get its ASCII code
'    rotcode = asccode + 2             'rotate it 2 places
'    newletter = Chr(rotcode)          'convert back to an alphanumeric character
'    encrypted = encrypted & newletter 'build encrypted password letter by letter

' The single-line version of the code removes the need for 4 variables, but it's harder to read.
' That's the price you pay for optimisation.
' Sometimes I write code verbosely during development, and refine it later when all is working.

End Function
Private Sub cmdCancel_Click()
    End
End Sub

-------------- next part --------------
Option Explicit    'insist the all variables are declared before they are used

' the following structure needs to go in GENERAL DECLARATIONS at the very top of the project

Private Type RecordType    ' Define user-defined type.  vb.net equivalent is 'Structure'
    ID As Integer
    Name As String * 20
End Type


Private Sub Form_Load()

    Dim MyRecord As RecordType, RecordNumber    ' Declare variables.
    Dim LastRecordNumber As Integer
    Dim foundit As Boolean
    Dim i As Integer
    
    ' Open sample file for random access.
    
    Open "u:\testfile.db" For Random Shared As #1 Len = Len(MyRecord)
    
     'create 5 records
     
    For i = 1 To 5
        MyRecord.ID = 1000 + i
        MyRecord.Name = "name" & CStr(i) & " Surname" & CStr(i)
        MsgBox "Creating record number " & i & " - " & MyRecord.Name
        Put #1, i, MyRecord
    Next
    
    RecordNumber = 4    ' Define record number.
    Lock #1, RecordNumber    ' Lock record.
    Get #1, RecordNumber, MyRecord    ' Read record.
    
    MsgBox "Changing record 4"
    MyRecord.ID = 234                 ' Modify record
    MyRecord.Name = "John Smith"
    Put #1, RecordNumber, MyRecord    ' Write modified record.
    
    Unlock #1, RecordNumber    ' Unlock current record.
    
    ' add a record
    ' use a private function to get the last record number
    
    LastRecordNumber = FindLastRecord(1, Len(MyRecord))
    'parameter 1 =  1, the file handle
    'paramter 2 = length of the type (this lets the function be re-used in any program with any TYPEs)
    
    Seek #1, LastRecordNumber   ' go to end of file
    MyRecord.ID = 999           ' create new record
    MyRecord.Name = "New person"
    Put #1, , MyRecord     'no record number given, so next one automatically used
    
    MsgBox "Last record accessed in random file was number " & Loc(1)
    
    ' read all records starting from the last.
    
    For RecordNumber = LastRecordNumber To 1 Step -1
        Seek #1, RecordNumber    ' Set position.
        Get #1, , MyRecord       ' Read record.  Note the record number is omitted!
        MsgBox "Person in record " & RecordNumber & " is " & MyRecord.Name
    Next RecordNumber
    
    'find a record
    Seek #1, 1             ' go to start
    foundit = False        ' flag when record is found
    
    While Not EOF(1) And Not foundit   ' keep searching until file ends OR record is found
        Get #1, , MyRecord   ' get next record
        RecordNumber = Loc(1)          'find current recordnumber
        MsgBox "Looking for john smith in record " & RecordNumber
        
        'tip: force uppercase if the case of the string could vary
        'also need to trim because myrecord.name is padded with spaces up until its defined length!
        
        If Trim(UCase(MyRecord.Name)) = "JOHN SMITH" Then        'found it
            MsgBox "Found John Smith in record " & RecordNumber
            foundit = True   'set flag to show find was made so loop should end
            MyRecord.Name = "DELETED"  ' mark for deletion
            Put #1, RecordNumber, MyRecord     'update record
        Else
            MsgBox "Name in record " & RecordNumber & " (" & MyRecord.Name & ") is not john smith"
        End If
    Wend
    
    MsgBox "To summarise the state of play..."
    
    LastRecordNumber = FindLastRecord(1, Len(MyRecord))
    MsgBox "we have " & LastRecordNumber & " records"
        
    For i = 1 To LastRecordNumber
        Get #1, i, MyRecord     ' read record
        MsgBox "Record " & i & " ID=" & MyRecord.ID & ", name=" & MyRecord.Name
    Next
    
    ' to delete a record - write every other record to a new file
    
    MsgBox "Deleting John Smith's record..."
    
    Open "u:\NEWFILE.db" For Random Shared As #2 Len = Len(MyRecord)
    
    Seek #1, 1       'rewind input file
    RecordNumber = 1
    
    ' use my FindLastRecord function again to get number of last record
    
    For i = 1 To FindLastRecord(1, Len(MyRecord))
        Get #1, i, MyRecord     ' read record
        
        If Trim(MyRecord.Name) <> "DELETED" Then                'to be kept
            MsgBox "Writing record" & i & "= " & MyRecord.Name
            Put #2, , MyRecord   'if record number is omitted, the next rec number is used
        Else
            MsgBox "NOT WRITING record " & i & " which is flagged for deletion!"
        End If
    
    Next
    
    ' now close both files
    Close
    
    ' so we can delete the original file...
    Kill "u:\testfile.db"
    
    ' and rename the new file with the old one's name...
    Name "u:\newfile.db" As "u:\testfile.db"
    
    'reopen the changed file to prove it works...
    Open "u:\testfile.db" For Random Shared As #1 Len = Len(MyRecord)
    
    MsgBox "To prove the new file has had the record deleted..."
    
    LastRecordNumber = FindLastRecord(1, Len(MyRecord))
    MsgBox "we now have " & LastRecordNumber & " records"
        
    For i = 1 To LastRecordNumber
        Get #1, i, MyRecord     ' read record
        MsgBox "Record " & i & " ID=" & MyRecord.ID & ", name=" & MyRecord.Name
    Next
    
    
    MsgBox "Now deleting the testfile..."
    Close 1
    Kill "u:\testfile.db"
    MsgBox "All Done! Closing down"
    
    End
    
End Sub

Private Function FindLastRecord(filehandle As Integer, RecordLength As Integer)
    'file handle passed as a parameter
    ' \ is integer divide
    'put return value into variable name the same as the function
    
    FindLastRecord = LOF(filehandle) \ RecordLength    ' Get number of records in file.

End Function


More information about the sofdev mailing list