Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 creating functions
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hey_joe42




PostPosted: Thu Mar 20, 2003 5:11 pm   Post subject: creating functions

i want to make part of my program into a function with a variable the changes but works like i input it from the program and stuff
here is what i have not function"ed"
code:
        open : fn, "inventory1.bin", read, seek
        put "Enter category"
        get manu
        exit when manu = "quit"
        exit when eof (fn)
        read : fn, prod
        View.Set ("graphics:600;400")         % Enlarge the window to the maximum size
        % The Text Field IDs
        var textBox : int
        % The label for the title
        var title : int
        % The name of the file to be viewed
        const fileNameToBeViewed : string := "inventory1.bin"
        % Attempt to open the file.  Put an error message if open fails
        var f : int
        open : f, fileNameToBeViewed, read
        if f = 0 then
            put "Unable to open '" + fileNameToBeViewed + "' : ", Error.LastMsg
            return
        end if
        % We opened the file successfully.  Now create the widgets.
        GUI.SetBackgroundColour (grey)
        % Create the title label
        title := GUI.CreateLabelFull (20, 280, fileNameToBeViewed, 250, 0,
            GUI.CENTER, 0)
        % Create the text box
        textBox := GUI.CreateTextBoxFull (10, 10, 580, 365, GUI.INDENT, 0)
        % Read the file and place it in the text box.
        var line : string
        line := "Title  Manufact Price  #in stock  warning #  #to order  product # Category  Sale"
        GUI.AddLine (textBox, line)
        loop
            exit when eof (f)
            read : f, prod
            if prod.cater = manu then
                line := prod.product + "   |   " + prod.manufacturer + "   |   $" + realstr (prod.price, 6) + "   |  " + intstr (prod.number) + "  |  " + intstr (prod.reorder) + " | " +
                    intstr (prod.numinstock) + " | " + prod.prodnumber + " | " + prod.cater + " | " + prod.sale
                GUI.AddLine (textBox, line)
            end if
        end loop
        close : f         % Close the file
        % Process Events
        var mx, my, mbtn : int
        var font1 : int
        font1 := Font.New ("Arial:10")
        drawfillbox (20, 380, 59, 395, 35)
        Font.Draw ("BACK", 22, 382, font1, 0)
        loop
            if buttonmoved ("down") then
                buttonwait ("down", mx, my, mbtn, mbtn)
                if mbtn = 1 then
                    if mx > 20 and mx < 59 and my > 380 and my < 395 then
                        cls
                        displayinfo
                    end if
                end if
            end if
            exit when GUI.ProcessEvent
        end loop


where is says if prod.cater=manu, i want to be able to create a variable for prod.cater so that it can change, like i can input in for the function stuff like if for one time i run it i want it to be prod.cater it does so, and if the other i want it to be prod.sale it does so, how do i do this?
Sponsor
Sponsor
Sponsor
sponsor
hey_joe42




PostPosted: Thu Mar 20, 2003 5:47 pm   Post subject: (No subject)

or does anyone have any other ideas cuz maybe i functions isn't good enough, like maybe a procedure, or im out of ideas, i just want it so that i can have it change lets say call it var chngui:string, and i want it to be field that will change so i don't have to write out the gui part everytime
Tony




PostPosted: Thu Mar 20, 2003 6:48 pm   Post subject: (No subject)

i just wrote a huge tutorial on procedures and functions - http://www.compsci.ca/bbs/viewtopic.php?t=407 I hope you'll find it useful
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
hey_joe42




PostPosted: Thu Mar 20, 2003 7:00 pm   Post subject: thanks

that refreshed my brain and i've got it
code:
procedure guilishious (produ : string)
    open : fn, "inventory1.bin", read, seek
    put "Enter category"
    get manu
    %exit when eof (fn)
    read : fn, prod
    View.Set ("graphics:600;400")             % Enlarge the window to the maximum size
    % The Text Field IDs
    var textBox : int
    % The label for the title
    var title : int
    % The name of the file to be viewed
    const fileNameToBeViewed : string := "inventory1.bin"
    % Attempt to open the file.  Put an error message if open fails
    var f : int
    open : f, fileNameToBeViewed, read
    if f = 0 then
        put "Unable to open '" + fileNameToBeViewed + "' : ", Error.LastMsg
        return
    end if
    % We opened the file successfully.  Now create the widgets.
    GUI.SetBackgroundColour (grey)
    % Create the title label
    title := GUI.CreateLabelFull (20, 280, fileNameToBeViewed, 250, 0,
        GUI.CENTER, 0)
    % Create the text box
    textBox := GUI.CreateTextBoxFull (10, 10, 580, 365, GUI.INDENT, 0)
    % Read the file and place it in the text box.
    var line : string
    line := "Title  Manufact Price  #in stock  warning #  #to order  product # Category  Sale"
    GUI.AddLine (textBox, line)
    loop
        exit when eof (f)
        read : f, prod
        if prod.cater = manu then
            line := prod.product + "   |   " + prod.manufacturer + "   |   $" + realstr (prod.price, 6) + "   |  " + intstr (prod.number) + "  |  " + intstr (prod.reorder) + " | " +
                intstr (prod.numinstock) + " | " + prod.prodnumber + " | " + prod.cater + " | " + prod.sale
            GUI.AddLine (textBox, line)
        end if
    end loop
    close : f             % Close the file
    % Process Events
    var mx, my, mbtn : int
    var font1 : int
    font1 := Font.New ("Arial:10")
    drawfillbox (20, 380, 59, 395, 35)
    Font.Draw ("BACK", 22, 382, font1, 0)
    loop
        if buttonmoved ("down") then
            buttonwait ("down", mx, my, mbtn, mbtn)
            if mbtn = 1 then
                if mx > 20 and mx < 59 and my > 380 and my < 395 then
                    cls
                    displayinfo
                end if
            end if
        end if
        exit when GUI.ProcessEvent
    end loop
end guilishious

thanks
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: