Formating Dates

Formating dates from a file...

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

43 Replies - 2865 Views - Last Post: 30 July 2008 - 12:30 AM Rate Topic: -----

#1 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Formating Dates

Post icon  Posted 29 July 2008 - 02:05 AM

Still working on this lottery project. The dates are being read from a excel file that does show the lottery numbers. (If file is needed, let me know) I started over as I don't think I was on the right track. I'm making a new form that will display the numbers, seeing how the form I was given didn't have that option. That way I'll know if it works or not. Dates need to be formatted from this: 27-Sept-07 to this: 09-27-07. Here's the code I have right now.


Option Explicit On
Option Strict On

Public Class MainForm
	Structure strLotteryDraws

		Public lotterydate As Date
		Public num1 As String
		Public num2 As String
		Public num3 As String
		Public num4 As String
		Public num5 As String

		Public LotteryDraws As ArrayList

	End Structure
	

	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub

	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		' displays the dates stored in a sequential access file

		Dim tmpDraws As strLotteryDraws
		Dim lottery As String

		If My.Computer.FileSystem.FileExists("fantasyfive.csv") Then
			lottery = _
			My.Computer.FileSystem.ReadAllText("fantasyfive.csv")

		Else
			MessageBox.Show("File does not exist", "Dates", _
			MessageBoxButtons.OK, MessageBoxIcon.Information)

		End If

		Dim i As Integer
		Dim j As Integer = 1
		Dim slotNum As String

		For i = 0 To lottery.Length - 1<---says 'lottery' not declared(green line)
			slotNum = lottery.Substring(i, 1)

			If lottery.Substring(i, 1) < "0" Or lottery.Substring(i) > "9" Then
				i = i + 1

			Else
				Select Case j
					Case 1
						tmpDraws.lotterydate = CDate(lottery.Substring(i - 1, 9))
						j = j + 1
						i = i + 9

					Case 2
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num1 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num1 = lottery.Substring(i, 2)
							i = i + 2
						End If
						j = j + 1

					Case 3
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num2 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num2 = lottery.Substring(i, 2)

						End If
						j = j + 1
					Case 4
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num3 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num3 = lottery.Substring(i, 2)
							i = i + 2

						End If
						j = j + 1

					Case 5
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num4 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num4 = lottery.Substring(i, 2)
							i = i + 2

						End If
						j = j + 1

					Case 6
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num5 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num5 = lottery.Substring(i, 2)
							i = i + 2

						End If
						j = 1

				End Select
			End If

			xDatesLabel.Text = tmpDraws.lotterydate.ToString


		Next i
	  
	End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Formating Dates

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,410
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 02:13 AM

Usually best practice when defining a string to assign it a value
eg
Dim MyString as String=""


In your code

Option Explicit On
Option Strict On

Public Class MainForm
	Structure strLotteryDraws

		Public lotterydate As Date
		Public num1 As String=""
		Public num2 As String=""
		Public num3 As String=""
		Public num4 As String=""
		Public num5 As String=""

		Public LotteryDraws As ArrayList

	End Structure
	

	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub

	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		' displays the dates stored in a sequential access file

		Dim tmpDraws As strLotteryDraws
		Dim lottery As String="" 'Try adding this.

		If My.Computer.FileSystem.FileExists("fantasyfive.csv") Then
			lottery = _
			My.Computer.FileSystem.ReadAllText("fantasyfive.csv")

		Else
			MessageBox.Show("File does not exist", "Dates", _
			MessageBoxButtons.OK, MessageBoxIcon.Information)
' Added this as I think you don't want the next section of code to run if the file isn't found
Exit Sub

		End If

		Dim i As Integer
		Dim j As Integer = 1
		Dim slotNum As String

		For i = 0 To lottery.Length - 1'<---says 'lottery' not declared(green line)
			slotNum = lottery.Substring(i, 1)

			If lottery.Substring(i, 1) < "0" Or lottery.Substring(i) > "9" Then
				i = i + 1

			Else
				Select Case j
					Case 1
						tmpDraws.lotterydate = CDate(lottery.Substring(i - 1, 9))
						j = j + 1
						i = i + 9

					Case 2
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num1 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num1 = lottery.Substring(i, 2)
							i = i + 2
						End If
						j = j + 1

					Case 3
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num2 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num2 = lottery.Substring(i, 2)

						End If
						j = j + 1
					Case 4
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num3 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num3 = lottery.Substring(i, 2)
							i = i + 2

						End If
						j = j + 1

					Case 5
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num4 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num4 = lottery.Substring(i, 2)
							i = i + 2

						End If
						j = j + 1

					Case 6
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num5 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num5 = lottery.Substring(i, 2)
							i = i + 2

						End If
						j = 1

				End Select
			End If

			xDatesLabel.Text = tmpDraws.lotterydate.ToString


		Next i
	  
	End Sub
