ASAP How to create Strings/SubStrings
-
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
-
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
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)
-
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)
-
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?
-
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)
-
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?
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)
-
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)
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.
-
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.
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.