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

Username:   Password: 
 RegisterRegister   
 help with my base converter
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Nizzem




PostPosted: Wed Jan 25, 2006 4:16 pm   Post subject: help with my base converter

This is my poorly made prog:

code:
% The "GUI.CreateTextFieldFull" program
import GUI
View.Set ("graphics:200;100,nobuttonbar")

var TextField : int  % The Text Field IDs.

var answer,answer3,answer5 : string
var answer2,answer4,answer6 : int
 var addressLabel := GUI.CreateLabelFull (45, 40, "Base_?:", 0, 0,
       GUI.RIGHT, 0)
  procedure AddressEntered (text : string)
    GUI.SetSelection (TextField, 0, 0)
    GUI.Quit
end AddressEntered 



proc base10

cls
    GUI.SetBackgroundColor (gray)

GUI.Refresh

    var convert := GUI.CreateButton (52, 5, 100, "Convert", GUI.Quit)

    TextField := GUI.CreateTextFieldFull (50, 40, 100, "",
        AddressEntered, GUI.INDENT, 0, 0)

  GUI.SetLabel (addressLabel, "Base_10")
     
    loop
        exit when GUI.ProcessEvent
    end loop

    GUI.Dispose (convert)

    answer := GUI.GetText (TextField)
    colorback (gray)
    Text.Locate (maxrow - 1, 1)
    put "Base_2: ", intstr (strint (answer), 0, 2)
    put "Base_16: ", intstr (strint (answer), 0, 16)
   
end base10

proc base16

    GUI.SetBackgroundColor (gray)

GUI.Refresh
    var convert := GUI.CreateButton (52, 5, 100, "Convert", GUI.Quit)

    TextField := GUI.CreateTextFieldFull (50, 40, 100, "",
        AddressEntered, GUI.INDENT, 0, 0)

  GUI.SetLabel (addressLabel, "Base_16") 
  loop
        exit when GUI.ProcessEvent
    end loop
GUI.Dispose (addressLabel)
   
    answer3 := GUI.GetText (TextField)
    colorback (gray)
    Text.Locate (maxrow - 1, 1)
    answer4 := strint (answer3, 16)

    put "Base_10: ", answer4
    put "Base_2: ", intstr (answer4, 0, 2)
   
end base16

proc base2

cls
GUI.SetBackgroundColor (gray)

GUI.Refresh
    var convert := GUI.CreateButton (52, 5, 100, "Convert", GUI.Quit)

    TextField := GUI.CreateTextFieldFull (50, 40, 100, "",
        AddressEntered, GUI.INDENT, 0, 0)

   GUI.SetLabel (addressLabel, "Base_2")
 
    loop
        exit when GUI.ProcessEvent
    end loop

   
    answer5 := GUI.GetText (TextField)
    colorback (gray)
    Text.Locate (maxrow - 1, 1)
    answer6 := strint (answer5,2)

    put "Base_10: ", answer6
    put "Base_16: ", intstr (answer6,0,16)
end base2
GUI.Refresh

var binary : int := GUI.CreateButtonFull (1, 75, 0, "Binary",
            base2, 0, '^D', true)
var decimal : int := GUI.CreateButtonFull (72, 75, 0, "Decimal",
            base10, 0, '^D', true)
var hex : int := GUI.CreateButtonFull (150, 75, 0, "Hex",
            base16, 0, '^D', true)




  loop

        exit when GUI.ProcessEvent
    end loop

Right now I want to add an input checker to it. So that when entering a binary number if the number isn't 1 or 0 it would highlight the number and give you the opportunity to change it. As far as I understand the code for that should look something like this:
code:

     procedure CheckInput (s : string)
            for i : 1 .. length (s)
                if (s (i) < '0' or '1' < s (i)) and s (i) not= ' ' then
                    GUI.SetSelection (TextField, i, i + 1)
                    return
                end if
            end for
            GUI.Quit
        end CheckInput

But I am unable to successfully intergrade it into my program. If anyone could help me it would be appreciated.
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: