|
Post by harrybrunton on Jan 25, 2006 20:19:59 GMT
hi, I am new to message boards, so I hope I am doing the right thing, I some years ago wrote a simple qbasic program to input the contents of a label, so several could be printed for dispatch purposes. I now want to allow the users to edit the address details rather than always start from a new label. I can't find or perhaps understand how you edit an existing variable, please help
|
|
|
Post by Mikrondel on Jan 26, 2006 0:27:55 GMT
Well, it may have helped if you posted your program.
Still, I'll try as best as I can to assist.
What I think you want to do is, more or less, have INPUT start off with something that you can edit.
Sorry friend, but INPUT is garbage. I practically never use it.
The alternative is tough, however. There is a function, INKEY$, which returns a single keypress. You can use it to construct something better than INPUT, but it's far from easy. Even if you're experienced it takes quite a bit of coding and debugging.
I really don't have the time to do something like that, however I've dug up an old subroutine of mine, that I don't trust (as I made it a very long time ago) but may be sufficient for you. Give me some feedback and report any bugs, and maybe I'll change it for you.
' ************************************ ' * * ' * Serious Input-v1.1 - A.Budzynowski * ' * * ' ************************************ ' Specs: ' GetInput <string to edit>, <maximum length>, <top row of edit box>, <leftmost column of edit box>, <bottom row>, <rightmost column> ' For a 1-line input, set top and bottom row to the same thing.
DECLARE SUB GetInput (Strng$, size AS INTEGER, startrow AS INTEGER, startcol AS INTEGER, endrow AS INTEGER, endcol AS INTEGER)
CLS Edit$ = "Well, here's a nice long sample for you, I hope you understand how it works. More or less usable." GetInput Edit$, 110, 2, 2, 4, 22
LOCATE 10 PRINT Edit$
END
SUB GetInput (Strng$, size AS INTEGER, startrow AS INTEGER, startcol AS INTEGER, endrow AS INTEGER, endcol AS INTEGER)
IF LEN(Strng$) > size THEN Strng$ = LEFT$(Strng$, size) IF startrow < 1 THEN startrow = 1 IF startcol < 1 THEN startcol = 1 IF endrow < 1 THEN endrow = 1 IF endcol < 1 THEN endcol = 20
HL = endcol - startcol + 1 VL = endrow - startrow + 1
CursorPos = LEN(Strng$) + 1 StartPos = LEN(Strng$) - VL * HL + 1 IF LEN(Strng$) < size THEN StartPos = StartPos + 1 IF StartPos < 1 THEN StartPos = 1
COLOR 7, 1 Old$ = " " LOCATE , , 1, 31, 31
DO Key$ = INKEY$
IF LEN(Key$) = 2 THEN SELECT CASE RIGHT$(Key$, 1)
CASE "H" CursorPos = CursorPos - HL: IF CursorPos < StartPos THEN StartPos = StartPos - HL: CursorPos = StartPos CASE "K" CursorPos = CursorPos - 1 CASE "M" IF CursorPos <= LEN(Strng$) THEN CursorPos = CursorPos + 1 CASE "S" IF CursorPos <= LEN(Strng$) THEN Strng$ = LEFT$(Strng$, CursorPos - 1) + RIGHT$(Strng$, LEN(Strng$) - CursorPos)
CASE "G" IF CursorPos - StartPos > 0 THEN CursorPos = StartPos ELSE StartPos = 1: CursorPos = 1 CASE "O" IF VL * HL < LEN(Strng$) THEN IF CursorPos - StartPos + 1 < VL * HL THEN CursorPos = StartPos + VL * HL - 1 ELSE StartPos = LEN(Strng$) + 2 - VL * HL: CursorPos = StartPos + VL * HL - 1: IF LEN(Strng$) = size THEN StartPos = StartPos - 1 IF VL * HL >= LEN(Strng$) THEN CursorPos = LEN(Strng$) + 1: IF LEN(Strng$) >= size THEN CursorPos = CursorPos - 1
CASE "R" insrt% = 1 - insrt%: IF insrt% = 0 THEN LOCATE , , 1, 31, 31 ELSE LOCATE , , 1, 0, 31 END SELECT
IF CursorPos < StartPos THEN StartPos = StartPos - 1 IF CursorPos - StartPos + 1 > VL * HL THEN StartPos = StartPos + 1 END IF IF LEN(Key$) = 1 THEN IF ASC(Key$) <> 254 AND NOT ((ASC(Key$) < 32 AND ASC(Key$) > 23) OR (ASC(Key$) < 14 AND ASC(Key$) > 6)) THEN IF insrt% = 0 THEN IF LEN(Strng$) < size THEN Strng$ = LEFT$(Strng$, CursorPos - 1) + Key$ + RIGHT$(Strng$, LEN(Strng$) - CursorPos + 1): CursorPos = CursorPos + 1: IF LEN(Strng$) - StartPos + 1 >= VL * HL AND LEN(Strng$) <= size THEN StartPos = _ StartPos + 1 IF insrt% = 1 THEN IF StartPos + CursorPos - 1 < LEN(Strng$) THEN IF LEN(Strng$) < size THEN Strng$ = LEFT$(Strng$, CursorPos - 1) + Key$ + RIGHT$(Strng$, LEN(Strng$) - CursorPos): CursorPos = CursorPos + 1: IF LEN(Strng$) - StartPos + 1 >= VL * HL AND LEN(Strng$) < _ size THEN StartPos = StartPos + 1 END IF END IF IF Key$ = CHR$(8) THEN IF CursorPos > 1 THEN Strng$ = LEFT$(Strng$, CursorPos - 2) + RIGHT$(Strng$, LEN(Strng$) - CursorPos + 1): CursorPos = CursorPos - 1: IF CursorPos < StartPos THEN StartPos = StartPos - 3: IF StartPos < 1 THEN StartPos = 1
IF ASC(Key$) = 13 THEN EXIT DO END IF
IF Old$ <> Key$ THEN IF CursorPos < 1 THEN CursorPos = 1 IF StartPos < 1 THEN StartPos = 1
LOCATE startrow FOR i = 0 TO VL - 1 LOCATE , startcol PRINT MID$(Strng$, StartPos + i * (HL), HL); IF POS(0) <= endcol THEN PRINT SPACE$(endcol - POS(0) + 1); PRINT NEXT i END IF
IF Old$ <> Key$ THEN LOCATE startcol + INT((CursorPos - StartPos) / HL), startcol + ((CursorPos - StartPos) MOD HL) END IF
Old$ = Key$
LOOP LOCATE , , 0, 31, 31 END SUB
Anyway I hope that helped in some way, and you solve your problem.
Mikrondel
|
|