Editing A Field Variable

Just starting out? Need help? Post your questions and find answers here.
AussiePup
User
User
Posts: 19
Joined: Fri Jun 20, 2003 4:47 pm
Location: Chapel Hill, NC

Editing A Field Variable

Post by AussiePup »

if I do something like this ... name.s = input() and let's say "Johnny" was entered. Now I want to allow the user to edit this variable .. sounds dumb, but I have been unable to figure out how to do this. Hopefully, I have just overlooked the command, etc..

Thanks,

AussiePup
Regards,

Martin
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Editing A Field Variable

Post by Demivec »

Display the variable's contents, input the new value from the user, then assign it to the variable.
AussiePup
User
User
Posts: 19
Joined: Fri Jun 20, 2003 4:47 pm
Location: Chapel Hill, NC

Re: Editing A Field Variable

Post by AussiePup »

Thanks for the reply. I did a print of the variable, as you suggested, and then did an input in the same location, using consolelocate .. this could work, but isn't there a way to move around in an input field to edit. For example, if you make a typo, you can't use the arrow key to go back and correct .. this just doesn't seem right. Also, there should be a way to have a predetermine variable length, etc.. I have programmed in Clipper for almost 30 years and could simply do a get with any variable.

Surely there is a better and more elegant way? (I hope)

Thanks,

AussiePup
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Editing A Field Variable

Post by luis »

No, the best you can do with input is this:

Code: Select all

EnableExplicit

Define sName.s, sTemp.s

If OpenConsole()
    Print("Enter your name and press return: ")
    sName = Input()
    
    PrintN("Hello, you entered: " + sName)

    Print("If you want to change it, enter the new name or press enter: ")
    sTemp = Input()
    
    If sTemp
        sName = sTemp
    EndIf
    
    PrintN("Your name is: " + sName)
    PrintN("")               
    PrintN("Press return to exit")
    Input()
EndIf

Input only does a simple read of the standard input, no editing, similar to scanf() in C, if you know it.

You have to create a input routine for yourself using Inkey() and insert and remove chars from a buffer string accordingly. Anyway, you have to build this routine once and use it forever in your console applications, it's a good exercise :)


Clipper... Nantucket software right? I remember doing some routines in C for it to write directly to the screen (for a friend of mine). Fast access without the snow effect on cga cards... good old times !
"Have you tried turning it off and on again ?"
AussiePup
User
User
Posts: 19
Joined: Fri Jun 20, 2003 4:47 pm
Location: Chapel Hill, NC

Re: Editing A Field Variable

Post by AussiePup »

Thanks Luis,

Tells me what I need to know. It's a rarity that I use my PureBasic, so I don't know whether I will write some input function or not, but if I do, I will let you know. I just wrote a Sudoku solver that gets the numbers from data statements. Now that I have it working, I need to have a user interface to enter a puzzle. This is what started me down this road. In Clipper, I could turn confirm off, which would allow single character or end of field entries to "get" without the user pressing return. I guess I could write a function using inkey to do this without too much trouble.

Thanks again,

Martin
Regards,

Martin
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Editing A Field Variable

Post by luis »

Nice one :)

If you encounter problems let me know what you need from your console input and I'll try to write a basic (no pun intended) one for you as soon as I have a little time.
"Have you tried turning it off and on again ?"
Post Reply