Doesn't save anything yet, but thought I'd post what little I had already. I've just been very busy lately. Hopefully, I'll get a little more time tonight to work on it.
caretDelay = 500 : `flashing delay on caret
caretTimestamp = timer()
RecordCount = 4
RecordLines = 4
dim records$(RecordCount*RecordLines)
records$(1) = "Peter Parker"
records$(2) = "123 Metro Ln."
records$(3) = "555-654-6548"
records$(4) = "[email protected]"
recordPointer = 0
focusedField = 1
activeRecord = recordPointer * RecordLines
recordElement = activeRecord + focusedField
caretX = 12
sync on
sync rate 0
DO
cls
oldkey = key
key = asc(inkey$())
rem so pressing a single key won't display a billion copies
if oldkey <> key
if (key > 31 and key < 127) OR (key > 127 and key < 255)
records$(recordElement) = insertChar$(records$(recordElement), chr$(key), caretX)
inc caretX
else
rem backspace
if key = 8
rem delete previous character
if caretX > 0
t$ = records$(recordElement)
aToken$ = left$(t$, caretX-1)
bToken$ = right$(t$, len(t$)-caretX)
records$(recordElement) = aToken$ + bToken$
dec caretX
endif
endif
rem tab
if key = 9 and tabFlag = 0
tabFlag = 1
inc focusedField, 1
if focusedField > 4 then focusedField = 1
recordElement = activeRecord + focusedField
caretX = len(records$(recordElement))
endif
rem return key
if key = 13
endif
endif
endif
rem delete key
if scancode() = 211 and delFlag=0
delFlag=1
t$ = records$(recordElement)
if caretX < len(t$)
aToken$ = left$(t$, caretX)
bToken$ = right$(t$, len(t$)-(caretX+1))
records$(recordElement) = aToken$ + bToken$
endif
endif
if scancode() = 0 then delFlag=0 : tabFlag=0
ink rgb(186,186,186),0
box 196,160,364,344
ink 0,0
text 200,184, "Name"
drawTextField(200, 200, 160, records$(activeRecord+1), 2-focusedField, caretX)
text 200,224, "Address"
drawTextField(200, 240, 160, records$(activeRecord+2), 3-focusedField, caretX)
text 200,264, "Phone"
drawTextField(200, 280, 160, records$(activeRecord+3), 4-focusedField, caretX)
text 200,304, "Email"
drawTextField(200, 320, 160, records$(activeRecord+4), 5-focusedField, caretX)
gosub _HandleFieldFocus
gosub _DisplayCaret
sync
loop
REM **************************************************
REM
REM **************************************************
_HandleFieldFocus:
if mouseclick() = 1 and mFlag = 0
mFlag = 1
if mouseWithin(200,200,360,220) = 1
focusedField = 1
caretX = getCaretClickPosition(records$(activeRecord+1), 202)
endif
if mouseWithin(200,240,360,260) = 1
focusedField = 2
caretX = getCaretClickPosition(records$(activeRecord+2), 202)
endif
if mouseWithin(200,280,360,300) = 1
focusedField = 3
caretX = getCaretClickPosition(records$(activeRecord+3), 202)
endif
if mouseWithin(200,320,360,340) = 1
focusedField = 4
caretX = getCaretClickPosition(records$(activeRecord+4), 202)
endif
recordElement = activeRecord + focusedField
endif
if mouseclick() = 0 then mFlag = 0
RETURN
REM **************************************************
REM
REM **************************************************
_DisplayCaret:
if timer() > caretTimestamp + caretDelay
showCaret = abs(showCaret-1)
caretTimestamp = timer()
endif
if showCaret = 1
x = text width(left$(records$(activeRecord+focusedField), caretX))
text 201+x,202+(focusedField-1)*40, "|"
endif
RETURN
REM **************************************************
REM Returns the character position of where the mouse
REM cursor is in relation to the string 't$' starting
REM at the 'x' screen coordinate
REM **************************************************
function getCaretClickPosition(t$, x)
x = mousex() - x
for i = 1 to len(t$)
if text width(left$(t$,i)) > x then caretX = i-1 : exit
if x > text width(t$) then caretX = len(t$)
next i
endfunction caretX
REM **************************************************
REM Returns true if mouse is within the coordinates
REM **************************************************
function mouseWithin(x1, y1, x2, y2)
if mousex() > x1 and mousex() < x2 and mousey() > y1 and mousey() < y2 then exitfunction 1
endfunction 0
REM **************************************************
REM Draws a text box and its text where (x,y) is the
REM upper-left corner of the box and 'size' is the
REM width in pixels of the box.
REM **************************************************
function drawTextField(x, y, size, text$, hasFocus, caretX)
ink rgb(255,255,255),0
box x, y, x+size, y+height
ink 0, 0
if hasFocus = 1
ink 564160,0
else
ink 0,0
endif
`cx = text width(left$(text$, caretX))
if cx > size
`size - cx
endif
text x+2, y+2, text$
height = 20
line x, y, x+size, y
line x, y, x, y+height
line x, y+height, x+size, y+height
line x+size, y, x+size, y+height
ink 0,0
endfunction
REM **************************************************
REM Returns given string with character 'C' inserted
REM at position 'P'
REM **************************************************
function insertChar$(string$, c$, p)
t$ = left$(string$, p)
t2$ = right$(string$, len(string$)-len(t$))
t$ = t$ + c$ + t2$
endfunction t$
REM **************************************************
REM Returns the string truncated to a specified width
REM in pixels.
REM **************************************************
function capLength$(string$, width)
L = len(string$)
min = width / text width("A")
for j = min to L
if text width(left$(string$,j)) > width then exitfunction left$(string$,j-1)
next j
endfunction string$
