Results 1 to 6 of 6

Thread: [RESOLVED] MaxLenght Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2012
    Posts
    11

    Resolved [RESOLVED] MaxLenght Help

    The MaxLength works for inpu but not for output as discussed here: https://stackoverflow.com/questions/...gth-for-output . How can I limit the digit numbers in a textbox?

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,042

    Re: MaxLenght Help

    Hi,

    ist it this your after..

    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim MeineZahl As Double
    
            MeineZahl = 0.129456789
            TextBox1.Text = MeineZahl.ToString("0.##")
    
            MeineZahl = 2.555
            TextBox2.Text = MeineZahl.ToString("0.##")
        End Sub
    regards
    Chris

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2012
    Posts
    11

    Re: MaxLenght Help

    Quote Originally Posted by ChrisE View Post
    Hi,

    ist it this your after..

    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim MeineZahl As Double
    
            MeineZahl = 0.129456789
            TextBox1.Text = MeineZahl.ToString("0.##")
    
            MeineZahl = 2.555
            TextBox2.Text = MeineZahl.ToString("0.##")
        End Sub
    regards
    Chris
    Thanks for your reply. I don't use button click, its dynamic. As soon as you type in numbers the calculator outputs the result. So if your result is "01234567890123456789" it should become -> "0123456789" only 10 digits.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: MaxLenght Help

    ChrisE just put the code in a button as an example, you can use the same code in any event you like (in this case, where your calculator sets the value of the textbox).

    In terms of truncating to a certain number of characters, you can do this:
    Code:
    If TextBox1.Text.Length > 10 Then TextBox1.Text = TextBox1.Text.SubString(0,10)

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2012
    Posts
    11

    Wink Re: MaxLenght Help

    Quote Originally Posted by si_the_geek View Post
    ChrisE just put the code in a button as an example, you can use the same code in any event you like (in this case, where your calculator sets the value of the textbox).

    In terms of truncating to a certain number of characters, you can do this:
    Code:
    If TextBox1.Text.Length > 10 Then TextBox1.Text = TextBox1.Text.SubString(0,10)
    Works like a charm! Thanks.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: MaxLenght Help

    No problem


    As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
    (this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)

    You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width