End Class


This post has been edited by AdamSpeight2008: 29 July 2008 - 02:16 AM

Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,410
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 02:32 AM

The following code simplifies the act of reading in the data contain in csv file, which what I think you're trying to do.

Public Class Form1

    Dim Lottos As New List(Of Lotto)
 
    Private Structure Lotto
        Public Datum As String
        Public Number() As Integer
    End Structure

' csv file Format
' Date , Number 1, Number 2,Number 3, Number 4, Number 5
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Prepare file to be parsed        
 Dim Delimiters() As Char = {","}
 Dim tfp As Microsoft.VisualBasic.FileIO.TextFieldParser = My.Computer.FileSystem.OpenTextFieldParser("fantasyfive.csv", Delimiters)
 ' List to contain read in lottos
  Dim NewLotto As Lotto
  Dim Fields() As String
  While tfp.EndOfData = False
     NewLotto = New Lotto
     Fields = tfp.ReadFields
' The Fields array now contains the following data
' Fields(0)  => The Date
' Fields(1) => Number 1
' Fields(2) => Number 2
' Fields(3) => Number 3
' Fields(4) => Number 4
' Fields(5) => Number 5
     NewLotto.Datum =  CDate(Fields(0)).ToString("MM dd yyyy")' Converts Date to correct Format as well
     ReDim NewLotto.Number(4)
     For i As Integer = 1 To 5
       NewLotto.Number(i - 1) = CInt(Fields(i))
     Next
' Sort the number
Array.Sort(NewLotto.Number)
' Add it to the collection of other lottos
     Lottos.Add(NewLotto)
   End While
   tfp.Close()
  End Sub
End Class


This post has been edited by AdamSpeight2008: 29 July 2008 - 02:58 AM

Was This Post Helpful? 0
  • +
  • -

#4 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Formating Dates

Posted 29 July 2008 - 03:59 AM

Not sure what was meant by or where to add: 'Dim MyString as String = "". Have error:


Option Explicit On
Option Strict On

Public Class MainForm
	Structure strLotteryDraws

		Public lotterydate As Date
		Public num1 As String = ""
		Public num2 As String = ""
		Public num3 As String = ""<---errors here with all Num1-5 says 'Initializers on structure members are valid only for 'Shared' members and constants.	
Public num4 As String = ""
		Public num5 As String = ""

		Public LotteryDraws As ArrayList

	End Structure
  
	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub
	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		' displays the dates stored in a sequential access file  

		Dim tmpDraws As strLotteryDraws
		Dim lottery As String = ""

		If My.Computer.FileSystem.FileExists("fantasyfive.csv") Then
			lottery = _
			My.Computer.FileSystem.ReadAllText("fantasyfive.csv")

		Else
			MessageBox.Show("File does not exist", "Dates", _
			MessageBoxButtons.OK, MessageBoxIcon.Information)
			' Added this as I think you don't want the next section of code to run if the file isn't found  
			Exit Sub

		End If

		Dim i As Integer
		Dim j As Integer = 1
		Dim slotNum As String

		For i = 0 To lottery.Length - 1
			slotNum = lottery.Substring(i, 1)

			If lottery.Substring(i, 1) < "0" Or lottery.Substring(i) > "9" Then
				i = i + 1

			Else
				Select Case j
					Case 1
						tmpDraws.lotterydate = CDate(lottery.Substring(i - 1, 9))
						j = j + 1
						i = i + 9

					Case 2
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num1 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num1 = lottery.Substring(i, 2)
							i = i + 2
						End If
						j = j + 1

					Case 3
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num2 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num2 = lottery.Substring(i, 2)

						End If
						j = j + 1
					Case 4
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num3 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num3 = lottery.Substring(i, 2)
							i = i + 2

						End If
						j = j + 1

					Case 5
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num4 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num4 = lottery.Substring(i, 2)
							i = i + 2

						End If
						j = j + 1

					Case 6
						If lottery.Substring(i + 1) = "," Then
							tmpDraws.num5 = lottery.Substring(i)
							i = i + 1

						Else
							tmpDraws.num5 = lottery.Substring(i, 2)
							i = i + 2

						End If
						j = 1

				End Select
			End If

			xDatesLabel.Text = tmpDraws.lotterydate.ToString


		Next i

	End Sub
