Formating Dates

Formating dates from a file...

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

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

#16 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:38 PM

So I need to change the Label underneath the Dates Label, to a List box..I was working on another project so it might take a bit to finish, and make the list box.


Option Explicit On
Option Strict On

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 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))<---error says 'Redim statements require a parenthesized list of the new bounds of each dimension of the array'
			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
End Class



Also, here's a screenshot of the form.

Attached File(s)

  • Attached File  Doc2.doc (88K)
    Number of downloads: 46

Was This Post Helpful? 0
  • +
  • -

#17 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:57 PM

Okay, I changed it :)


Option Explicit On
Option Strict On

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 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))<--Same error here
			For i As Integer = 1 To 5
				NewLotto.Number(i - 1) = CInt(Fields(i + 1))
			Next()<---This one says 'expression expected'

			' 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.xLotteryLabel.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.xLotteryLabel.Text = _<---Not sure if this is right..xLotteryLabel is where numbers are displayed.
			 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
End Class


This post has been edited by LadyWolf: 29 July 2008 - 07:03 PM

Was This Post Helpful? 0
  • +
  • -

#18 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 07:14 PM

Give me a mo I'll attach my project I've using during this .

Here it is (It very basic & functional)
Attached File  WindowsApplication12.zip (99.77K)
Number of downloads: 58

This post has been edited by AdamSpeight2008: 29 July 2008 - 07:12 PM

Was This Post Helpful? 0
  • +
  • -

#19 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 - 07:33 PM

View PostAdamSpeight2008, on 29 Jul, 2008 - 10:14 PM, said:

Give me a mo I'll attach my project I've using during this .

Here it is (It very basic & functional)
Attachment attachment



:^: Probablly why it's not working for me is we have a different forms going on lol. Yours looks great though. Anyway to drop the small list box and keep the rest?
Was This Post Helpful? 0
  • +
  • -

#20 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 07:40 PM

View PostLadyWolf, on 30 Jul, 2008 - 03:33 AM, said:

:^: Probablly why it's not working for me is we have a different forms going on lol. Yours looks great though. Anyway to drop the small list box and keep the rest?


Maybe possible, I need sometime to time to figure out how change the lotto numbers depending on the date selected though. (I think it possible though)
Was This Post Helpful? 0
  • +
  • -

#21 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 07:59 PM

Figured it out :^:
first Make sure that xDatesLabel is ReadOnly and has vertical scrollbars.
Remove the listbox.
Then any lines that contain references to the listbox. (the ones with the errors)

Add this event code
    Private Sub xDatesLabel_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles xDatesLabel.MouseClick
        Dim line As Integer = -1
        If e.Button = Windows.Forms.MouseButtons.Left Then
' Find out which text line the mouse click was on.
            line = Me.xDatesLabel.GetLineFromCharIndex(Me.xDatesLabel.GetCharIndexFromPosition(e.Location))
         End If
        If line <> -1 Then
' Display lotto numbers
            Me.xLbl_Lotto.Text = _
            Lottos(line).Number(0) & " " & _
            Lottos(line).Number(1) & " " & _
            Lottos(line).Number(2) & " " & _
            Lottos(line).Number(3) & " " & _
            Lottos(line).Number(4)

        End If
    End Sub


And cha-ching!(VB.Net :ph34r: )
Was This Post Helpful? 0
  • +
  • -

#22 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 - 08:00 PM

View PostAdamSpeight2008, on 29 Jul, 2008 - 10:40 PM, said:

View PostLadyWolf, on 30 Jul, 2008 - 03:33 AM, said:

:^: Probablly why it's not working for me is we have a different forms going on lol. Yours looks great though. Anyway to drop the small list box and keep the rest?


Maybe possible, I need sometime to time to figure out how change the lotto numbers depending on the date selected though. (I think it possible though)


The numbers seem fine and match the dates, as they are being read by the file, I guess I'm just a little confused about there being 2 list boxes :) I would think only one would be need for the dates.

This post has been edited by LadyWolf: 29 July 2008 - 08:04 PM

Was This Post Helpful? 0
  • +
  • -

#23 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 - 08:23 PM

Didn't see your post there, I was finding out that the Dates and numbers didn't match after all lol :)
Was This Post Helpful? 0
  • +
  • -

#24 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 08:27 PM

View PostLadyWolf, on 30 Jul, 2008 - 04:00 AM, said:

View PostAdamSpeight2008, on 29 Jul, 2008 - 10:40 PM, said:

View PostLadyWolf, on 30 Jul, 2008 - 03:33 AM, said:

:^: Probablly why it's not working for me is we have a different forms going on lol. Yours looks great though. Anyway to drop the small list box and keep the rest?


Maybe possible, I need sometime to time to figure out how change the lotto numbers depending on the date selected though. (I think it possible though)


The numbers seem fine and match the dates, as they are being read by the file, I guess I'm just a little confused about there being 2 list boxes :) I would think only one would be need for the dates.

Ones a textbox (xDatesLabel) the other a listbox. Which you choose is down to personnel preferences.
Was This Post Helpful? 0
  • +
  • -

#25 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 - 08:31 PM

View PostLadyWolf, on 29 Jul, 2008 - 11:23 PM, said:

Didn't see your post there, I was finding out that the Dates and numbers didn't match after all lol :)


Okay I'll work on it.. :)
Was This Post Helpful? 0
  • +
  • -

#26 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 - 09:13 PM

View PostAdamSpeight2008, on 29 Jul, 2008 - 10:59 PM, said:

Figured it out :^:
first Make sure that xDatesLabel is ReadOnly and has vertical scrollbars.
Remove the listbox.
Then any lines that contain references to the listbox. (the ones with the errors)

