Is there existing an inputroutine?

General FreeBASIC programming questions.
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Is there existing an inputroutine?

Postby Jawade » Nov 23, 2018 13:58

An input routine for to get data.

I wrote severals, but it is not easy. I mean one whit the
input arguments locate, length, color. And keys ASCII,
backspace, Arrow left and right.

Maybe knows someone a right one.
MrSwiss
Posts: 3127
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Is there existing an inputroutine?

Postby MrSwiss » Nov 23, 2018 17:08

Since I don't really understand your question, can you provide some code,
which highlights the problem, you are having?

See also: FB-Manual/Input
D.J.Peters
Posts: 7694
Joined: May 28, 2005 3:28

Re: Is there existing an inputroutine?

Postby D.J.Peters » Nov 23, 2018 17:35

@MrSwiss he means an input field a one row edit box you know ?

I saw one or two solutions in the past ... must do a forum search :-(

Joshy
MrSwiss
Posts: 3127
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Is there existing an inputroutine?

Postby MrSwiss » Nov 23, 2018 18:24

@Joshy, thanks.

@Jawade,
which OS are you using? (WIN/LIN/other, please specify)
Console or Graphics (GUI)?
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Is there existing an inputroutine?

Postby Jawade » Nov 23, 2018 21:16

I use Windows 10. And I mean an input routine who can give the program
several data, like usename, password and so on. I want one who well wil
ppassed in in a existing program. I wrote one wich have only the Backspace
key, and I don't get it better.
MrSwiss
Posts: 3127
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Is there existing an inputroutine?

Postby MrSwiss » Nov 23, 2018 21:41

Jawade wrote:I wrote one wich have only the Backspace key, and I don't get it better.
Well, in console mode, there is not much more, that can be done.
In GUI mode, you could use a existing library, like WinGUI which has a Edit-Control.

Some Edit... Functions (essentially the same, just returning different variable types).
You can call them, as many times as needed:

Code: Select all



Function EditStr( _                     ' console only Edit-Control
    ByVal row   As UByte = 1, _         ' row position
    ByVal col   As UByte = 1, _         ' column pos.
    ByVal txt   As String = "", _       ' user message (if any)
    ByVal f_c   As UByte = 7, _         ' foreground color
    ByVal b_c   As UByte = 0 _          ' background color
    ) As String                         ' return a string
    Dim As String   tmp = ""

    Color(f_c, b_c) : Locate(row, col)
    Line Input txt + ": ", tmp
    Color(7, 0) : Return tmp
End Function

Function EditLng( _                     ' console only Edit-Control
    ByVal row   As UByte = 1, _         ' row position
    ByVal col   As UByte = 1, _         ' column pos.
    ByVal txt   As String = "", _       ' user message (if any)
    ByVal f_c   As UByte = 7, _         ' foreground color
    ByVal b_c   As UByte = 0 _          ' background color
    ) As Long                           ' return a number
    Dim As String   tmp = ""

    Color(f_c, b_c) : Locate(row, col)
    Line Input txt + ": ", tmp
    Color(7, 0) : Return CLng(tmp)
End Function

Function EditDbl( _                     ' console only Edit-Control
    ByVal row   As UByte = 1, _         ' row position
    ByVal col   As UByte = 1, _         ' column pos.
    ByVal txt   As String = "", _       ' user message (if any)
    ByVal f_c   As UByte = 7, _         ' foreground color
    ByVal b_c   As UByte = 0 _          ' background color
    ) As Double                         ' return a float number
    Dim As String   tmp = ""

    Color(f_c, b_c) : Locate(row, col)
    Line Input txt + ": ", tmp
    Color(7, 0) : Return Val(tmp)
End Function


Locate(2, 2) : Print "Press [ENTER] to finish input."
Dim As String   s = EditStr(5, 2,"input test", 14)
Cls
Locate(2, 1) : Print "Edit return: *"; s; "* (without the *)"
Locate(6, 1) : Print "press a key to EXIT ";

sleep
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Is there existing an inputroutine?

Postby Jawade » Nov 23, 2018 23:11

Thanks, it is very nice. Works also in graphics.
TJF
Posts: 3473
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Is there existing an inputroutine?

Postby TJF » Nov 24, 2018 10:56

You may also want to check InputUsing code with advanced OMIKRON BASIC syntax:

https://www.freebasic-portal.de/code-be ... e-257.html
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Is there existing an inputroutine?

Postby Jawade » Nov 24, 2018 13:01

Thanks, looks very goood.


Now I look for a routine who prints everything. Because I use a printroutine
who is scalable.
Munair
Posts: 834
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: Is there existing an inputroutine?

Postby Munair » Nov 24, 2018 13:57

Jawade wrote:Thanks, looks very goood.


Now I look for a routine who prints everything. Because I use a printroutine
who is scalable.

There are several kinds of devices one can print to.
jj2007
Posts: 1180
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Is there existing an inputroutine?

Postby jj2007 » Nov 24, 2018 17:03

TJF wrote:You may also want to check InputUsing code with advanced OMIKRON BASIC syntax:

https://www.freebasic-portal.de/code-be ... e-257.html
Omikron Basic, really? Wasn't that the Atari ST Basic for a short period? I have tinkered with it, but then Gfa took over.

Re input routine, see this thread. Works fine but the way FB treats external DLLs is a bit awkward. That routine allows a prompt and a prefilled string, like this:

Code: Select all

MyString=GETINPUT("What's your hobby? ", "programming in Basic")

The prefilled part can be edited using cursor left/right, backspace, inserting chars etc.
TJF
Posts: 3473
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Is there existing an inputroutine?

Postby TJF » Nov 24, 2018 20:23

jj2007 wrote:Wasn't that the Atari ST Basic for a short period? I have tinkered with it, but then Gfa took over.

It was vice versa: Atari started with Gfa and then the powerful OMIKRON took over.
grindstone
Posts: 640
Joined: May 05, 2015 5:35
Location: Germany

Re: Is there existing an inputroutine?

Postby grindstone » Nov 24, 2018 23:40

dodicat
Posts: 5819
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Is there existing an inputroutine?

Postby dodicat » Nov 25, 2018 0:43

Dynamic input (in a loop)

Code: Select all

 

Sub _input(st As String,message As String)
    Dim As String i=""
    Static As long k=1
    Static As String j,blink
    static as double t
    i=Inkey
    If Left(i,1)=Chr(08) Then j=Mid(j,1,Len(j)-1)
    Select Case Left(i,1)
    Case Chr(0) To Chr(254)
        If Left(i,1)<>Chr(08) Then
            j=j+Left(i,1)
        End If
    End Select
    if timer-t>.5 then
        t=timer
        k=-k
    if k=1 Then blink=" " else blink="_"
        end if
    If Left(i,1)=Chr(27) Then j=""
    If i<>Chr(13) Then
        Print st & j & blink
    Else
        j=Rtrim(j,Chr(13))
        message=j
        j=""
    End If
End Sub

Function framecounter() As long
    dim as double t2=timer
    Static As Double t3,frames,answer
    frames=frames+1
    If (t2-t3)>=1 Then
        t3=t2
        answer=frames
        frames=0
    End If
    Return answer
End Function


dim as string msg
do
     cls
    locate 1,,0
    print "fPS ";framecounter
    locate 3,,0
    _input("Enter stuff (q to quit)  ",msg)
    locate 7,,0
    print msg
    sleep 20,1
    loop until msg="q"
 
jj2007
Posts: 1180
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Is there existing an inputroutine?

Postby jj2007 » Nov 25, 2018 0:48

Yes, that one is brilliant. Thanks for reminding us!

@TJF:
TJF wrote:
jj2007 wrote:Wasn't that the Atari ST Basic for a short period? I have tinkered with it, but then Gfa took over.

It was vice versa: Atari started with Gfa and then the powerful OMIKRON took over.
I used Gfa on the Atari ST until roughly 1996, then my work hierarchy forced me to switch to Windows. And there I continued with Gfa until they introduced 64-bit Windows versions. But I can still run my 16-bit Windows stuff in a VM, and my old Atari programs run just fine in the Steem emulator. And today, I use Gfa syntax in Win7 and Win10, see here ;-)

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest