Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
Dim strType As String = Field1.Text(0)
Dim strYear As String = Field1.Text(2)
Dim strMonth As String = Field1.Text(1)
Dim strMonth0 As String = Field1.Text(3)
Dim iFalse As String = ("If N/A then your data may be incorrect")
Select Case Field1.Text(0)
Case "F", "f"
strType = "Factory Produced in:"
Case Else
strType = "Other Produced in:"
End Select
Select Case Field1.Text(2)
Case "A", "a"
strMonth = "Jan"
Case "B", "b"
strMonth = "Feb"
Case "C", "c"
strMonth = "Mar"
Case "D", "d"
strMonth = "Apr"
Case "E", "e"
strMonth = "May"
Case "F", "f"
strMonth = "Jun"
Case "G", "g"
strMonth = "Jul"
Case "H", "h"
strMonth = "Aug"
Case "I", "i"
strMonth = "Sep"
Case "J", "j"
strMonth = "Oct"
Case "K", "k"
strMonth = "Nov"
Case "L", "l"
strMonth = "Dec"
Case "0"
strYear = "2010"
Case "1"
strYear = "2011"
Case "2"
strYear = "2012"
Case "3"
strYear = "2013"
Case Else
strMonth = "N/A"
End Select
Select Case Field1.Text(1)
Case "0"
strYear = "2000 OR 2010"
Case "1" Or Field1(2) = "2013"
strYear = "2001"
Case "2"
strYear = "2002 OR 2012"
Case "3"
strYear = "2003 OR 2013"
Case "4"
strYear = "2004"
Case "5"
strYear = "2005"
Case "6"
strYear = "2006"
Case "7"
strYear = "2007"
Case "8"
strYear = "2008"
Case "9"
strYear = "2009"
Case Else
strYear = "N/A"
End Select
Select Case Field1.Text(3)
Case "A", "a"
strMonth = "Jan"
Case "B", "b"
strMonth = "Feb"
Case "C", "c"
strMonth = "Mar"
Case "D", "d"
strMonth = "Apr"
Case "E", "e"
strMonth = "May"
Case "F", "f"
strMonth = "Jun"
Case "G", "g"
strMonth = "Jul"
Case "H", "h"
strMonth = "Aug"
Case "I", "i"
strMonth = "Sep"
Case "J", "j"
strMonth = "Oct"
Case "K", "k"
strMonth = "Nov"
Case "L", "l"
strMonth = "Dec"
End Select
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
MessageBox.Show(String.Format("{0} {1} {2}", strType, strMonth, strYear))
If strYear = "N/A" Then
MessageBox.Show(iFalse)
ElseIf strMonth = "N/A" Then
MessageBox.Show(iFalse)
End If
'F8L0038 = Factory 2008 December'
End Sub
5 Replies - 134 Views - Last Post: 30 January 2013 - 06:37 PM
#1
How can I output the correct value from a string?
Posted 30 January 2013 - 07:09 AM
So I am trying to get the correct values from this string, however some of the input varies so where F8L0000 is equal to (0)= Factory (1) = 2008 (3) = December. However I now also have the issue where some numbers are longer on the year so F13L000 Should be Factory, 2013, December. I can only get Factory, 2001, NA. I am really lost on this. what can I do to get this working correctly again?
Replies To: How can I output the correct value from a string?
#2
Re: How can I output the correct value from a string?
Posted 30 January 2013 - 07:38 AM
After reading this a LOT I think I understand what you are doing and having issues with.
F13L000 versus F8L0000
The problem is that you are harccoded your breaks at Text(0), Text(1) and so on.
I would tear the string apart based on length.
0 is your F
Length - 4 to end is your L000
Length -1 to length-4 is your 8 or 13
From *what* string? How would it normally be formatted and what would be an example of what it normally contains?
Can be made easier to read if you take your case and drop it to lower so you only have to check against one version of the letter./ Since you do this in a couple different places it is a worthwhile savings.
This is a silly long block of code when you can just take the value (what you are using in your switch and add it to 2000.
F13L000 versus F8L0000
The problem is that you are harccoded your breaks at Text(0), Text(1) and so on.
I would tear the string apart based on length.
0 is your F
Length - 4 to end is your L000
Length -1 to length-4 is your 8 or 13
Quote
So I am trying to get the correct values from this string,
From *what* string? How would it normally be formatted and what would be an example of what it normally contains?
Quote
018
Select Case Field1.Text(2)
019 Case "A", "a"
Can be made easier to read if you take your case and drop it to lower so you only have to check against one version of the letter./ Since you do this in a couple different places it is a worthwhile savings.
018
Select Case Field1.Text(2).ToLower()
019 Case "a"
Quote
Case "8" 077 Case "9" 078 strYear = "2009"
This is a silly long block of code when you can just take the value (what you are using in your switch and add it to 2000.
#3
Re: How can I output the correct value from a string?
Posted 30 January 2013 - 09:29 AM
Ok so you kinda are on to what im failing to explain, so the user inputs a serial number into a field then the app, outputs the corresponding dates.
so the variable bits are; first (will either be F or O), second (will be the year, however now I have found out that the year can be 2 digits not one like it was originally coded), third (will usually be the month which is a letter, unless it has a 2 digit year where it will be a number), and forth digit (would normally be irrelevant except if the serial has the 2 digit year, in which case it would be a letter for the month). Here are some examples: F4G0000 would be a factory model, made in 2004, G being July.
The real issue im having is that now it wont work because I need it to select the units based on what type of character the user enters? rather than what is in which character place??
I have quite clearly confused myself!
so the variable bits are; first (will either be F or O), second (will be the year, however now I have found out that the year can be 2 digits not one like it was originally coded), third (will usually be the month which is a letter, unless it has a 2 digit year where it will be a number), and forth digit (would normally be irrelevant except if the serial has the 2 digit year, in which case it would be a letter for the month). Here are some examples: F4G0000 would be a factory model, made in 2004, G being July.
The real issue im having is that now it wont work because I need it to select the units based on what type of character the user enters? rather than what is in which character place??
I have quite clearly confused myself!
This post has been edited by AdamSpeight2008: 30 January 2013 - 09:45 AM
Reason for edit:: DeQuoting Quoted Post
#4
Re: How can I output the correct value from a string?
Posted 30 January 2013 - 09:47 AM
dugzilla, on 30 January 2013 - 10:29 AM, said:
The real issue im having is that now it wont work because I need it to select the units based on what type of character the user enters? rather than what is in which character place??
Character place is fine... but you can't hardcode it. You have to calculate the position because the length is variable. I just described how to do that (but I'm not writing the code for you).
You need to calculate the string.substring from the entire string
Fx4G0000 || ||_____ Length of entire string-4 to the end || |_______ Length of entire string-5 for a length of 1 ||________Start at 2 for a length of of entire string-5 |________Position 0
This post has been edited by tlhIn`toq: 30 January 2013 - 09:48 AM
#5
Re: How can I output the correct value from a string?
Posted 30 January 2013 - 10:09 AM
You could use .TryParse against the 2nd and 3rd character. If parsed successfully then you know that you have a two digit year. If not, then you know that the 3rd character in your string is the Month
If integer.tryparse("8L") then
'it will not successfully parse
'so only take the 1st digit for the year and adjust your index accordingly for the rest of the string
else
'it did succeed
'take both of these digits for the year and adjust your index accordingly
end if
#6
Re: How can I output the correct value from a string?
Posted 30 January 2013 - 06:37 PM
CharlieMay, on 30 January 2013 - 10:09 AM, said:
You could use .TryParse against the 2nd and 3rd character. If parsed successfully then you know that you have a two digit year. If not, then you know that the 3rd character in your string is the Month
If integer.tryparse("8L") then
'it will not successfully parse
'so only take the 1st digit for the year and adjust your index accordingly for the rest of the string
else
'it did succeed
'take both of these digits for the year and adjust your index accordingly
end if
Just an alternative to CharlieMay's idea... since this is VB.NET, you can also validate with IsNumeric()
If IsNumeric("8L") Then
'Two-digit-year
Else
'One-digit-year
End If
Since in the example, the condition is false, this will output a one-digit-year which is "8".
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|