Prefilled INPUT - editing variables rather than retyping the whole thing

General FreeBASIC programming questions.
Post Reply
GrantsV
Posts: 1
Joined: Jun 07, 2019 12:23

Prefilled INPUT - editing variables rather than retyping the whole thing

Post by GrantsV »

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!
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by badidea »

I don't think it is possible with input, the alternative is a custom input routine like this:

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"
(a quick modification of old code I found, likely contains one or more bugs)
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by dodicat »

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
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by MrSwiss »

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 ...
Last edited by MrSwiss on Jun 07, 2019 15:28, edited 1 time in total.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by jj2007 »

Didn't we have a long thread some months ago?
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by dodicat »

Mr Swiss
But the const IS being modified in -gen gas.
jj2007
Probably, somebody must have came across it before.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by jj2007 »

Search the forum for GetString
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by fxm »

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).
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by jj2007 »

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
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by MrSwiss »

Well, 32 bit is just so much, on the way to obsolescence, we can just about forget it ...
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by jj2007 »

Thank you Mr Swiss for your most valuable contribution.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by dodicat »

Sorry jj2007, your dll file was quarantined by avira.
I re started and renamed the dll, but that was quarantined also.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Prefilled INPUT - editing variables rather than retyping the whole thing

Post by jj2007 »

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 ;-)
Post Reply