Add this event code
    Private Sub xDatesLabel_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles xDatesLabel.MouseClick
        Dim line As Integer = -1
        If e.Button = Windows.Forms.MouseButtons.Left Then
' Find out which text line the mouse click was on.
            line = Me.xDatesLabel.GetLineFromCharIndex(Me.xDatesLabel.GetCharIndexFromPosition(e.Location))
         End If
        If line <> -1 Then
' Display lotto numbers
            Me.xLbl_Lotto.Text = _
            Lottos(line).Number(0) & " " & _
            Lottos(line).Number(1) & " " & _
            Lottos(line).Number(2) & " " & _
            Lottos(line).Number(3) & " " & _
            Lottos(line).Number(4)

        End If
    End Sub


And cha-ching!(VB.Net :ph34r: )


mmmmmmm Never made a Label 'Read Only' and didn't know scrollbars could be added to a label. I'm looking to find, but don't see where their at.
Was This Post Helpful? 0
  • +
  • -

#27 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 - 09:34 PM

K found the Vscrollbar..didn't have that open...
Was This Post Helpful? 0
  • +
  • -

#28 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Formating Dates

Posted 29 July 2008 - 09:34 PM

View PostLadyWolf, on 30 Jul, 2008 - 05:13 AM, said:

View PostAdamSpeight2008, on 29 Jul, 2008 - 10:59 PM, said:

Figured it out :^:
first Make sure that xDatesLabel is ReadOnly and has vertical scrollbars.
Remove the listbox.
Then any lines that contain references to the listbox. (the ones with the errors)

Add this event code
    Private Sub xDatesLabel_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles xDatesLabel.MouseClick
        Dim line As Integer = -1
        If e.Button = Windows.Forms.MouseButtons.Left Then
' Find out which text line the mouse click was on.
            line = Me.xDatesLabel.GetLineFromCharIndex(Me.xDatesLabel.GetCharIndexFromPosition(e.Location))
         End If
        If line <> -1 Then
' Display lotto numbers
            Me.xLbl_Lotto.Text = _
            Lottos(line).Number(0) & " " & _
            Lottos(line).Number(1) & " " & _
            Lottos(line).Number(2) & " " & _
            Lottos(line).Number(3) & " " & _
            Lottos(line).Number(4)

        End If
    End Sub


And cha-ching!(VB.Net :ph34r: )


mmmmmmm Never made a Label 'Read Only' and didn't know scrollbars could be added to a label. I'm looking to find, but don't see where their at.

The control named xDatesLabel is actually a Textbox.
Was This Post Helpful? 0
  • +
  • -

#29 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 - 09:35 PM

View PostAdamSpeight2008, on 30 Jul, 2008 - 12:34 AM, said:

View PostLadyWolf, on 30 Jul, 2008 - 05:13 AM, said:

View PostAdamSpeight2008, on 29 Jul, 2008 - 10:59 PM, said:

Figured it out :^:
first Make sure that xDatesLabel is ReadOnly and has vertical scrollbars.
Remove the listbox.
Then any lines that contain references to the listbox. (the ones with the errors)

Add this event code
    Private Sub xDatesLabel_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles xDatesLabel.MouseClick
        Dim line As Integer = -1
        If e.Button = Windows.Forms.MouseButtons.Left Then
' Find out which text line the mouse click was on.
            line = Me.xDatesLabel.GetLineFromCharIndex(Me.xDatesLabel.GetCharIndexFromPosition(e.Location))
         End If
        If line <> -1 Then
' Display lotto numbers
            Me.xLbl_Lotto.Text = _
            Lottos(line).Number(0) & " " & _
            Lottos(line).Number(1) & " " & _
            Lottos(line).Number(2) & " " & _
            Lottos(line).Number(3) & " " & _
            Lottos(line).Number(4)

        End If
    End Sub


And cha-ching!(VB.Net :ph34r: )


mmmmmmm Never made a Label 'Read Only' and didn't know scrollbars could be added to a label. I'm looking to find, but don't see where their at.

The control named xDatesLabel is actually a Textbox.


Ahhh okay...
Was This Post Helpful? 0
  • +
  • -

#30 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 - 09:42 PM

View PostLadyWolf, on 30 Jul, 2008 - 12:35 AM, said:

View PostAdamSpeight2008, on 30 Jul, 2008 - 12:34 AM, said:

View PostLadyWolf, on 30 Jul, 2008 - 05:13 AM, said:

View PostAdamSpeight2008, on 29 Jul, 2008 - 10:59 PM, said:

Figured it out :^:
first Make sure that xDatesLabel is ReadOnly and has vertical scrollbars.
Remove the listbox.
Then any lines that contain references to the listbox. (the ones with the errors)

Add this event code
    Private Sub xDatesLabel_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles xDatesLabel.MouseClick
        Dim line As Integer = -1
        If e.Button = Windows.Forms.MouseButtons.Left Then
' Find out which text line the mouse click was on.
            line = Me.xDatesLabel.GetLineFromCharIndex(Me.xDatesLabel.GetCharIndexFromPosition(e.Location))
         End If
        If line <> -1 Then
' Display lotto numbers
            Me.xLbl_Lotto.Text = _
            Lottos(line).Number(0) & " " & _
            Lottos(line).Number(1) & " " & _
            Lottos(line).Number(2) & " " & _
            Lottos(line).Number(3) & " " & _
            Lottos(line).Number(4)

        End If
    End Sub


And cha-ching!(VB.Net :ph34r: )


mmmmmmm Never made a Label 'Read Only' and didn't know scrollbars could be added to a label. I'm looking to find, but don't see where their at.

The control named xDatesLabel is actually a Textbox.


Ahhh okay...


Okay text box is up..
Was This Post Helpful? 0
  • +
  • -

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