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

Username:   Password: 
 RegisterRegister   
 get statements screwing up my program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shlitiouse




PostPosted: Sun Apr 17, 2005 5:35 pm   Post subject: get statements screwing up my program

Alright, I'm working on a painting program. One of the features is that it has boxes on the bottom where the user can click on the box and input a width value or height value. As well as a writting option where the user can input a word and have that word printed on the painting area when they click their mouse. The only problem is, if the user doesn't enter anything and just hits "enter" then the program creates a blank line in that space and moves it down to the next line, continuing to ask the user to enter a value. Does anyone know how I can stop the program from doing this and to just exit the get statement, or to stop it from shifting down a line? If you need an example of the coding I'm using for this, I'll be glad to provide it.
Sponsor
Sponsor
Sponsor
sponsor
Vertico




PostPosted: Sun Apr 17, 2005 5:56 pm   Post subject: (No subject)

im not sure if this is what u mean.

code:
if answer = " " then
answer:= ""
end if



it would help if there was some code 2 understand what u are talking about
Cervantes




PostPosted: Sun Apr 17, 2005 6:17 pm   Post subject: (No subject)

I don't think it can be done. the get command is not very flexible. You might try using a loop to getch several keystrokes to form your input string yourself.

code:

var key : string (1)
var input := ""

loop
    getch (key)
    exit when ord (key) = 10 %enter
    input += key
    locate (1, 1)
    put input
end loop


This isn't error proofed though. If we want an integer for width:
code:

var key : string (1)
var input := ""
var width : int

loop
    getch (key)
    exit when ord (key) = 10 %enter
    if strintok (input + key) then
        input += key
    end if
    locate (1, 1)
    put input
end loop
if strintok (input) then
    width := strint (input)
else
    width := -1     %error!  no value.
end if
put width


Then it might be useful to make this into a procedure.
code:

var width : int

proc getInteger (var variable : int, outputRow, outputCol : int)
    var key : string (1)
    var input := ""
    loop
        getch (key)
        exit when ord (key) = 10 %enter
        if strintok (input + key) then
            input += key
        end if
        locate (outputRow, outputCol)
        put input
    end loop
    if strintok (input) then
        variable := strint (input)
    end if
end getInteger
getInteger (width, 10, 10)


You can also do things like deleting characters:
code:

var width : int

proc getInteger (var variable : int, outputRow, outputCol : int)
    var key : string (1)
    var input := ""
    loop
        getch (key)
        exit when ord (key) = 10 %enter
        if ord (key) = 8 and input ~= "" then %backspace
            input := input (1 .. * -1)
        elsif strintok (input + key) then
            input += key
        end if
        locate (outputRow, outputCol)
        put input
    end loop
    if strintok (input) then
        variable := strint (input)
    end if
end getInteger
getInteger (width, 10, 10)

You could take this even further too, and make yourself your very own text box. I made a text box class that is almost completely functional without too much trouble.
Martin




PostPosted: Sun Apr 17, 2005 6:21 pm   Post subject: Re: get statements screwing up my program

shlitiouse wrote:
Alright, I'm working on a painting program. One of the features is that it has boxes on the bottom where the user can click on the box and input a width value or height value. As well as a writting option where the user can input a word and have that word printed on the painting area when they click their mouse. The only problem is, if the user doesn't enter anything and just hits "enter" then the program creates a blank line in that space and moves it down to the next line, continuing to ask the user to enter a value. Does anyone know how I can stop the program from doing this and to just exit the get statement, or to stop it from shifting down a line? If you need an example of the coding I'm using for this, I'll be glad to provide it.


The best thing that you could do would be to use getch instead of get (along with noecho) and make your own get function. It would look something like this (in pseudocode)

code:
View.Set ("noecho") % so nothing shows up on the screen when people type

var ch : string (1)
var line : string := ""
var goodchars : string := "abc...ABC...123..." %a list of all of the valid characters
loop
     getch (ch)
     if (ch = enter) then
         exit
     elsif (ch = backspace) and (length(line) > 0) then
         line = line (1 .. * -1) % it's been a while, this probably isn't right
     elsif (index (goodchars, ch) > 0) then
         line = line + ch
     end if
     locate (wherever)
     put line
end loop
c0bra54




PostPosted: Wed Apr 20, 2005 12:32 am   Post subject: (No subject)

or use the mouse to draw the box, such as

(sorry mad hwk need to get done, so only algorithm from me right now:P )

if mousebutton = 1 then

record the x and y into arrays, for safe keeping.. and you will eventually run out of oom.. but thats ok Razz...

and yeh just reord them, and then when button = 0 gain record the x and y, and this will give you the box.. how ever you could draw the lines for the outline as you drag ur mouse fairly without problem just use a cls View.Update and a bit of math Razz


but yeh, cause having the user enter data... it would work.. but also y not just have the text being entered at the bottom of the screen.. jsut a Q Razz...

if u've ever used AUTO cad.. do it like they do Razz .. the text i mean, sry i couldn't help more..
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: