P
Patrick Sullivan
I was having hell trying to get values like 6.50 to return two ints, a = 6
and b = 50.
The data is from a program that uses nn.nn for a time format in hours and
minutes. But 6.50 in decimal would be 6 hours and 30 minutes, not 6 hours
and fifty minutes. I don't know if anyone can use this, but here it is.
Private Function DecToInt(ByVal str As String) As String
Dim c As Integer = 0
Dim lCharacters As Char() = str.ToCharArray()
Dim lNumber As System.Text.StringBuilder = New System.Text.StringBuilder
Do While lCharacters(c) >= "0" And lCharacters(c) <= "9"
lNumber.Append(lCharacters(c))
c += 1
Loop
If lNumber.Length > 0 Then
Return lNumber.ToString
End If
Return "0"
End Function
Private Sub FillInput()
txtName.Text = lstNames.SelectedItem
Dim i As Short
Try
Dim sr As StreamReader = New StreamReader("Names.txt")
Dim line As String
Dim strFileItem As String
Do Until strFileItem = txtName.Text
line = sr.ReadLine()
strFileItem = line.Substring(0, (line.IndexOf(",")))
Loop
' "Patrick Sullivan,04 Feb 1951,6.50,A,6,091.09,30.27" sample data
Dim fields() As String
fields = line.Split(",")
sr.Close()
dtpDate.Value = fields(1).ToString
Dim strValue As String = fields(2).ToString
Dim intDecPlace = strValue.IndexOf(".")
nupdHour.Value = DecToInt(strValue)
nupdMinute.Value = strValue.Substring(intDecPlace + 1, 2)
nupdTZ.Value = fields(4).ToString
txtLongitude.Text = fields(5).ToString
txtLatitude.Text = fields(6).ToString
Catch E As Exception
MsgBox(E.Message)
End Try
End Sub
and b = 50.
The data is from a program that uses nn.nn for a time format in hours and
minutes. But 6.50 in decimal would be 6 hours and 30 minutes, not 6 hours
and fifty minutes. I don't know if anyone can use this, but here it is.
Private Function DecToInt(ByVal str As String) As String
Dim c As Integer = 0
Dim lCharacters As Char() = str.ToCharArray()
Dim lNumber As System.Text.StringBuilder = New System.Text.StringBuilder
Do While lCharacters(c) >= "0" And lCharacters(c) <= "9"
lNumber.Append(lCharacters(c))
c += 1
Loop
If lNumber.Length > 0 Then
Return lNumber.ToString
End If
Return "0"
End Function
Private Sub FillInput()
txtName.Text = lstNames.SelectedItem
Dim i As Short
Try
Dim sr As StreamReader = New StreamReader("Names.txt")
Dim line As String
Dim strFileItem As String
Do Until strFileItem = txtName.Text
line = sr.ReadLine()
strFileItem = line.Substring(0, (line.IndexOf(",")))
Loop
' "Patrick Sullivan,04 Feb 1951,6.50,A,6,091.09,30.27" sample data
Dim fields() As String
fields = line.Split(",")
sr.Close()
dtpDate.Value = fields(1).ToString
Dim strValue As String = fields(2).ToString
Dim intDecPlace = strValue.IndexOf(".")
nupdHour.Value = DecToInt(strValue)
nupdMinute.Value = strValue.Substring(intDecPlace + 1, 2)
nupdTZ.Value = fields(4).ToString
txtLongitude.Text = fields(5).ToString
txtLatitude.Text = fields(6).ToString
Catch E As Exception
MsgBox(E.Message)
End Try
End Sub