Results 1 to 5 of 5

Thread: input filtering

  1. #1

    input filtering

    In my console program I'm writing I need a way to get a number from the user. It needs to accept only digits (numbers from 0-100). Right now I'm using console_readline and I need a way to keep the user from typing in letters.

    Is there something built in to thinbasic that will do this or do I need to write a function?

    Thanks

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: input filtering

    Right now you need to write your own functions but your request in nice.
    Give me few days (I've something urgent to finish for the next two days) and I will add one or two native functions for reading numbers.


    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

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: input filtering

    Wow, input function with validation for specific entries would be neat. They could even be just separate commands to make it easy to make and use.

    input:
    only numbers: 0 1 2 3 4 5 6 7 8 9
    only numbers and separators: 0 1 2 3 4 5 6 7 8 9 , .
    money: $ 0 1 2 3 4 5 6 7 8 9 , . the dollar sign could be also for Euro and other currency symbols
    input only phone numbers (012) 345-6789

    Well you get the idea. Good recommendation Sandy, Eros will make something awesome when he has the time you can count on that!!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: input filtering

    To start, you can already use VERIFY function to test if input string contains only the chars you want.

    VERIFY returns zero if each character in MainString is present in MatchString. If not, it returns the position of the first non-matching character in MainString.

    [code=thinbasic]
    DIM lPos AS LONG
    '---returns 4 since "." is not in "0123456789"
    lPos = VERIFY("123.65,22.5", "0123456789")

    [/code]

    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

  5. #5
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: input filtering

    Wow, that is perfect then. Very flexible way to handle it!!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. input
    By lydia_sp in forum thinBasic General
    Replies: 7
    Last Post: 20-08-2009, 12:58

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
  •