End Class




Also another error: Event 'Load' cannot be found, in fantasyfive.vb?


Public Class fantasyfive

	Dim Lottos As New List(Of Lotto)

	Private Structure Lotto
		Public Datum As String
		Public Number() As Integer
	End Structure

	' csv file Format  
	' Date , Number 1, Number 2,Number 3, Number 4, Number 5  
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		' Prepare file to be parsed		  
		Dim Delimiters() As Char = CType((","), Char())<--had to tweak this
		Dim tfp As Microsoft.VisualBasic.FileIO.TextFieldParser = My.Computer.FileSystem.OpenTextFieldParser("fantasyfive.csv", Delimiters)
		' List to contain read in lottos  
		Dim NewLotto As Lotto
		Dim Fields() As String
		While tfp.EndOfData = False
			NewLotto = New Lotto
			Fields = tfp.ReadFields
			' The Fields array now contains the following data  
			' Fields(0)  => The Date  
			' Fields(1) => Number 1  
			' Fields(2) => Number 2  
			' Fields(3) => Number 3  
			' Fields(4) => Number 4  
			' Fields(5) => Number 5  
			NewLotto.Datum = CDate(Fields(0)).ToString("MM dd yyyy") ' Converts Date to correct Format as well  
			ReDim NewLotto.Number(4)
			For i As Integer = 1 To 5
				NewLotto.Number(i - 1) = CInt(Fields(i))
			Next
			' Sort the number  
			Array.Sort(NewLotto.Number)
			' Add it to the collection of other lottos  
			Lottos.Add(NewLotto)
		End While
		tfp.Close()
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,410
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 04:01 AM

remove ="" from the structure definition.


Option Explicit On
Option Strict On

Public Class MainForm
	Structure strLotteryDraws

		Public lotterydate As Date
		Public num1 As String
		Public num2 As String 
		Public num3 As String 	
Public num4 As String 
		Public num5 As String 

		Public LotteryDraws As ArrayList

	End Structure
  



Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,410
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 04:11 AM

Could you attach the file as well.
Was This Post Helpful? 0
  • +
  • -

#7 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Formating Dates

Posted 29 July 2008 - 04:14 AM

View PostAdamSpeight2008, on 29 Jul, 2008 - 07:01 AM, said:

remove ="" from the structure definition.


Option Explicit On
Option Strict On

Public Class MainForm
	Structure strLotteryDraws

		Public lotterydate As Date
		Public num1 As String
		Public num2 As String 
		Public num3 As String 	
				Public num4 As String 
		Public num5 As String 

		Public LotteryDraws As ArrayList

	End Structure
  




:) Okay that worked. Said there was build errors, yet didn't show anything. It read at the bottom that it could find the 'Load Event' which I assume is from the other error I mentioned.
Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,410
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 04:15 AM

Should have been, sorry

Option Explicit On
Option Strict On

