Qbasicnews.com
December 01, 2021, 11:55:39 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to make textbox?  (Read 5640 times)
-dezell-
New Member

Posts: 7



WWW
« on: September 19, 2004, 10:37:45 AM »

first of all...i apologise...this really isn't a newbie question...but since i'm a newbie...i think this is the right place for this post

i was curious...is there a possible way to do this?
i can't explain exactly, what i want(mostly because i don't speak english that well), so i'll try to show:

let's say i have a program code:
Code:

print"Hello! Answer to my questions"
input"What is your name?"; name$
input"How old are you?"; age$
print"Name: "; name$
print"Age: "; age$
      //here should be the textbox code..!!if u press ENTER, it counts the answer..


and then the program should look like this:
Code:

Hello! Answer to my questions
What is your name



_______________________
|______________________| //<<--this is where i could type


Code:

Hello! Answer to my questions
What is your name



_______________________
|dezell ______________| //<<--this is where i could type

Code:

Hello! Answer to my questions
What is your name
How old are you


_______________________
|2_____________________| //<<--this is where i could type

Code:

Hello! Answer to my questions
What is your name
How old are you
name dezell
age 2
_______________________
|______________________| //<<--this is where i could type


if somehing was not understandable, post here or send a private message...
thanks Smiley
Logged
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #1 on: September 19, 2004, 12:48:30 PM »

Well, you could do something like this:


[syntax="qbasic"]LOCATE 1, 1
PRINT "Hello! Answer to my questions"
PRINT "What is your name?"

LOCATE 7, 1
INPUT nam$
LOCATE 7, 1
PRINT "                             "  'Erase the text

LOCATE 3, 1
PRINT "How old are you?"

LOCATE 7, 1
INPUT age
LOCATE 7, 1
PRINT "                         "  'Erase the text

LOCATE 4, 1
PRINT "Name: "; nam$
PRINT "Age: "; age[/syntax]

I havent actually tested it, but it should work.
Logged
potato
Ancient QBer
****
Posts: 409



WWW
« Reply #2 on: September 19, 2004, 12:54:10 PM »

If you want a box made out of lines, you'll have to switch to a graphics mode (or make a crummy one using those extended ascii bars).
Logged

ammit potato!
Oz
I hold this place together
*****
Posts: 923



« Reply #3 on: September 19, 2004, 01:14:41 PM »

Code:
TYPE TextBoxType

  selected AS INTEGER

  x        AS INTEGER
  y        AS INTEGER

  length   AS INTEGER
  height   AS INTEGER

END TYPE


Code:
SUB Gui.Outline (xmin AS INTEGER, ymin AS INTEGER, xmax AS INTEGER, ymax AS INTEGER, blight AS LONG, bdark AS LONG)

 Future.Line xmin, ymin, xmax, ymin, blight, -1
 Future.Line xmin, ymin, xmin, ymax, blight, -1
 Future.Line xmin, ymax, xmax, ymax, bdark, -1
 Future.Line xmax, ymin, xmax, ymax, bdark, -1

END SUB


Code:
SUB Gui.TextBox (info AS TextBoxType, text AS STRING)

DIM kbd AS STRING
DIM tkey AS STRING * 1

jj% = info.length \ 8

Future.BOX info.x - 2, info.y - 2, info.x + info.length + 2, info.y + info.height + 2, Black&
Gui.Outline info.x + 1, info.y + 1, info.x + info.length + 1, info.y + info.height + 1, lGrey&, dGrey&
Future.FILLBOX info.x, info.y, info.x + info.length, info.y + info.height, White&

IF TIMER MOD 2 = 0 THEN
 dx% = info.x + ((LEN(text) + 1) * 8)
 Future.Line dx%, info.y + 1, dx%, info.y + info.height - 1, Black&, -1
END IF

kbd = INKEY$
tkey = kbd


IF kbd = CHR$(32) THEN text = text + "_"

IF ASC(tkey) > 32 AND ASC(tkey) <= 126 THEN
 text = text + tkey
ELSEIF tkey = CHR$(13) THEN
 info.selected = 0
ELSEIF tkey = CHR$(8) AND LEN(text) > 0 THEN
 text = LEFT$(text, (LEN(text) - 1))
ELSEIF tkey = CHR$(8) AND LEN(text) = 0 THEN
 SOUND 200, .5
END IF

keyboard = kbd

Gui.Print text, info.x, info.y, Black&

END SUB


Its using future library, so just translate it........ Tongue

Oz~
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #4 on: September 19, 2004, 01:16:07 PM »

Gui.PRINT is basically Future.PRINT, but with a constant transparent background......ignore it

