| | |
Saving textbox data based on date selected
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Solved Threads: 0
Hi
I am looking to create a program to help with my running training. It would be like a diary where I could select a date using either a DateTimePicker or MonthCalendar and then enter text into the textbox based on that date.
Can you please help me with coding this as it would be great to keep track of my training?
I am looking to create a program to help with my running training. It would be like a diary where I could select a date using either a DateTimePicker or MonthCalendar and then enter text into the textbox based on that date.
Can you please help me with coding this as it would be great to keep track of my training?
•
•
•
•
Hi
I am looking to create a program to help with my running training. It would be like a diary where I could select a date using either a DateTimePicker or MonthCalendar and then enter text into the textbox based on that date.
Can you please help me with coding this as it would be great to keep track of my training?
What you dont know. adding controls or db connectivity or what?
Last edited by sbv; Mar 18th, 2008 at 1:42 am.
Accept Challenges and Enjoy Coding... :)
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
What you want?
What you dont know. adding controls or db connectivity or what?
I basically want to now from start to finish if possible. I have just got a form with a DateTimePicker and Textbox on currently.
I have figured out how to save to a text file but i'd end up with an awful lot of textfiles if i did it that way because i'd have an rtf file for each day of the week
Thanks again
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Solved Threads: 0
Sure, I mean if you select a date on the MonthCalendar you can enter text in the textbox. Then if you select another date the textbox will clear and allow you to enter more data for that particular date. If you then click back to a date where text has been entered previously the program would remember that and display it in the textbox.
Hope that makes sense
I have actually got that part of it working. Here is the code;
What I need help with now is saving the data so it is still there when the program is closed and re-opened. Does anybody know the solution for this?
Thanks
Hope that makes sense
I have actually got that part of it working. Here is the code;
VB.NET Syntax (Toggle Plain Text)
Public Class Form1 Dim DataDictionary As Dictionary(Of String, String) Dim CurrentDate As Date Private Sub MonthCalendar1_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected DateSelect() End Sub Public Sub New() InitializeComponent() CurrentDate = New Date DataDictionary = New Dictionary(Of String, String) DateSelect() End Sub Private Sub DateSelect() If MonthCalendar1.SelectionStart.Date = MonthCalendar1.SelectionEnd.Date Then CurrentDate = MonthCalendar1.SelectionStart.Date If Not ComboBox1.Items.Contains(CurrentDate.Date.ToLongDateString()) Then ComboBox1.Items.Add(CurrentDate.Date.ToLongDateString()) DataDictionary.Add(CurrentDate.Date.ToLongDateString(), "") ComboBox1.SelectedItem = CurrentDate.Date.ToLongDateString() Else ComboBox1.SelectedItem = CurrentDate.Date.ToLongDateString() If DataDictionary.ContainsKey(CurrentDate.Date.ToLongDateString()) Then TextBox1.Text = DataDictionary.Item(CurrentDate.Date.ToLongDateString()) Else TextBox1.Text = "" End If End If End If End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If DataDictionary.ContainsKey(CurrentDate.Date.ToLongDateString()) Then TextBox1.Text = DataDictionary.Item(CurrentDate.Date.ToLongDateString()) End If End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If DataDictionary.ContainsKey(CurrentDate.Date.ToLongDateString()) Then DataDictionary.Item(CurrentDate.Date.ToLongDateString()) = TextBox1.Text End If End Sub End Class
What I need help with now is saving the data so it is still there when the program is closed and re-opened. Does anybody know the solution for this?
Thanks
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Solved Threads: 0
I like the idea of using XML for my program
I was given the following bit of code but I don't really understand it or where it needs to fit into my code. Any help would be appreciated
I was given the following bit of code but I don't really understand it or where it needs to fit into my code. Any help would be appreciated
VB.NET Syntax (Toggle Plain Text)
<?xml version="1.0"?> <dates> <entry date="...">...</entry> <entry date="...">...</entry> </dates>
•
•
Join Date: Feb 2008
Posts: 52
Reputation:
Solved Threads: 6
•
•
•
•
I like the idea of using XML for my program
I was given the following bit of code but I don't really understand it or where it needs to fit into my code. Any help would be appreciated
VB.NET Syntax (Toggle Plain Text)
<?xml version="1.0"?> <dates> <entry date="...">...</entry> <entry date="...">...</entry> </dates>
Last edited by bwkeller; Mar 20th, 2008 at 11:16 am.
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Solved Threads: 0
I now have the following code which works perfectly. You can paste the code into a blank Windows Application Project to see it in action.
Now I need to add a couple more textboxes but I am told the code below only supports a single key and value.
How can I change the code to allow further textboxes to be added?
Now I need to add a couple more textboxes but I am told the code below only supports a single key and value.
How can I change the code to allow further textboxes to be added?
VB.NET Syntax (Toggle Plain Text)
Public Class Form1 Dim DataDictionary As Dictionary(Of String, String) Dim DataDocument As Xml.XmlDocument Dim FilePath As String Dim CurrentDate As Date Friend WithEvents DateSelector As System.Windows.Forms.MonthCalendar Friend WithEvents DateCombo As System.Windows.Forms.ComboBox Friend WithEvents DateInfo As System.Windows.Forms.TextBox Public Sub New() InitializeComponent() 'Manually add the controls needed Me.Text = "LogMyJog version 1" Me.Size = New Size(800, 600) Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle DateSelector = New MonthCalendar() DateSelector.Location = New Point(0, 0) Me.Controls.Add(DateSelector) DateCombo = New ComboBox() DateCombo.DropDownStyle = ComboBoxStyle.DropDownList DateCombo.Location = New Point(0, 164) DateCombo.Width = Me.ClientSize.Width DateCombo.Size = New Size(180, 50) Me.Controls.Add(DateCombo) DateInfo = New TextBox() DateInfo.Multiline = True DateInfo.ScrollBars = ScrollBars.Vertical DateInfo.Location = New Point(0, 188) DateInfo.Size = New Size(500, 200) Me.Controls.Add(DateInfo) CurrentDate = New Date DataDictionary = New Dictionary(Of String, String) DataDocument = New Xml.XmlDocument() 'This is where the data will be stored FilePath = Application.StartupPath & "\dateinfo.xml" If FileIO.FileSystem.FileExists(FilePath) Then DataDocument.Load(Application.StartupPath & "\dateinfo.xml") Dim Items As Xml.XmlNodeList Dim Item As Xml.XmlNode Dim ItemDate As Date Items = DataDocument.DocumentElement.SelectNodes("//item") For Each Item In Items 'Add data into the DataDictionary and ComboBox ItemDate = Date.Parse(Item.Attributes("date").Value) DataDictionary.Add(ItemDate.Date.ToLongDateString(), Item.FirstChild.InnerText) DateCombo.Items.Add(ItemDate.Date.ToLongDateString()) Next End If 'Add the event handlers for the three controls AddHandler DateInfo.TextChanged, AddressOf Me.DateInfo_TextChanged AddHandler DateCombo.SelectedIndexChanged, AddressOf Me.DateCombo_SelectedIndexChanged AddHandler DateSelector.DateChanged, AddressOf Me.DateSelector_DateChanged 'Initialize the controls using the CurrentDate DateSelect() End Sub Private Sub DateSelect() If DateSelector.SelectionStart.Date = DateSelector.SelectionEnd.Date Then CurrentDate = DateSelector.SelectionStart.Date If Not DateCombo.Items.Contains(CurrentDate.Date.ToLongDateString()) Then DateCombo.Items.Add(CurrentDate.Date.ToLongDateString()) DataDictionary.Add(CurrentDate.Date.ToLongDateString(), "") DateCombo.SelectedItem = CurrentDate.Date.ToLongDateString() Else DateCombo.SelectedItem = CurrentDate.Date.ToLongDateString() If DataDictionary.ContainsKey(CurrentDate.Date.ToLongDateString()) Then DateInfo.Text = DataDictionary.Item(CurrentDate.Date.ToLongDateString()) Else DateInfo.Text = "" End If End If End If End Sub Private Sub DateSelector_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) DateSelect() End Sub Private Sub DateCombo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) If DataDictionary.ContainsKey(DateCombo.Text) Then DateSelector.SelectionStart = Date.Parse(DateCombo.Text) DateSelector.SelectionEnd = Date.Parse(DateCombo.Text) End If End Sub Private Sub DateInfo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) If DataDictionary.ContainsKey(CurrentDate.Date.ToLongDateString()) Then DataDictionary.Item(CurrentDate.Date.ToLongDateString()) = DateInfo.Text End If End Sub Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing 'Save the DataDictionary to the Xml Document... DataDocument = New Xml.XmlDocument() Dim Root As Xml.XmlElement Dim Item As Xml.XmlElement Dim Data As Xml.XmlCDataSection Dim DateAttribute As Xml.XmlAttribute Dim Key As String Root = DataDocument.CreateElement("data") For Each Key In DataDictionary.Keys Item = DataDocument.CreateElement("item") DateAttribute = DataDocument.CreateAttribute("date") DateAttribute.Value = Key Item.Attributes.Append(DateAttribute) Data = DataDocument.CreateCDataSection(DataDictionary(Key)) Item.AppendChild(Data) Root.AppendChild(Item) Next DataDocument.AppendChild(Root) DataDocument.Save(FilePath) End Sub End Class
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Retrieve System startup list
- Next Thread: Indent the C text in vb.net
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons center check code component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dissertationthesis dropdownlist excel fade file-dialog folder ftp generatetags hardcopy image images input insert intel internet login math mobile monitor ms navigate net networking objects opacity output passingparameters peertopeervideostreaming picturebox picturebox1 port problem problemwithinstallation project reports" savedialog searchvb.net select serial shutdown soap string survey tcp temperature text textbox timer toolbox trim update updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf





