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

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




PostPosted: Mon Jun 02, 2003 9:59 am   Post subject: Class Error

When I run my program OOT highlights the following code and says

I_numeratorTextField := GUI.CreateTextFieldFull (100, 75, 30, "",
Edit, GUI.EXDENT, Font.New ("Arial:14"), 0)

Class subprograms cannot be subprogram variables

What does this mean?

code:

procedure Edit (text : string)
        if strintok (GUI.GetText (I_numeratorTextField)) = false then
            GUI.SetText (I_numeratorTextField, "")
        elsif strintok (GUI.GetText (I_denominatorTextField)) = false then
            GUI.SetText (I_denominatorTextField, "")
        else
        end if
    end Edit

    procedure Get
        I_inputWindow := Window.Open ("graphics:300;100")
        I_numeratorTextField := GUI.CreateTextFieldFull (100, 75, 30, "",
            Edit, GUI.EXDENT, Font.New ("Arial:14"), 0)
        I_denominatorTextField := GUI.CreateTextFieldFull (100, 50, 30, "",
            Edit, GUI.EXDENT, Font.New ("Arial:14"), 0)
    end Get
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Mon Jun 02, 2003 11:34 pm   Post subject: (No subject)

i ran the code and did not get any errors, may be if you post all your code we could help more...
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
vlovich




PostPosted: Tue Jun 03, 2003 8:21 am   Post subject: (No subject)

Hacker Dan wrote:
i ran the code and did not get any errors, may be if you post all your code we could help more...

Don't know how cause when I ran it there were 9 errors. But back to the problem at hand, the reason your getting a Class subprograms cannot be subprogram variables message is cause:

I_numeratorTextField := GUI.CreateTextFieldFull (100, 75, 30, "",
Edit, GUI.EXDENT, Font.New ("Arial:14"), 0)

you use Edit as a variable although there is an identically named function.
tum_twish




PostPosted: Tue Jun 03, 2003 10:10 am   Post subject: (No subject)

Here is the code ->its very long though

code:

import GUI in "%oot/lib/GUI"

var I_operationButton : array 1 .. 4 of int
var S_textForOperationButton : array 1 .. 4 of string (1)
var I_getValueButton : array 1 .. 2 of int
var S_textForGetValueButton : array 1 .. 2 of string
var I_fractionCalculatorWindow, I_inputWindow : int
var I_numeratorTextField, I_denominatorTextField : int

