dcsimg
Results 1 to 4 of 4
  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    14

    Resolved [RESOLVED] Get a part of the number in the textbox

    hi all dears
    We have 15 numbers in the textbox
    We want to save the seventh and eighth numbers in the variable.
    Numbers are different
    I use this command:
    Code:
            Dim num As Long
            num = textbox1.Text
            Dim out As String
            out = Mid(num, 7, 8)
            MessageBox.Show(out)
    But this command shows after the seventh number
    For example, if our numbers are 365478013265478
    We only want to print the seventh and eighth digits, 01...

    But our commands after the seventh number shows everything
    Output means this is 013265478

    How can we print only seventh and eighth numbers?

    Thanks

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

    Re: Get a part of the number in the textbox

    A TextBox contains a String. Even if that String contains digits, it's still a String. Assuming that you have already validated the contents of the TextBox, i.e. that it is the correct length and that it is all digits:
    vb.net Code:
    1. Dim part = TextBox1.Text.Substring(6, 2)
    2.  
    3. MessageBox.Show(part)
    That will geta substring, i.e. part of a String, that starts at index 6, i.e. at the seventh character, and of length 2.
    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

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    14

    Re: Get a part of the number in the textbox

    Quote Originally Posted by jmcilhinney View Post
    A TextBox contains a String. Even if that String contains digits, it's still a String. Assuming that you have already validated the contents of the TextBox, i.e. that it is the correct length and that it is all digits:
    vb.net Code:
    1. Dim part = TextBox1.Text.Substring(6, 2)
    2.  
    3. MessageBox.Show(part)
    That will geta substring, i.e. part of a String, that starts at index 6, i.e. at the seventh character, and of length 2.
    Thanks dear
    The problem was solved.

  4. #4
    PowerPoster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,093

    Re: Get a part of the number in the textbox

    Near the top of the forum towards the right is a drop down called "Thread Tools". It has an option to mark the thread resolved. If you mark this resolved it will save people that want to help from looking at something that was solved already.
    Please remember next time...elections matter!

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


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.