Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. ASAP How to create Strings/SubStrings

ASAP How to create Strings/SubStrings

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    justmeTW
    wrote on last edited by
    #1

    How do you create a string with 3 substrings to validate a telephone number. I know I can use the MaskEdit tool but I can't in this program. I have to use the IsNumeric function to determine is the textbox has the correct data. The telephone number is in the format of 999-999-9999, where 9 is represented by any number. I have to create 3 substrings for each part of the number. Also when I click on my button to exe the IsNumeric function I get my error message I created "Please enter a numeric value" because the dashes are not a number, how do I stop the error message without removing the IsNumeric function. HELP PLEASE ASAP Thanks in advance

    C 1 Reply Last reply
    0
    • J justmeTW

      How do you create a string with 3 substrings to validate a telephone number. I know I can use the MaskEdit tool but I can't in this program. I have to use the IsNumeric function to determine is the textbox has the correct data. The telephone number is in the format of 999-999-9999, where 9 is represented by any number. I have to create 3 substrings for each part of the number. Also when I click on my button to exe the IsNumeric function I get my error message I created "Please enter a numeric value" because the dashes are not a number, how do I stop the error message without removing the IsNumeric function. HELP PLEASE ASAP Thanks in advance

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      myString.Split('-') will return an array of strings. In the case of a valid phone number it will be three strings. You can then do your IsNumeric test on each of the three strings. --Colin Mackay--

      "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

      J 1 Reply Last reply
      0
      • C Colin Angus Mackay

        myString.Split('-') will return an array of strings. In the case of a valid phone number it will be three strings. You can then do your IsNumeric test on each of the three strings. --Colin Mackay--

        "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

        J Offline
        J Offline
        justmeTW
        wrote on last edited by
        #3

        How do you create the string and substrings for a valid entry?

        C J 2 Replies Last reply
        0
        • J justmeTW

          How do you create the string and substrings for a valid entry?

          J Offline
          J Offline
          justmeTW
          wrote on last edited by
          #4

          This is the code I have but I'm not getting the output correct. What am I doing wrong? Dim MyString As String Dim intLen As Integer MyString = (999 - 999 - 9999) MyString.Substring(0, 2) MyString.Substring(4, 6) MyString.Substring(8, 11) intLen = Len(MyString) If IsNumeric(MyString.Substring(0, 2)) = False Then txtTel.Text = Nothing txtTel.Focus() MsgBox("Please enter a numeric value") End If If IsNumeric(MyString.Substring(4, 6)) = False Then txtTel.Text = Nothing txtTel.Focus() MsgBox("Please enter a numeric value") End If If IsNumeric(MyString.Substring(8, 11)) = False Then txtTel.Text = Nothing txtTel.Focus() MsgBox("Please enter a numeric value") End If What am I not doing right?

          C 1 Reply Last reply
          0
          • J justmeTW

            How do you create the string and substrings for a valid entry?

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            String handling is one of the most basic parts of programming. Either you need more time to learn the basics i.e. sit down with a book that will take you step-by-step through each basic aspect of programming. Or, if do know how to program already, then you need to phrase your question better because I have no idea what you mean. --Colin Mackay--

            "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

            J 1 Reply Last reply
            0
            • J justmeTW

              This is the code I have but I'm not getting the output correct. What am I doing wrong? Dim MyString As String Dim intLen As Integer MyString = (999 - 999 - 9999) MyString.Substring(0, 2) MyString.Substring(4, 6) MyString.Substring(8, 11) intLen = Len(MyString) If IsNumeric(MyString.Substring(0, 2)) = False Then txtTel.Text = Nothing txtTel.Focus() MsgBox("Please enter a numeric value") End If If IsNumeric(MyString.Substring(4, 6)) = False Then txtTel.Text = Nothing txtTel.Focus() MsgBox("Please enter a numeric value") End If If IsNumeric(MyString.Substring(8, 11)) = False Then txtTel.Text = Nothing txtTel.Focus() MsgBox("Please enter a numeric value") End If What am I not doing right?

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              justmeTW wrote: I'm not getting the output correct. What am I doing wrong? What output are you getting? justmeTW wrote: MyString = (999 - 999 - 9999) I'm guessing that the quotes are missing here, but are actually there in the real code. justmeTW wrote: MyString.Substring(0, 2) MyString.Substring(4, 6) MyString.Substring(8, 11) This doesn't do anything useful. It wastes processor time because the substring operation is carried out, but the result is thrown away as you don't assign it to any variable. I'm assuming that Substring() takes the start and end index. I'm also assuming that IsNumeric() takes a string and not an individual character. Can you confirm these assumptions? justmeTW wrote: txtTel.Text = Nothing txtTel.Focus() If the user gets it wrong, by all means, focus on the control, but don't delete the text - What if the user just mistyped one character? Do they want to have to type it all in again, or just correct the erroneous character? These should help debug your code. --Colin Mackay--

              "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

              1 Reply Last reply
              0
              • C Colin Angus Mackay

                String handling is one of the most basic parts of programming. Either you need more time to learn the basics i.e. sit down with a book that will take you step-by-step through each basic aspect of programming. Or, if do know how to program already, then you need to phrase your question better because I have no idea what you mean. --Colin Mackay--

                "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

                J Offline
                J Offline
                justmeTW
                wrote on last edited by
                #7

                I'm in a Programming class that is suppose to be step-by-step, but it's not, that is why I am having so much difficulty. Colin wrote:What output are you getting? When I type in a letter char I'm suppose to get a error message, if I just use the following code it works: If IsNumeric(txtTel.Text) = False then txtTel.Text = Nothing txtTel.Focus msgbox("Please enter a numeric value") end if Is works as long as I don't have the dashes in the text box. What my assignment calls for is to create a string for the phone number 999-999-9999 then create 3 substrings for each part of the orginal string (999-999-9999). The first substring should be "999", second substring "999" and third substring "9999" but my book doesnt explain how to create the substrings. I have search throught the VB help and every other resource I have found, but still don't understand how to create the substrings and then use them for the IsNumeric function. Colin wrote: If the user gets it wrong, by all means, focus on the control, but don't delete the text - What if the user just mistyped one character? Do they want to have to type it all in again, or just correct the erroneous character. If the input is not valid I am to clear the textbox and set focus back to it and have then re-enter the phone number. That is why I did it that way, it's part of the assignment. I know there is a way to have the error part to be selected instead of the whole thing but right now I am just trying to get the required part done and understand how to do it. My main problem is with creating the substrings and how to get the IsNumeric function to skip the dashes and only read the numbers.

                J 1 Reply Last reply
                0
                • J justmeTW

                  I'm in a Programming class that is suppose to be step-by-step, but it's not, that is why I am having so much difficulty. Colin wrote:What output are you getting? When I type in a letter char I'm suppose to get a error message, if I just use the following code it works: If IsNumeric(txtTel.Text) = False then txtTel.Text = Nothing txtTel.Focus msgbox("Please enter a numeric value") end if Is works as long as I don't have the dashes in the text box. What my assignment calls for is to create a string for the phone number 999-999-9999 then create 3 substrings for each part of the orginal string (999-999-9999). The first substring should be "999", second substring "999" and third substring "9999" but my book doesnt explain how to create the substrings. I have search throught the VB help and every other resource I have found, but still don't understand how to create the substrings and then use them for the IsNumeric function. Colin wrote: If the user gets it wrong, by all means, focus on the control, but don't delete the text - What if the user just mistyped one character? Do they want to have to type it all in again, or just correct the erroneous character. If the input is not valid I am to clear the textbox and set focus back to it and have then re-enter the phone number. That is why I did it that way, it's part of the assignment. I know there is a way to have the error part to be selected instead of the whole thing but right now I am just trying to get the required part done and understand how to do it. My main problem is with creating the substrings and how to get the IsNumeric function to skip the dashes and only read the numbers.

                  J Offline
                  J Offline
                  justmeTW
                  wrote on last edited by
                  #8

                  Colin wrote: If the user gets it wrong, by all means, focus on the control, but don't delete the text - What if the user just mistyped one character? Do they want to have to type it all in again, or just correct the erroneous character. If the input is not valid I am to clear the textbox and set focus back to it and have then re-enter the phone number. That is why I did it that way, it's part of the assignment. I know there is a way to have the error part to be selected instead of the whole thing but right now I am just trying to get the required part done and understand how to do it. My main problem is with creating the substrings and how to get the IsNumeric function to skip the dashes and only read the numbers. I forgot to add that it only clears the box if the txtTel.Text is a letter char, if it is a number is won't clear it.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups