
-----------------------------------
jamonathin
Mon Jan 23, 2006 11:45 am

GUI Text Field Help
-----------------------------------
Hey all, for some reason i cant get my textfields to work right.  I set up an example program of what is wrong.

There are 2 textfields, the user puts a value into one of them, and hits the button, which is supposed to double the inputed value and put it into the other text field.   Only this code doesn't work :?

import GUI

var xValue, yValue : real := 1
var box1, box2, button : int

procedure fieldEntered1 (text : string)
    GUI.SetSelection (box1, 0, 0)
    GUI.SetActive (box1)
end fieldEntered1

procedure fieldEntered2 (text : string)
    GUI.SetSelection (box2, 0, 0)
    GUI.SetActive (box2)
end fieldEntered2

proc redoFields
    box1 := GUI.CreateTextField (100, 100, 100, intstr (round (xValue)), fieldEntered1)
    box2 := GUI.CreateTextField (100, 200, 100, intstr (round (yValue)), fieldEntered2)
end redoFields

procedure buttonHit
    if strint (GUI.GetText (box1)) = 1 then
        xValue := yValue * 2
    elsif strint (GUI.GetText (box2)) = 1 then
        yValue := xValue / 2
    end if
    GUI.Dispose (box1)
    GUI.Dispose (box2)
    redoFields
end buttonHit

redoFields
button := GUI.CreateButton (300, 100, 0, "button", buttonHit)

loop
    exit when GUI.ProcessEvent
end loop


any help is appreciated

-----------------------------------
Clayton
Tue Jan 24, 2006 2:13 am


-----------------------------------
i got the code to work according to what you said you wanted it to do so here it is hope it helps

import GUI

var xValue, yValue : int := 1
var box1, box2, button : int

procedure fieldEntered1 (text : string)
    GUI.SetSelection (box1, 0, 0)
    GUI.SetActive (box1)
end fieldEntered1

procedure fieldEntered2 (text : string)
    GUI.SetSelection (box2, 0, 0)
    GUI.SetActive (box2)
end fieldEntered2
proc fields
    box1 := GUI.CreateTextField (100, 100, 100, intstr (round (xValue)), fieldEntered1)
    box2 := GUI.CreateTextField (100, 200, 100, intstr (round (xValue * 2)), fieldEntered2)
end fields
procedure buttonHit
    xValue := strint (GUI.GetText (box1))
    GUI.Dispose (box1)
    GUI.Dispose (box2)
    fields
end buttonHit
fields
button := GUI.CreateButton (300, 100, 0, "button", buttonHit)

loop
    exit when GUI.ProcessEvent
end loop

there you go

-----------------------------------
jamonathin
Tue Jan 24, 2006 2:29 pm


-----------------------------------
Ok that works, but my dilema is, what if I enter the information in the top field?  Lets look at it this way, its a way to convert money, lets say canadian to US.  Now, what if i have $20 US, and i want this button to convert it into canadian, or what if i have $15 CDN and i want the button to convert it to american.

Where the top field would represent american, and the bottom field would represent canadian. :?

-----------------------------------
jamonathin
Wed Jan 25, 2006 12:21 pm


-----------------------------------
I have it now, so thanks n e ways for ur help, anyone wonderin how, heres the code . .

import GUI

var xValue, yValue, xOld, yOld : int := 0
var box1, box2, button : int

procedure fieldEntered1 (text : string)
    GUI.SetSelection (box1, 0, 0)
    GUI.SetActive (box1)
end fieldEntered1

procedure fieldEntered2 (text : string)
    GUI.SetSelection (box2, 0, 0)
    GUI.SetActive (box2)
end fieldEntered2
proc fields
    box1 := GUI.CreateTextField (100, 100, 100, intstr (round (xValue)), fieldEntered1)
    box2 := GUI.CreateTextField (100, 200, 100, intstr (round (yValue)), fieldEntered2)
end fields
procedure buttonHit
    xValue := strint (GUI.GetText (box1))
    yValue := strint (GUI.GetText (box2))
    if xValue = xOld then
        xValue := round (yValue / 2)
    elsif yValue = yOld then
        yValue := xValue * 2
    else
        xValue := 0
        yValue := 0
    end if
    xOld := xValue
    yOld := yValue
    GUI.Dispose (box1)
    GUI.Dispose (box2)
    fields
end buttonHit
fields
button := GUI.CreateButton (300, 100, 0, "button", buttonHit)

loop
    exit when GUI.ProcessEvent
end loop


-----------------------------------
Clayton
Wed Jan 25, 2006 3:26 pm


-----------------------------------
glad you fixed that up, i didnt know that you wanted to be able to input into both fields but kool gj
