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

Username:   Password: 
 RegisterRegister   
 Gui button conversion help... (code complete though)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chrispaks




PostPosted: Wed May 25, 2005 4:31 pm   Post subject: Gui button conversion help... (code complete though)

The gradient button isnt working, anyone know why/ how to fix it?
NOTE: Radians work fine...

(BTW for those of you not good at math, the conversion follows

Deg to Rad ---> # of degrees * pi / 180
Deg to Grad ---> # of degrees * 100 / 90

code:
% The "Convert" Program
% This creates some widgets and does alot with them.
import GUI in "%oot/lib/GUI"

View.Set ("graphics:680;460,nobuttonbar")
Window.Set (defWinID, "title:Degrees, Radians and Gradients!")

var degreesTextField, radiansTextField, gradientsTextField, degreesTextField_G, GradientsTextField, GradientsTextField_D : int

const pi := 3.1415926535897932384626433832795
const grad := 1.1111111111111111111111111111111

%DEGREES TO RADIANS
%------------------------------------------------------------
%------------------------------------------------------------
proc DegreesToRadians
    var degrees : string := GUI.GetText (degreesTextField)
    if strrealok (degrees) then
        var radians : real := (strreal (degrees) * pi / 180)
        GUI.SetText (radiansTextField, realstr (radians, 1))
    end if
end DegreesToRadians

proc DegreesToRadians1 (dummy : string)
    DegreesToRadians
end DegreesToRadians1



%RADIANS TO DEGREES
%------------------------------------------------------------
%------------------------------------------------------------
proc RadiansToDegrees
    var radians : string := GUI.GetText (radiansTextField)
    if strrealok (radians) then
        var degrees : real := ((strreal (radians)) * 180 / pi)
        GUI.SetText (degreesTextField, realstr (degrees, 1))
    end if
end RadiansToDegrees

proc RadiansToDegrees1 (dummy : string)
    RadiansToDegrees
end RadiansToDegrees1




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%DEGREES TO RADIANS
%------------------------------------------------------------
%------------------------------------------------------------
proc DegreesToGradients
    var degrees1 : string := GUI.GetText (degreesTextField_G)
    if strrealok (degrees1) then
        var gradients : real := (strreal (degrees1) * 100 / 90)
        GUI.SetText (gradientsTextField, realstr (gradients, 1))
    end if
end DegreesToGradients

proc DegreesToGradients1 (dummy : string)
    DegreesToGradients
end DegreesToGradients1



%RADIANS TO DEGREES
%------------------------------------------------------------
%------------------------------------------------------------
proc GradientsToDegrees
    var gradients : string := GUI.GetText (GradientsTextField_D)
    if strrealok (gradients) then
        var degrees1 : real := ((strreal (gradients)) * 90 / 100)
        GUI.SetText (degreesTextField, realstr (degrees1, 1))
    end if
end GradientsToDegrees

proc GradientsToDegrees1 (dummy : string)
    GradientsToDegrees
end GradientsToDegrees1




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




%--------------------------------------------------------------
%--------------------------------------------------------------
%--------------------------------------------------------------
%------------------------- Seperation -------------------------
%--------------------------------------------------------------
%--------------------------------------------------------------
%--------------------------------------------------------------


%Textfield for degrees reading
degreesTextField := GUI.CreateTextFieldFull (15, 330, 75, "",
    DegreesToRadians1, GUI.INDENT, 0, 0)

%Create label for degrees field
var d1 : real := GUI.CreateLabelFull (25, 335 +
    GUI.GetHeight (degreesTextField),
    "Degrees", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the radians reading
radiansTextField := GUI.CreateTextFieldFull (215, 330, 75, "",
    RadiansToDegrees1, GUI.INDENT, 0, 0)

%Create a label for the radians field
var d2 : real := GUI.CreateLabelFull (225, 335 +
    GUI.GetHeight (degreesTextField),
    "Radians", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the fahrenheight reading to degrees
var ToRadians := GUI.CreateButton (105, 340, 95, "Convert ->",
    DegreesToRadians)

%Create a text field for the degrees reading to radians
var ToDegrees := GUI.CreateButton (105, 310, 95, "<- Convert",
    RadiansToDegrees)

%------------------------------------------------------------
%------------------------------------------------------------



%Textfield for Degrees/Gradients reading
degreesTextField_G := GUI.CreateTextFieldFull (15, 230, 75, "",
    DegreesToGradients1, GUI.INDENT, 0, 0)

%Create label for degrees field
var e1 : real := GUI.CreateLabelFull (25, 235 +
    GUI.GetHeight (degreesTextField),
    "Degrees", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the gradients reading
GradientsTextField_D := GUI.CreateTextFieldFull (215, 230, 75, "",
    DegreesToGradients1, GUI.INDENT, 0, 0)

%Create a label for the gradients field
var e2 : real := GUI.CreateLabelFull (225, 235 +
    GUI.GetHeight (degreesTextField),
    "Gradients", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the fahrenheight reading to degrees
var ToGradients_D := GUI.CreateButton (105, 240, 95, "Convert ->",
    DegreesToGradients)

%Create a text field for the degrees reading to gradients
var ToDegrees_G := GUI.CreateButton (105, 210, 95, "<- Convert",
    GradientsToDegrees)

%------------------------------------------------------------
%------------------------------------------------------------


GUI.SetBackgroundColour (grey)

loop
    exit when GUI.ProcessEvent
end loop

Sponsor
Sponsor
Sponsor
sponsor
StarGateSG-1




PostPosted: Wed May 25, 2005 5:00 pm   Post subject: (No subject)

Your code is great and all but before you, fix that problem you need to test the rest of program.

When you input gradient it comes out in the wrong degree box.

The second one is your commenting, I like the style but, I got lost reading some of it you seem to have a in the wrong places.

As for your problem check up were you grad the data form for conversion.

Finally add a quit button.
Delos




PostPosted: Wed May 25, 2005 5:41 pm   Post subject: (No subject)

Also, for Pi, you might want to use Math.PI (or was it Math.Pi?) instead of a hardcoded value. I'm not sure which is more accurate, the one you've got or Math.Pi.
chrispaks




PostPosted: Wed May 25, 2005 8:20 pm   Post subject: (No subject)

I bascically got as far as the end
Now im mad...

The Grad to Rad box inverse on itself Rolling Eyes

code:
% The "Convert" Program
% This creates some widgets and does alot with them!

import GUI in "%oot/lib/GUI"

View.Set ("graphics:680;460,nobuttonbar,title:Degrees and Radians and Gradients!")
Window.Set (defWinID, "title:Degrees and Radians and Gradients!")

var degreesTextField, radiansTextField, gradientsTextField, degreesTextField_G, GradientsTextField, GradientsTextField_D : int
var RadiansTextField_G, gradientsTextField_G, GradientsTextField_R, gradientsTextField_R : int

const pi := 3.1415926535
const grad := 1.1111111111

%DEGREES TO RADIANS
%------------------------------------------------------------
%------------------------------------------------------------
proc DegreesToRadians
    var degrees : string := GUI.GetText (degreesTextField)
    if strrealok (degrees) then
        var radians : real := (strreal (degrees) * pi / 180)
        GUI.SetText (radiansTextField, realstr (radians, 1))
    end if
end DegreesToRadians

proc DegreesToRadians1 (dummy : string)
    DegreesToRadians
end DegreesToRadians1

%RADIANS TO DEGREES
%------------------------------------------------------------
%------------------------------------------------------------
proc RadiansToDegrees
    var radians : string := GUI.GetText (radiansTextField)
    if strrealok (radians) then
        var degrees : real := ((strreal (radians)) * 180 / pi)
        GUI.SetText (degreesTextField, realstr (degrees, 1))
    end if
end RadiansToDegrees

proc RadiansToDegrees1 (dummy2 : string)
    RadiansToDegrees
end RadiansToDegrees1

%DEGREES TO GRADIENTS
%------------------------------------------------------------
%------------------------------------------------------------
proc DegreesToGradients
    var degrees1 : string := GUI.GetText (degreesTextField_G)
    if strrealok (degrees1) then
        var gradients := (strreal (degrees1) * 100 / 90)
        GUI.SetText (GradientsTextField_D, realstr (gradients, 1))
    end if
end DegreesToGradients

proc DegreesToGradients1 (dummy3 : string)
    DegreesToGradients
end DegreesToGradients1

%GRADIENTS TO DEGREES
%------------------------------------------------------------
%------------------------------------------------------------
proc GradientsToDegrees
    var gradients : string := GUI.GetText (GradientsTextField_D)
    if strrealok (gradients) then
        var degrees1 : real := ((strreal (gradients)) * 90 / 100)
        GUI.SetText (degreesTextField_G, realstr (degrees1, 1))
    end if
end GradientsToDegrees

proc GradientsToDegrees1 (dummy4 : string)
    GradientsToDegrees
end GradientsToDegrees1

%RADIANS TO GRADIENTS
%------------------------------------------------------------
%------------------------------------------------------------
proc RadiansToGradients
    var Radians : string := GUI.GetText (RadiansTextField_G)
    if strrealok (Radians) then
        var gradients2 : real := ((strreal (Radians) * 180 / pi) * 100 / 90)
        GUI.SetText (RadiansTextField_G, realstr (gradients2, 1))
    end if
end RadiansToGradients

proc RadiansToGradients1 (dummy5 : string)
    RadiansToGradients
end RadiansToGradients1

%GRADIENTS TO RADIANS
%------------------------------------------------------------
%------------------------------------------------------------
proc GradientsToRadians
    var gradients4 : string := GUI.GetText (GradientsTextField_R)
    if strrealok (gradients4) then
        var radians2 : real := (((strreal (gradients4)) * 90 / 100) * pi / 180)
        GUI.SetText (GradientsTextField_R, realstr (radians2, 1))
    end if
end GradientsToRadians

proc GradientsToRadians1 (dummy6 : string)
    GradientsToRadians
end GradientsToRadians1



%****************************************************************
%************************** Seperation **************************
%****************************************************************



%----------------------------------------------------------------
%------------------------ Radian Section ------------------------
%----------------------------------------------------------------

%Textfield for degrees reading
degreesTextField := GUI.CreateTextFieldFull (15, 330, 75, "",
    DegreesToRadians1, GUI.INDENT, 0, 0)

%Create label for degrees field
var da1 : real := GUI.CreateLabelFull (25, 335 +
    GUI.GetHeight (degreesTextField),
    "Degrees", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the radians reading
radiansTextField := GUI.CreateTextFieldFull (215, 330, 75, "",
    RadiansToDegrees1, GUI.INDENT, 0, 0)

%Create a label for the radians field
var da2 : real := GUI.CreateLabelFull (225, 335 +
    GUI.GetHeight (degreesTextField),
    "Radians", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the fahrenheight reading to degrees
var ToRadians := GUI.CreateButton (105, 340, 95, "Convert ->",
    DegreesToRadians)

%Create a text field for the degrees reading to radians
var ToDegrees := GUI.CreateButton (105, 310, 95, "<- Convert",
    RadiansToDegrees)

%--------------------------------------------------------------
%------------------- Gradient Section -------------------------
%--------------------------------------------------------------

%Textfield for Degrees/Gradients reading
degreesTextField_G := GUI.CreateTextFieldFull (15, 230, 75, "",
    DegreesToGradients1, GUI.INDENT, 0, 0)

%Create label for degrees field
var ea1 : real := GUI.CreateLabelFull (25, 235 +
    GUI.GetHeight (degreesTextField),
    "Degrees", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the gradients reading
GradientsTextField_D := GUI.CreateTextFieldFull (215, 230, 75, "",
    DegreesToGradients1, GUI.INDENT, 0, 0)

%Create a label for the gradients field
var ea2 : real := GUI.CreateLabelFull (225, 235 +
    GUI.GetHeight (degreesTextField),
    "Gradients", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the fahrenheight reading to degrees
var ToGradients_D := GUI.CreateButton (105, 240, 95, "Convert ->",
    DegreesToGradients)

%Create a text field for the degrees reading to gradients
var ToDegrees_G := GUI.CreateButton (105, 210, 95, "<- Convert",
    GradientsToDegrees)

%----------------------------------------------------------------
%----------------------- Rad/Grad Section -----------------------
%----------------------------------------------------------------

%Textfield for Radian/Gradients reading
RadiansTextField_G := GUI.CreateTextFieldFull (15, 130, 75, "",
    RadiansToGradients1, GUI.INDENT, 0, 0)

%Create label for degrees field
var fa1 : real := GUI.CreateLabelFull (25, 135 +
    GUI.GetHeight (degreesTextField),
    "Radians", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the gradients reading
GradientsTextField_R := GUI.CreateTextFieldFull (215, 130, 75, "",
    GradientsToRadians1, GUI.INDENT, 0, 0)

%Create a label for the gradients field
var fa2 : real := GUI.CreateLabelFull (225, 135 +
    GUI.GetHeight (degreesTextField),
    "Gradients", 50, 0, GUI.CENTER, 0)

%------------------------------------------------------------

%Create a text field for the fahrenheight reading to degrees
var ToGradients_R := GUI.CreateButton (105, 140, 95, "Convert ->",
    GradientsToRadians)

%Create a text field for the degrees reading to gradients
var ToRadians_G := GUI.CreateButton (105, 110, 95, "<- Convert",
    RadiansToGradients)

%----------------------------------------------------------------
%------------------------ Final touches! ------------------------
%----------------------------------------------------------------

GUI.SetBackgroundColour (grey)

%Text label at the top (instruction)
var toptext1 : real := GUI.CreateLabelFull (150, 400 +
    GUI.GetHeight (degreesTextField),
    "This converts degrees, radians, and gradients, into each other!", 50, 0, GUI.CENTER, 0)

loop
    exit when GUI.ProcessEvent
end loop


Dont worry about the exit button its part of a huge ass procedure later on Wink
StarGateSG-1




PostPosted: Wed May 25, 2005 9:21 pm   Post subject: (No subject)

Forst things first you need the quit button so the Gui files don't pop-up even if it isn't wbnat you want right now, just make one. More to come let me see in to this.

Edit:
I have no clue in must be somehting with your map, I suggest you write a simple program that takes a value and you can use those formula by themselves. It will eb a good challenge for you.

By the way I added a temp quit button, for you. Add it for now then the Gui wndow would pop up.

Quote:
%Quit Button
var Quit := GUI.CreateButton (maxx - 100, maxy - 100, 95, "Quit",
GUI.Quit)
loop
exit when GUI.ProcessEvent
end loop

%Gets rid of the window
View.Set ("invisible")


Just add this to the ned of your program, then it will eb there as a temperary button.
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  [ 5 Posts ]
Jump to:   


Style:  
Search: