get statements screwing up my program
Author |
Message |
shlitiouse
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Vertico
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Martin
![](http://www.compsci.ca/wiki/images/4/46/CanadianStickUp.jpg)
|
Posted: 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 |
|
|
|
|
|
![](images/spacer.gif) |
c0bra54
![](http://www.planetnintendo.com/ff1/unnedizzy.gif)
|
Posted: 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 ...
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
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 ...
if u've ever used AUTO cad.. do it like they do .. the text i mean, sry i couldn't help more.. |
|
|
|
|
![](images/spacer.gif) |
|
|