class Fraction
    import I_fractionCalculatorWindow, I_inputWindow, I_numeratorTextField,
        I_denominatorTextField, GUI
    export Numerator, Denominator, Get, Set, Put, Add, Subtract, Multiply,
        Divide
    var I_numeratorOfFraction, I_denominatorOfFraction : int

    function GCD (I_m, I_n : int) : int

        % This function calculates the GCD of the two numbers
        % This function requires the two integers.
        % The function sends back an integer value of GCD.

        var I_a, I_b, I_t : int
        I_a := I_m
        I_b := I_n
        loop
            I_t := I_a mod I_b
            exit when I_t = 0
            I_a := I_b
            I_b := I_t
        end loop
        result I_b
    end GCD

    function LCM (I_m, I_n : int) : int
        result (I_m * I_n) div GCD (I_m, I_n)
    end LCM

    procedure Reduce
        var I_greatestCommonDenominator : int := GCD (I_numeratorOfFraction,
            I_denominatorOfFraction)
        I_numeratorOfFraction := I_numeratorOfFraction div
            I_greatestCommonDenominator
        I_denominatorOfFraction := I_denominatorOfFraction div
            I_greatestCommonDenominator
    end Reduce

    function Numerator : int
        result I_numeratorOfFraction
    end Numerator

    function Denominator : int
        result I_denominatorOfFraction
    end Denominator

    procedure Edit (text : string)
        if strintok (GUI.GetText (I_numeratorTextField)) = false then
            GUI.SetText (I_numeratorTextField, "")
        elsif strintok (GUI.GetText (I_denominatorTextField)) = false then
            GUI.SetText (I_denominatorTextField, "")
        else
            put "OK"
        end if
    end Edit

    procedure Get
        var x : ^Fraction
        I_inputWindow := Window.Open ("graphics:300;100")
        I_numeratorTextField := GUI.CreateTextFieldFull (100, 75, 30, "",
            Edit, GUI.EXDENT, Font.New ("Arial:14"), 0)
        I_denominatorTextField := GUI.CreateTextFieldFull (100, 50, 30, "",
            Edit, GUI.EXDENT, Font.New ("Arial:14"), 0)
    end Get

    procedure Set
        loop
            exit when I_denominatorOfFraction not= 0
            Get
        end loop
        Reduce
    end Set

    procedure Put (x, y : int)
        Font.Draw ("                                     ", x, y,
            Font.New ("Arial:14"), white)
        if I_numeratorOfFraction = 0 then
            Font.Draw ("0", x, y, Font.New ("Arial:14"), blue)
        elsif abs (I_numeratorOfFraction) < I_denominatorOfFraction then
            Font.Draw (intstr (I_numeratorOfFraction) + "/" +
                intstr (I_denominatorOfFraction), x, y,
                Font.New ("Arial:14"), blue)
        elsif I_denominatorOfFraction = 0 then
            Font.Draw ("undefined", x, y, Font.New ("Arial:14"), blue)
        elsif I_numeratorOfFraction mod I_denominatorOfFraction = 0 then
            Font.Draw (intstr (I_numeratorOfFraction div
                I_denominatorOfFraction), x, y, Font.New ("Arial:14"), blue)
        else
            Font.Draw (intstr (I_numeratorOfFraction div
                I_denominatorOfFraction), x, y, Font.New ("Arial:14"), blue)
            Font.Draw (intstr (abs (I_numeratorOfFraction
                - (I_numeratorOfFraction div I_denominatorOfFraction) *
                I_denominatorOfFraction)) + "/" +
                intstr (abs (I_denominatorOfFraction)), x + 25, y,
                Font.New ("Arial:14"), blue)
        end if
    end Put

    procedure Add (I_numeratorOfFirstFraction,
            I_denominatorOfFirstFraction,
            I_numeratorOfSecondFraction, I_denominatorOfSecondFraction :
            int)
        var I_equivalentNumeratorOfSecondFraction,
            I_equivalentNumeratorOfFirstFraction : int
        var I_lowestCommonDenominatorOfBothFractions : int :=
            LCM (I_denominatorOfFirstFraction,
            I_denominatorOfSecondFraction)
        I_equivalentNumeratorOfSecondFraction :=
            I_numeratorOfSecondFraction
            * (I_lowestCommonDenominatorOfBothFractions div
            I_denominatorOfSecondFraction)
        I_equivalentNumeratorOfFirstFraction :=
            I_numeratorOfFirstFraction
            * (I_lowestCommonDenominatorOfBothFractions div
            I_denominatorOfFirstFraction)
        I_numeratorOfFraction := I_equivalentNumeratorOfFirstFraction +
            I_equivalentNumeratorOfSecondFraction
        I_denominatorOfFraction :=
            I_lowestCommonDenominatorOfBothFractions
        Reduce
    end Add

    procedure Subtract (I_numeratorOfFirstFraction,
            I_denominatorOfFirstFraction, I_numeratorOfSecondFraction,
            I_denominatorOfSecondFraction : int)
        var I_equivalentNumeratorOfSecondFraction,
            I_equivalentNumeratorOfFirstFraction : int
        var I_lowestCommonDenominatorOfBothFractions : int :=
            LCM (I_denominatorOfSecondFraction,
            I_denominatorOfFirstFraction)
        I_equivalentNumeratorOfSecondFraction := ( -
            I_numeratorOfSecondFraction)
            * (I_lowestCommonDenominatorOfBothFractions div
            I_denominatorOfSecondFraction)
        I_equivalentNumeratorOfFirstFraction :=
            I_numeratorOfFirstFraction
            * (I_lowestCommonDenominatorOfBothFractions div
            I_denominatorOfFirstFraction)
        I_numeratorOfFraction := I_equivalentNumeratorOfSecondFraction +
            I_equivalentNumeratorOfFirstFraction
        I_denominatorOfFraction :=
            I_lowestCommonDenominatorOfBothFractions
        Reduce
    end Subtract

    procedure Multiply (I_numeratorOfFirstFraction,
            I_denominatorOfFirstFraction, I_numeratorOfSecondFraction,
            I_denominatorOfSecondFraction : int)
        I_numeratorOfFraction := I_numeratorOfSecondFraction *
            I_numeratorOfFirstFraction
        I_denominatorOfFraction := I_denominatorOfSecondFraction *
            I_denominatorOfFirstFraction
        Reduce
    end Multiply

    procedure Divide (I_numeratorOfFirstFraction,
            I_denominatorOfFirstFraction, I_numeratorOfSecondFraction,
            I_denominatorOfSecondFraction : int)
        I_numeratorOfFraction := I_numeratorOfFirstFraction *
            I_denominatorOfSecondFraction
        I_denominatorOfFraction := I_denominatorOfFirstFraction *
            I_numeratorOfSecondFraction
        Reduce
    end Divide
end Fraction

var C_firstFraction, C_secondFraction, C_thirdFraction : ^Fraction
new C_firstFraction
new C_secondFraction
new C_thirdFraction

