Skip to main content

Exercise 5: Write Object Versions of Data Entry and Lookup

  1. The new store subroutine of myBASdatentobj.

    
    public sub store()
    ' store the data
        dim yn, per
     
        input "Store? (y/n): ", yn ' see if user wants to store
        ' only go on if user says yes
        if ( yn <> "y" ) then
            println "...not stored."
            exit sub
        end if
     
        per = New BasTutorial.Person()
        with per
            .Name = name
            .Phone = phone
            .DOB = intdob
            .%Save()
        end with
        per = Nothing
        println "...stored" ' done
    end sub
    
  2. The new load subroutine of myBASlookupobj.

    
    private sub load(id as %Integer)
    ' load a person into local variables
        dim per
        per = OpenId BasTutorial.Person(id)
        with per
            name = .Name
            phone = .Phone
            intdob = .DOB
        end with
        per = Nothing
    end sub
    
  3. The new update subroutine of myBASlookupobj.

    
    private sub update(id As %Integer,_
                       newname As %String,_
                       newphone As %String,_
                       newintdob As %Integer)
    ' update ^PersonD and ^PersonI
        dim per
        per = OpenId BasTutorial.Person(id)
        with per
            .Name = newname
            .Phone = newphone
            .DOB = newintdob
            .%Save() ' this updates indices too, all within a transaction!
        end with
        per = Nothing
        println "...updated."
    end sub
    
  4. Update the getphone subroutine of myBASlookupobj by changing this line:

    
        ph = traverse(^PersonI("Phone", origph), 1, loopid)
    

    to this:

    
        ph = traverse(^PersonI("Phone", origph))
        if ph <> "" then loopid = traverse(^PersonI("Phone", ph, ""))
    
  5. Then change this line:

    
        loopid = ^PersonI("Phone", origph)
    

    to this:

    
        loopid = traverse(^PersonI("Phone", origph, ""))
    
  6. Then change this line:

    
        ph = traverse(^PersonI("Phone", ph), 1, loopid)
    

    to this:

    
        ph = traverse(^PersonI("Phone", ph))
        if ph <> "" then loopid = traverse(^PersonI("Phone", ph, ""))
    
FeedbackOpens in a new tab