Results 1 to 9 of 9

Thread: Console Box and Console Readline

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    16

    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, 15

    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.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    16
    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!

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    Hi TheOne,

    no problem, the questions are interesting!

    Where did you found %console_quick_edit_mode and %console_mouse_input?


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    16
    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 , 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.

    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.)

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    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/libr...=vs.85%29.aspx

    Regarding the short syntax for variables - when you do not like typing too much, this version comes really handy.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8
    Junior Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    16
    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.

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    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.
    Attached Images Attached Images
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •