Prefilled INPUT - editing variables rather than retyping the whole thing
Prefilled INPUT - editing variables rather than retyping the whole thing
Hi,
Is there anyway to have INPUT prefilled with text so it can be edited?
For example, let say I'm editing a string variable and need to amend it, but don't want to retype it all in again.
CODE
=====
address1$ = "29 Stenson Road"
INPUT "Edit Address:", address1$
Desired Result At Console
======================
Edit Address: 29 Stenson Road<<<cursor is here ready for editing>>>
<I press delete 4 times and type "Street" and return, address1$ now = "29 Stenson Street">
Thanks!
Is there anyway to have INPUT prefilled with text so it can be edited?
For example, let say I'm editing a string variable and need to amend it, but don't want to retype it all in again.
CODE
=====
address1$ = "29 Stenson Road"
INPUT "Edit Address:", address1$
Desired Result At Console
======================
Edit Address: 29 Stenson Road<<<cursor is here ready for editing>>>
<I press delete 4 times and type "Street" and return, address1$ now = "29 Stenson Street">
Thanks!
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
I don't think it is possible with input, the alternative is a custom input routine like this:
(a quick modification of old code I found, likely contains one or more bugs)
Code: Select all
function waitKey() as string
dim as string key
do
key = inkey
sleep 1
loop while key = ""
return key
end function
function getInput(labelStr as string, preStr as string, row as integer, col as integer) as string
dim as string key, retStr = preStr
dim as integer colCursor = col + len(labelStr) + len(retStr)
locate row, col
print labelStr + retStr;
while 1
key = waitKey()
select case key
case chr(8) 'bakcspace
if len(retStr) > 0 then
retStr = left(retStr, len(retStr) - 1)
locate row, colCursor - 1
print " ";
colCursor -= 1
end if
case chr(13) 'enter
exit while
case chr(27) 'secape
retStr = ""
exit while
case chr(32) to chr(127) 'printable char
retStr += key
print key
colCursor += 1
end select
locate row, colCursor
wend
return retStr
end function
dim as string retStr = "Street xyz"
do
locate 8, 20: print "type 'exit' for exit, <escape> to clear"
retStr = getInput("Address: ", retStr, 10, 20)
cls
locate 12, 20: print retStr
loop until lcase(retStr) = "exit"
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
I think I've found a bug with input and line input in -gen gas (with const)
Code: Select all
const s="type a few characters "
print "Const = ";s
print len(s)
line input s,s
print "Const = ";s
print len(s)
print mid(s,1,1)
sleep
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
IMO, not a bug. Just the fact, that a Const cannot be modified and that is OK!
(call it "expected behaviour")
line input s, s The second s (at least), MUST be a variable ...
(call it "expected behaviour")
line input s, s The second s (at least), MUST be a variable ...
Last edited by MrSwiss on Jun 07, 2019 15:28, edited 1 time in total.
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
Didn't we have a long thread some months ago?
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
Mr Swiss
But the const IS being modified in -gen gas.
jj2007
Probably, somebody must have came across it before.
But the const IS being modified in -gen gas.
jj2007
Probably, somebody must have came across it before.
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
Search the forum for GetString
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
Difference already seen between gas and gcc:
- For gas, a literal string is put in the .DATA section.
- For gcc, a literal string is put in the .RDATA section (read only).
So gas allows to modified a literal string while gcc returns a run-time error ("segmentation violation" signal).
- For gas, a literal string is put in the .DATA section.
- For gcc, a literal string is put in the .RDATA section (read only).
So gas allows to modified a literal string while gcc returns a run-time error ("segmentation violation" signal).
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
Windows 32-bit:
Code: Select all
#inclib "MbMicroDll" ' download from http://www.jj2007.eu/images/MbMicroDll.dll
#include "crt.bi"
Declare Function InputString Cdecl Alias "GETINPUT" (destination As Zstring ptr, prefill As Zstring ptr) As zString ptr
Dim As zString*200 dest
Dim As zString*30 pref="FreeBasic is a great dialect"
printf("Please edit the string: ")
printf("The DLL returned the string '%s'", InputString(@dest, @pref))
sleep
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
Well, 32 bit is just so much, on the way to obsolescence, we can just about forget it ...
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
Thank you Mr Swiss for your most valuable contribution.
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
Sorry jj2007, your dll file was quarantined by avira.
I re started and renamed the dll, but that was quarantined also.
I re started and renamed the dll, but that was quarantined also.
Re: Prefilled INPUT - editing variables rather than retyping the whole thing
MbMicroDll.dll is written in Assembler, and crappy heuristic scanners "detect" that as suspicious. VirusTotal says at https://www.virustotal.com/gui/file/5a9 ... /detection that 7 out of 71 AV engines flag it as suspicious. Strangely enough, Avira on VT says it's OK. Some AV's allow to declare specific folders "safe", see https://answers.avira.com/en/question/h ... 88?sh=true for the procedure. You would have to trust me, though ;-)