Public Class MainForm
'	Structure strLotteryDraws
'		Public lotterydate As Date
'		Public num1 As String 
'		Public num2 As String 
'		Public num3 As String
'Public num4 As String 
'		Public num5 As String 
'		Public LotteryDraws As ArrayList
'	End Structure

	  Dim Lottos As New List(Of Lotto)

	Private Structure Lotto
		Public Datum As String
		Public Number() As Integer
	End Structure

	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub
	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		' displays the dates stored in a sequential access file  

		Dim tmpDraws As strLotteryDraws
		Dim lottery As String = ""

		If My.Computer.FileSystem.FileExists("fantasyfive.csv") Then
			lottery = _
			My.Computer.FileSystem.ReadAllText("fantasyfive.csv")

		Else
			MessageBox.Show("File does not exist", "Dates", _
			MessageBoxButtons.OK, MessageBoxIcon.Information)
			' Added this as I think you don't want the next section of code to run if the file isn't found  
			Exit Sub

		End If

	' csv file Format  
	' Date , Number 1, Number 2,Number 3, Number 4, Number 5  
		' Prepare file to be parsed		  
		Dim Delimiters() As Char = Dim Delimiters() As Char = {CChar(",")} 'Should be this
		Dim tfp As Microsoft.VisualBasic.FileIO.TextFieldParser = My.Computer.FileSystem.OpenTextFieldParser("fantasyfive.csv", Delimiters)
		' List to contain read in lottos  
		Dim NewLotto As Lotto
		Dim Fields() As String
		While tfp.EndOfData = False
			NewLotto = New Lotto
			Fields = tfp.ReadFields
			' The Fields array now contains the following data  
			' Fields(0)  => The Date  
			' Fields(1) => Number 1  
			' Fields(2) => Number 2  
			' Fields(3) => Number 3  
			' Fields(4) => Number 4  
			' Fields(5) => Number 5  
			NewLotto.Datum = CDate(Fields(0)).ToString("MM dd yyyy") ' Converts Date to correct Format as well  
			ReDim NewLotto.Number(4)
			For i As Integer = 1 To 5
				NewLotto.Number(i - 1) = CInt(Fields(i))
			Next
			' Sort the number  
			Array.Sort(NewLotto.Number)
			' Add it to the collection of other lottos  
			Lottos.Add(NewLotto)
		End While
		tfp.Close()
' show date
		  xDatesLabel.Text = Lottos(0).datum

	End Sub
	
End Class


This post has been edited by AdamSpeight2008: 29 July 2008 - 04:21 AM

Was This Post Helpful? 0
  • +
  • -

#9 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Formating Dates

Posted 29 July 2008 - 04:19 AM

Hold on a bit for file, have to get it somewhere else...Not adding it here..

This post has been edited by LadyWolf: 29 July 2008 - 04:23 AM

Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,410
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 04:23 AM

View PostLadyWolf, on 29 Jul, 2008 - 12:19 PM, said:

Here's the file.

It's not attached, doh!
Was This Post Helpful? 0
  • +
  • -

#11 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Formating Dates

Posted 29 July 2008 - 04:49 AM

View PostAdamSpeight2008, on 29 Jul, 2008 - 07:23 AM, said:

View PostLadyWolf, on 29 Jul, 2008 - 12:19 PM, said:

Here's the file.

It's not attached, doh!


:wub: Sorry wouldn't attach for some reason.
Attached File  fantasyfive.txt (39.99K)
Number of downloads: 84

View PostLadyWolf, on 29 Jul, 2008 - 07:47 AM, said:

View PostAdamSpeight2008, on 29 Jul, 2008 - 07:23 AM, said:

View PostLadyWolf, on 29 Jul, 2008 - 12:19 PM, said:

Here's the file.

It's not attached, doh!


:wub: Sorry wouldn't attach for some reason.
Attachment attachment


I sent as a txt file though when coding it's an csv file.
Was This Post Helpful? 0
  • +
  • -

#12 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Formating Dates

Posted 29 July 2008 - 05:48 AM

View PostLadyWolf, on 29 Jul, 2008 - 07:49 AM, said:

View PostAdamSpeight2008, on 29 Jul, 2008 - 07:23 AM, said:

View PostLadyWolf, on 29 Jul, 2008 - 12:19 PM, said:

Here's the file.

It's not attached, doh!


:wub: Sorry wouldn't attach for some reason.
Attachment attachment

View PostLadyWolf, on 29 Jul, 2008 - 07:47 AM, said:

View PostAdamSpeight2008, on 29 Jul, 2008 - 07:23 AM, said:

View PostLadyWolf, on 29 Jul, 2008 - 12:19 PM, said:

Here's the file.

It's not attached, doh!


:wub: Sorry wouldn't attach for some reason.
Attachment attachment


I sent as a txt file though when coding it's an csv file, even though it looks like a txt file when I 'Open file'. Not sure if that is normal.

Don't need to add lottery numbers, only read what's in the file..and display the formatted dates in the xDatesLabel, and the lottery numbers from file to the xLotteryLabel.

Was This Post Helpful? 0
  • +
  • -