procedure Operate
    GUI.Refresh
    locate (10, 12)
    put "                                               "
    locate (10, 12)
    C_firstFraction -> Put (25, 25)
    if GUI.GetEventWidgetID = I_operationButton (1) then
        C_thirdFraction -> Add (C_firstFraction -> Numerator,
            C_firstFraction ->
            Denominator, C_secondFraction -> Numerator, C_secondFraction
            ->
            Denominator)
        put " + " ..
    elsif GUI.GetEventWidgetID = I_operationButton (2) then
        C_thirdFraction -> Subtract (C_firstFraction -> Numerator,
            C_firstFraction ->
            Denominator, C_secondFraction ->
            Numerator, C_secondFraction -> Denominator)
        put " - " ..
    elsif GUI.GetEventWidgetID = I_operationButton (3) then
        C_thirdFraction -> Multiply (C_firstFraction -> Numerator,
            C_firstFraction ->
            Denominator, C_secondFraction ->
            Numerator, C_secondFraction -> Denominator)
        put " x " ..
    elsif GUI.GetEventWidgetID = I_operationButton (4) then
        C_thirdFraction -> Divide (C_firstFraction -> Numerator,
            C_firstFraction ->
            Denominator, C_secondFraction ->
            Numerator, C_secondFraction -> Denominator)
        put " ", chr (246), " " ..
    end if
    C_secondFraction -> Put (35, 25)
    put " = " ..
    C_thirdFraction -> Put (55, 25)
end Operate

procedure Get
    if GUI.GetEventWidgetID = I_getValueButton (1) then
        C_firstFraction -> Get
        C_firstFraction -> Set
        Window.SetActive (I_fractionCalculatorWindow)
        locatexy (1, maxy - 25)
        put "            "
        Font.Draw ("A :", 1, maxy - 25, Font.New ("Arial:14"), blue)
        C_firstFraction -> Put (25, maxy - 25)
        put ""
        GUI.Enable (I_getValueButton (2))
    elsif GUI.GetEventWidgetID = I_getValueButton (2) then
        C_secondFraction -> Get
        C_secondFraction -> Set
        Window.SetActive (I_fractionCalculatorWindow)
        locate (2, 1)
        put "                   "
        locate (2, 1)
        put "B: " ..
        C_secondFraction -> Put (25, 25)
        put ""
        for I_operationButtonNumber : 1 .. 4
            GUI.Enable (I_operationButton (I_operationButtonNumber))
        end for
    end if
end Get

var a : ^Fraction
new a

S_textForOperationButton (1) := "+"
S_textForOperationButton (2) := "-"
S_textForOperationButton (3) := "*"
S_textForOperationButton (4) := "/"
S_textForGetValueButton (1) := "a"
S_textForGetValueButton (2) := "b"
I_fractionCalculatorWindow :=
    Window.Open ("title:Fraction Calculator,screen:25;40")

for I_operationButtonNumber : 1 .. 4
    I_operationButton (I_operationButtonNumber) :=
        GUI.CreateButtonFull (I_operationButtonNumber * 65, 100, 0,
        S_textForOperationButton (I_operationButtonNumber), Operate, 0,
        S_textForOperationButton (I_operationButtonNumber), false)
    GUI.Disable (I_operationButton (I_operationButtonNumber))
end for

for I_getValueButtonNumber : 1 .. 2
    I_getValueButton (I_getValueButtonNumber) :=
        GUI.CreateButtonFull (I_getValueButtonNumber * 100, 50, 0,
        "Get " +
        S_textForGetValueButton (I_getValueButtonNumber), Get, 0,
        S_textForGetValueButton (I_getValueButtonNumber),
        false)
end for
GUI.Hide (I_numeratorTextField)
GUI.Hide (I_denominatorTextField)
a -> Get
loop
    exit when GUI.ProcessEvent
end loop

tum_twish




PostPosted: Tue Jun 03, 2003 10:12 am   Post subject: (No subject)

I checked the GUI parameters and I use Edit for the ActionProcedure
Tony




PostPosted: Tue Jun 03, 2003 10:13 am   Post subject: (No subject)

what I Find wrong with this program is that you call procedure Edit, but it requires a string parameter (text:string) passed to it.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
tum_twish




PostPosted: Tue Jun 03, 2003 10:16 am   Post subject: (No subject)

but its for a text field
gui automatically sends the text to the Edit procedure
Andy




PostPosted: Tue Jun 03, 2003 2:13 pm   Post subject: (No subject)

ya, if you are gona call a procedure used by text field you have to have the text as the prameter
procedure edit (text:string)
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  [ 8 Posts ]
Jump to:   


Style:  
Search: