Computer Science Canada

Needed Help on Unit, Module etc.

Author:  Anonymous [ Wed May 10, 2006 10:41 pm ]
Post subject:  Needed Help on Unit, Module etc.

I've been wondering if I wanted a specific block of code I wanted to put in every program I ever made, how could I easily transfer it. This is what I mean:

I use my USB Key with all my Turing on it for at home, and at school. But each time I plug it in I have a different letter drive, home is 'F', school room 503 is 'D', and in the library computer lab at school it's 'E'. So when I access music with Music.PlayFile or Pic.Draw(picID), it would automatically determine its directory.

What I want is to incorperate this lblock in everything I do. I'm guessing this is where unit and module are placed, but I'm not sure.

code:


unit
module stack
    export Drive

    procedure Drive
        var computerLib := "KLCVI-LIB-"
        var drive : char

        if (Sys.GetUserName = "Drew Martell") then %tells if im on my home computer
            drive := 'F'

        elsif (Sys.GetUserName = "martelld") then %tells if im at school
            drive := 'D'

        elsif (Sys.GetComputerName = computerLib + "01") or
                (Sys.GetComputerName = computerLib + "02") or
                (Sys.GetComputerName = computerLib + "03") or
                (Sys.GetComputerName = computerLib + "04") or
                (Sys.GetComputerName = computerLib + "05") or
                (Sys.GetComputerName = computerLib + "06") or
                (Sys.GetComputerName = computerLib + "07") or
                (Sys.GetComputerName = computerLib + "08") or
                (Sys.GetComputerName = computerLib + "09") or
                (Sys.GetComputerName = computerLib + "10") or
                (Sys.GetComputerName = computerLib + "11") or
                (Sys.GetComputerName = computerLib + "12") or
                (Sys.GetComputerName = computerLib + "13") then
            drive := 'E'

        end if
    end Drive
end stack



Author:  do_pete [ Thu May 11, 2006 5:38 am ]
Post subject: 

You don't really need to do that because when opening files, you don't need to write its full path. For example, if I had a picture whose path was "C:/folder/pics/a.jpg" and my current directory was "C:/folder/" I would open it like this:
code:
a := Pic.FileNew ("pics//a.jpg")


: