Page 1 of 1

Editing A Field Variable

Posted: Mon Oct 26, 2009 8:49 pm
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

Re: Editing A Field Variable

Posted: Mon Oct 26, 2009 9:14 pm
by Demivec
Display the variable's contents, input the new value from the user, then assign it to the variable.

Re: Editing A Field Variable

Posted: Mon Oct 26, 2009 10:46 pm
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

Re: Editing A Field Variable

Posted: Mon Oct 26, 2009 10:52 pm
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 !

Re: Editing A Field Variable

Posted: Tue Oct 27, 2009 12:42 am
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

Re: Editing A Field Variable

Posted: Tue Oct 27, 2009 12:54 am
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.