View Full Version : Console Box and Console Readline
Hello,
I was experimenting with the Console_Box and Console_PrintAt from looking at some examples.
I have a question if it is possible to read input at particular location.
For example, if I setup a Console_Box and use the Console_PrintAt to do this:
Console_PrintAt ("Enter address: ", 1, 5, 158)
Is there a way to use the Console_Readline() to start reading input after the "Enter address: ?
Then I'll do the same for next input for city, state, zip, etc.
Right now, it's expecting input at the top of the box (1,1). Maybe I'm mixing apples and oranges and it can't be done.
Just wondering.
Thanks.
Petr Schreiber
19-03-2011, 11:44
Hi,
you were close :) To do what you need, you have to set cursor position first.
I created for you sample with simple wrapper function:
Uses "Console"
String sInput
sInput = Custom_InputAt("Enter your name please: ", 10, 10, %CONSOLE_FOREGROUND_GREEN)
Console_PrintAt("Your name is "+sInput, 10, 11)
sInput = Custom_InputAt("Enter your surname please: ", 10, 12, %CONSOLE_FOREGROUND_GREEN)
Console_PrintAt("Your surname is "+sInput, 10, 13)
WaitKey
Function Custom_InputAt( sPrompt As String, xPos As Long, yPos As Long, Optional lColor As Long) As String
Long oldTextAttribute
String sInput
' -- Did we passed color (4th param)?
If Function_NParams = 4 Then
' -- Retrieve old text attribute
oldTextAttribute = Console_GetTextAttribute()
' -- Set new color
Console_SetTextAttribute(lColor)
End If
' -- Print text at desired location
Console_PrintAt(sPrompt, xPos, yPos)
' -- Set cursor right after it
Console_SetCursorPosition(xPos+Len(sPrompt), yPos)
' -- Read the input
sInput = Console_ReadLine()
' -- Did we passed color (4th param)?
If Function_NParams = 4 Then
' -- Roll back old text attribute
Console_SetTextAttribute(oldTextAttribute)
End If
Return sInput
End Function
Petr
Thanks Petr.
I had a long reply and guess I had to log in again and lost my long reply.
I started out learning thinBasic with a data entry program to read inputs and created a tab delimited file.
Then my next education was to read in a file and output a tab delimited file.
After that I wanted to use UI to redo my data entry program so that the user could go back and edit any input that was typed wrong. But I got stuck on it.
So looking through the sample scripts and the help manual, I came across a ftp script. That's how I got the idea to maybe redo my "console" data entry program to include colors and may user can re-edit input and hitting return. If that didn't work, I was going to try another idea from one of the samples of yes/no button to display all the input and allow user to verify before continuing.
Thanks for your sample, Petr because it helps me understand more of thinBasic. I had to look up Function_NParam. LOL.
Could you tell me what %console_quick_edit_mode and %console_mouse_input does?
It may help me with what I want to accomplish or maybe not.
Sorry if I ask "dumb" questions.
Much appreciated!
Petr Schreiber
21-03-2011, 20:30
Hi TheOne,
no problem, the questions are interesting!
Where did you found %console_quick_edit_mode and %console_mouse_input?
Petr
Hi Petr,
It's in the help manual under 8.7.53 Console_SetInputMode.
When I coded my first program (the data entry one), I've find a sample script that used the Console_SetInputMode as %Console_Enabled_Processed_Input.
Now that I know just a tiny more of thinBasic compared to you as pros and experts :D, I was wondering how the quick edit mode or mouse input might be used so that maybe I could use it in my program.
BTW, your wrapper code works great. Slowly retrofitting into my data entry program and testing. Had to debug cuz I wanted error message on the top and learning a few more things from my mistakes. :rolleyes:
Thanks.
PS: I've learned something new from your code. I was doing things like DIM sInput as String but it looks like you can just say String sInput. (So much I don't know.)
Petr Schreiber
22-03-2011, 14:09
Hi :),
I think I know what it does, it is wrapper for Win32 SetConsoleMode fuctions. You can read more about it here:
http://msdn.microsoft.com/en-us/library/ms686033%28v=vs.85%29.aspx
Regarding the short syntax for variables - when you do not like typing too much, this version comes really handy.
Petr
ErosOlmi
22-03-2011, 15:27
Dear TheOne,
if I get it correctly, you are trying to load a text file, parse its content, present to your user parsed data and finally have the possibility to save it back.
If so, did you check "MLGRID.tBasic" example in "\thinBasic\SampleScripts\UI\MLGrid\"
It shows how to use and handle data inside a grid using callbacks. You have quite strong control over your grid control and present nice data.
Loading and saving back text files should be quite easy once you have your parsing routine done. Just substitute sample data with your input parsing routine.
Let me know.
Eros
Thanks Petr. I saw read that.
Thanks Eros.
I will look at your sample as that would be a good starting point to learn more about UI and callbacks. What I was trying to do was modify my data entry program from console to UI so that it's more GUI like whereas you have input boxes. After entering data on the first input box, you can hit Tab or Return to get to next box. Or use the mouse to click on a certain box to re-enter data. At end, click on OK button (then the program will create the output record.)
I appreciate all your help and suggestions.
ErosOlmi
22-03-2011, 18:32
The example I gave you uses a grid control called MLGrid.
It is quite intuitive to be programmed and should be very easy to be used by your users because it seems a spreadsheet.
You need to do some functions that loads data and save at the end.