Oz~
Logged
-dezell-
New Member

Posts: 7



WWW
« Reply #5 on: September 19, 2004, 02:30:10 PM »

dark_prevail, thank you, that's what i wanted... Smiley

potato ...no, the box made out of lines is not very important...but this is an other possibility...still, right now i'll stick to this first example...

Oz, thank you too...though, I didn't get your program to work   :-?
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #6 on: September 19, 2004, 03:38:12 PM »

Where was teh program error?

I'll actually make the program if i can know where the problem is...

Oz~
Logged
HQSneaker
Wandering Guru
***
Posts: 394



WWW
« Reply #7 on: September 19, 2004, 04:52:25 PM »

Maybe he didn't even think of converting it and just copy/pasted
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #8 on: September 19, 2004, 05:19:22 PM »

More than likely

I guess taht means he wants me to do the dirty work [no, not rectal surgery...lol]

Code:

TYPE TextBoxType
 PosX  AS INTEGER
 PosY  AS INTEGER

 Length  AS INTEGER    'in characterrs....not pixels

 Text  AS STRING * 256

 Selected  AS INTEGER
END TYPE

DECLARE SUB TextBox (info AS TextBoxType)
DECLARE SUB RelPRINT (text AS STRING, x%, y%, col%)

SCREEN 12

DIM Test AS TextBoxType

Test.PosX = 1
Test.PosY = 1
Test.Length = 15
Test.Text = "Erease me"
Test.Selected = 1

DO UNTIL  Test.Selected = 0

 CALL TextBox (Test)

LOOP

END
'
'    I borrowed this code from Relsoft
'    I did minor editting to incorperate CHR$(13)
'
SUB RelPRINT (text AS STRING, x%, y%, col%)

'Prints the standard 8*8 CGA font
'Paramenters:
'Segment=the Layer to print to
'Xpos,Ypos=the coordinates of the text
'Text$=the string to print
'col= is the color to print(gradient)

oldx = x%
oldy = y%

DIM crap AS STRING * 1

Spacing% = 8
  FOR i% = 0 TO LEN(text$) - 1
    x% = x% + Spacing%
    crap = MID$(text$, i% + 1, 1)
    IF crap = CHR$(13) THEN
     crap = ""
     y% = y% + 8
     x% = oldx
    END IF
    Offset% = 8 * ASC(crap) + 14
    FOR j% = 0 TO 7
      DEF SEG = &HFFA6
      Bit% = PEEK(Offset% + j%)
      IF Bit% AND 1 THEN PSET (x%, y% + j%), col%
      IF Bit% AND 2 THEN PSET (x% - 1, y% + j%), col%
      IF Bit% AND 4 THEN PSET (x% - 2, y% + j%), col%
      IF Bit% AND 8 THEN PSET (x% - 3, y% + j%), col%
      IF Bit% AND 16 THEN PSET (x% - 4, y% + j%), col%
      IF Bit% AND 32 THEN PSET (x% - 5, y% + j%), col%
      IF Bit% AND 64 THEN PSET (x% - 6, y% + j%), col%
      IF Bit% AND 128 THEN PSET (x% - 7, y% + j%), col%
    NEXT j%
  NEXT i%
DEF SEG

x% = oldx
y% = oldy

END SUB

SUB TextBox (info as TextBoxType)

DIM kbd AS STRING
DIM tkey AS STRING * 1

LINE (info.x, info.y)-(info.x + info.length, info.y + info.height), 15,BF

IF TIMER MOD 2 = 0 THEN
 dx% = info.x + ((LEN(text) + 1) * 8)
 LINE (dx%, info.y + 1)-(dx%, info.y + info.height - 1), 0
END IF

kbd = INKEY$
tkey = kbd


IF kbd = CHR$(32) THEN text = text + "_"

IF ASC(tkey) > 32 AND ASC(tkey) <= 126 THEN
 info.text = info.text + tkey
ELSEIF tkey = CHR$(13) THEN
 info.selected = 0
ELSEIF tkey = CHR$(8) AND LEN(text) > 0 THEN
 text = LEFT$(text, (LEN(text) - 1))
ELSEIF tkey = CHR$(8) AND LEN(text) = 0 THEN
 SOUND 200, .5
END IF

keyboard = kbd

RelPRINT text, info.x, info.y, 0
END SUB


That should about do it......

I didn't test it, so be warned,

Oz~
Logged
-dezell-
New Member

Posts: 7



WWW
« Reply #9 on: September 21, 2004, 06:05:13 AM »

edit:
still, I made copy-paste...and qb said:
"END SUB or END FUNCTION must be last line in window"
like whatever Tongue
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!