#13 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Formating Dates

Posted 29 July 2008 - 06:16 AM

mmmmmmm


Public Class MainForm

	Dim Lottos As New List(Of Lotto)

	Private Structure Lotto
		Public Datum As String
		Public Number() As Integer
	End Structure

	' csv file Format  
	' Date , Number 1, Number 2,Number 3, Number 4, Number 5

	Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		' Prepare file to be parsed		  
		Dim Delimiters() As Char = CType((","), Char())
		Dim tfp As Microsoft.VisualBasic.FileIO.TextFieldParser = My.Computer.FileSystem.OpenTextFieldParser("fantasyfive.csv", Delimiters)
		' List to contain read in lottos  
		Dim NewLotto As Lotto
		Dim Fields() As String
		While tfp.EndOfData = False
			NewLotto = New Lotto
			Fields = tfp.ReadFields
			' The Fields array now contains the following data  
			' Fields(0)  => The Date  
			' Fields(1) => Number 1  
			' Fields(2) => Number 2  
			' Fields(3) => Number 3  
			' Fields(4) => Number 4  
			' Fields(5) => Number 5  
			NewLotto.Datum = CDate(Fields(0)).ToString("mm dd yyyy")
'Converts Date to correct Format as well <--error here says 'Conversion from string "Sun." to type 'Date' is not valid.' 
			ReDim NewLotto.Number(4)
			For i As Integer = 1 To 5
				NewLotto.Number(i - 1) = CInt(Fields(i))
			Next
			' Sort the number  
			Array.Sort(NewLotto.Number)
			' Add it to the collection of other lottos  
			Lottos.Add(NewLotto)
		End While
		tfp.Close()
	End Sub
End Class



There's days of the week in the file also.
Was This Post Helpful? 0
  • +
  • -

#14 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Formating Dates

Posted 29 July 2008 - 11:32 AM

Going to give this a break for awhile :crazy:
Was This Post Helpful? 0
  • +
  • -

#15 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,410
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 05:05 PM

Displays dates in label and also in a listbox (which I added).
Selecting a date displays the lotto numbers for that date,
    Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
        ' Prepare file to be parsed          
        Dim Delimiters() As Char = {CChar(",")}
        Dim tfp As Microsoft.VisualBasic.FileIO.TextFieldParser = My.Computer.FileSystem.OpenTextFieldParser("fantasyfive.txt", Delimiters)
        ' List to contain read in lottos  
        Dim NewLotto As Lotto
' Define stringBuild to speed up the building of the string.
        Dim listText As New System.Text.StringBuilder
        Dim Fields() As String
        While tfp.EndOfData = False
            NewLotto = New Lotto
            Fields = tfp.ReadFields
            ' The Fields array now contains the following data  
            ' Fields(0) => The Day  
            ' Fields(1) => The Date
            ' Fields(2) => Number 1  
            ' Fields(3) => Number 2  
            ' Fields(4) => Number 3  
            ' Fields(5) => Number 4  
            ' Fields(6) => Number 5  

            NewLotto.Datum = CDate(Fields(1)).ToString("MM dd yyyy") ' The format extension is Case-sensitive.
              ReDim NewLotto.Number(4)
            For i As Integer = 1 To 5
                NewLotto.Number(i - 1) = CInt(Fields(i + 1))
            Next
            ' Sort the number  
            Array.Sort(NewLotto.Number)
            ' Add it to the collection of other lottos  
            Lottos.Add(NewLotto)
            listText.AppendLine(Lottos(Lottos.Count - 1).Datum)
' add listbox
            Me.ListBox1.Items.Add(Lottos(Lottos.Count - 1).Datum)
        End While
        Me.xDatesLabel.Text = listText.ToString
        tfp.Close()
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        If Me.ListBox1.SelectedIndex <> -1 Then
            Me.xLbl_Lotto.Text = _
            Lottos(Me.ListBox1.SelectedIndex).Number(0) & " " & _
            Lottos(Me.ListBox1.SelectedIndex).Number(1) & " " & _
            Lottos(Me.ListBox1.SelectedIndex).Number(2) & " " & _
            Lottos(Me.ListBox1.SelectedIndex).Number(3) & " " & _
            Lottos(Me.ListBox1.SelectedIndex).Number(4)

        End If
    End Sub


Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3