G4C


WINBIG -1 -1 498 189  "CutVar.gc"
WinType 11110001
usetopaz

; ---- Decorations
BOX 0 0 498 87  OUT RIDGE
BOX 0 87 498 102  OUT RIDGE

; ---- Embossed Headings using the user's screen font
CTEXT 12 7  " Using CutVar on a word " #screen 8 2 0 0001
CTEXT 10 93  " Using CutVar on a line "  #screen 8 2 0 0001

xonLoad 
	GuiOpen CutVar.gc

xonClose
	GuiQuit CutVar.gc

; ---------------------------------- Upper half : cutting a word

TEXT 32 21 108 10  "Enter a word to be cut (and press <Return>) :" 48 NOBOX

XTEXTIN 32 32 216 13  '' word '' 100

TEXT 32 48 108 10  "Cut it after which letter?" 27 NOBOX


;  The number entered is used to mark the position to cut the word

XTEXTIN 378 46 54 13  'Enter a number' cutpos '' 100
	;     Cut the first (or last) 'cutpos' letters from 'word'
	;     and put them into 'dest'.
	;     A negative value counts from the end of the word.
	;     The CHAR argument determines that letters are counted.
	CutVar word CUT CHAR $cutpos dest
	;     Show the two parts
	update CutVar.gc 1 $dest
	update CutVar.gc 2 $word

XBUTTON 383 60 43 10  'Tip'
	setvar a 'Enter SENSIBLE values for the cutting position.\n'
	appvar a 'Remember GIGO : Garbage in, garbage out.\n\n'
	appvar a 'Try entering a negative value for the cutting position.'
	ezreq $a 'Okay' v

;     Gadgets to display the results

TEXT 32 58 108 10  "Your word has been cut into " 45 NOBOX

TEXT 32 69 162 13  " " 40 BOX
	gadid 1

TEXT 205 69 162 13  " " 40 BOX
	gadid 2

;----------------------------------------- Lower half
;     Line cutting, more or less the same as word cutting above

TEXT 32 109 108 10  "Enter a line to be cut (and press <Return>) : " 48 NOBOX

XTEXTIN 32 120 400 13  '' line "" 200

TEXT 32 135 108 10  "Cut it after which word?" 27 NOBOX

XTEXTIN 378 133 54 13  'Enter a number' wcutpos '' 100
	;     The WORD argument determines that words are counted.
	;     Otherwise, as above.
	CutVar line CUT WORD $wcutpos dest2
	;     The initial space needs to be cut from the second part of
	;     the line.
	if $wcutpos > 0                ; Counting forwards
	  CutVar line CUT CHAR 1 trim
	else                           ; Counting from the end
	  CutVar dest2 CUT CHAR 1 trim
	endif
	update CutVar.gc 3 $dest2
	update CutVar.gc 4 $line


TEXT 32 146 108 10  "Your line has been cut into " 45 NOBOX

TEXT 32 157 378 13  " " 100 BOX
	gadid 3

TEXT 32 171 378 13  " " 100 BOX
	gadid 4

