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

Username:   Password: 
 RegisterRegister   
 Textbox Assistance Required
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
l3eater




PostPosted: Fri Jan 08, 2010 11:20 pm   Post subject: Textbox Assistance Required

What is it you are trying to achieve?
Instead of using the put statement to output the answer, I want to use a Textbox, more for User Friendliness. Since when I use the put statement, it doesn't have boundaries, and would screw with the other buttons I have aligned with it.

Like, I creates an entire white line across where I have located the answer to appear.


What is the problem you are having?
The Textbox field doesn't accept variables with an int or real statement


Describe what you have tried to solve this problem
Using if statements within the Textbox.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


import GUI
setscreen ("graphics:1000,1650")

var TextFieldA : int
var TextBox : int

const FirstConversion : string := "The amount in US Dollars is $"

locate (6, 3)
put "Canadian to American"


% This starts a procedure which I've named CanToUsa. It allows Turing to convert
% any amount of money to the stated currency
proc CanToUsa
    var TextA : string := GUI.GetText (TextFieldA)
    if strrealok (TextA) then
        var num1 := strreal (TextA)
        var total : real
        % This gives the location of the answer
        locate (7, 25)
        total := num1 * 0.961879 % The exchange rate of Canadian to American
        for i : 0 .. 0
            GUI.ClearText (TextBox)
            GUI.AddText (TextBox, FirstConversion)
           % if total > 0 then
              %  put total
           % end if
            % GUI.AddLine (TextBox, total)
            % put total
        end for
        % put total : 0 : 3, "."
    end if
end CanToUsa

proc CanToUsa1 (dummy : string)
    CanToUsa
end CanToUsa1

TextFieldA := GUI.CreateTextFieldFull (15, 1525, 50, "", CanToUsa1, GUI.INDENT, 0, 0)

var button1 : int := GUI.CreateButton (100, 1525, 40, "Convert", CanToUsa)

TextBox := GUI.CreateTextBoxFull (190, 1505, 350, 55, 0, 0)


loop
    exit when GUI.ProcessEvent
end loop





Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Ktomislav




PostPosted: Sat Jan 09, 2010 12:21 pm   Post subject: Re: Textbox Assistance Required

GUI.AddText accepts only string so you have to convert your total: real variable to string.
To achieve this you can use a function called erealstr.
Copied from Turing Documentation.
erealstr (r : real, width, fractionWidth, exponentWidth : int) :string

So for you it would be something like this:
code:
var totalString: string
totalString := erealstr (total, 0, 2, 0)
GUI.AddLine (TextBox, totalString)


Hope this helps.
l3eater




PostPosted: Sat Jan 09, 2010 3:22 pm   Post subject: Re: Textbox Assistance Required

Thanks!

Though, the one you suggested wasn't the one I wanted. The one I wanted was realstr, which mostly keeps the total the same.

Thanks Again! Very Happy
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  [ 3 Posts ]
Jump to:   


Style:  
Search: