Force a way of writing-VBForums
Results 1 to 14 of 14

Thread: Force a way of writing

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    395

    Force a way of writing

    Hello VBForums
    Hello eveyone
    Gentelmans
    Please ..
    How to force to write the numbers in TextBox1 like this .. number phone:
    05 87 89 25 74 23
    Thank you in advance for help
    Cordially
    MADA

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,331

    Re: Force a way of writing

    For that format specifically, use a MaskedTextbox instead.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    546

    Re: Force a way of writing

    Lots of ways to do that. I did a Google search and found examples of formatting credit card numbers, which is a similar to what you want except you want groups of two numbers instead of four and spaces instead of dashes. Have a a try with some of those and report back if you need more help.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    395

    Re: Force a way of writing

    Hiii jmcilhinney
    Thanks for the help
    But I'm looking for a solution away from MaskedTextBox
    Cordially
    MADA

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    395

    Re: Force a way of writing

    Hiii paulg4ije
    Thank you gentelman
    Thank you very much for the help
    I will try to find a way so that the numbers in TextBox1 will be like that :
    I type 0546891238 will be automatically displayed 05 46 89 12 38
    Cordially
    MADA

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,331

    Re: Force a way of writing

    So there's a tool that does exactly what you want and you want to find a way to not use it? Suit yourself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    395

    Re: Force a way of writing

    Quote Originally Posted by jmcilhinney View Post
    So there's a tool that does exactly what you want and you want to find a way to not use it? Suit yourself.
    What is this tool please ??
    Cordially
    MADA

  8. #8
    Lively Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    75

    Re: Force a way of writing

    MaskedTextBox
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  9. #9
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,554

    Re: Force a way of writing

    JMC is pointing out MaskedTextBox is the best tool for this job.

    I don't like MaskedTextBox either, but I think he's right. I am pretty sure what you are thinking is "No, there's definitely an easy way to make a normal TextBox do this". Some smart aleck always disagrees, but no one ever remembers you have to block keystrokes AND copy/paste AND programmatic text changes. It's easier to just use the control that was built for the purpose.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,575

    Re: Force a way of writing

    There's two schools of thought... 1) used a maskedTextBox ... I'm not a fan of it either, it has its issues, but for the most part, it works. 2) you don't worry about the format during entry. You just let the user type it in how they want. When the then tab out, or the textbox looses focus, THEN you re-format it how you want. This is how we do our phone numbers. We don't make any assumptions about how they are entering it - it could be local, long distance or even international, so we wait until after entry, then look at what we have, prefixes, number of digits, and then based on that and a couple of other factors, we make an attempt at formatting it. I also ran into something similar last night with my router... it was asking for a MAC Address of somehting... but didn't give a hint as to how to enter it... so I entered it with colons... when I tabbed out, it re-formatted it to all caps and no colons. same thing.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    395

    Re: Force a way of writing

    Hello every one
    Maskedtextbox yes it's a great tool
    But I could not settle with this method of grabbing
    Cordially
    MADA

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,575

    Re: Force a way of writing

    I get it now... It should have been obvious but it wasn't, now I get it.
    Mada can only post in haiku! Or in some haiku-like form... that explains it all now..

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    395

    Re: Force a way of writing

    Thank you for help Master Techgnome
    I typed a number as an example in field Mask and after I put OK
    Name:  789.jpg
Views: 39
Size:  32.6 KB
    MADA

  14. #14
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,331

    Re: Force a way of writing

    Do what you should have done in the first place and read the documentation for the MaskedTextBox.Mask property. Not surprisingly, it explains how to set a mask properly.

    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width