MySavings *Tutorial*
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
4 posts
Page 1 of 1
I'm making this tutorial especially for Mark, who asked for one. It's about a program I just released to the Full Software section : MySavings. The program lets you keep track of your expenses and deposits while saving up for something.
- First, as usual, open up Microsoft Visual Basic 2008 or 2010.
- Create a new Windows Forms Application project and name it whatever you would like.
- Before we continue, we have to create the following settings under My.Settings:
- A String setting called "ItemName"
- A Decimal setting called "Cost"
- A Decimal settings called "SavedAmount"
- Now, add the following items to the form:
- A GroupBox (change it's text to "Create a new Savings Watcher").
- 3 Labels (Change their text to "What are you saving up for?", "How much does it cost?" and "How much have you saved so far?").
- A TextBox (Change it's name to "Item").
- Two NumericUpDown (Change their names to "Cost" and "Saved").
- Two buttons (Change their text to "Save" and "Cancel"
It's now time for the first part of the code.
- Under the Form1_Load Event, add this:
- Add a Public Sub and call it "UpdateMoney"
- In "UpdateMoney", add this code:
- Now, add a panel to the form and make sure it's "Dock" property is set to "Fill", so that the panel fills the form.
- In this panel, add the following controls:
- A GroupBox (Change it's text to "Savings for...").
- A Label (Label4). (Change it's text to "Cost:...").
- Another Label (Label5). (Change it's text to "Saved so far:...").
- Two buttons (Change their texts to "Add Money" and "Remove Money").
- A ProgressBar
- One last Label (Change it's text to "0% completed").
-Two buttons (Change their text to "Settings" and "Delete Savings").
- Now, for the second part of the code.
- In the Button3_Click Event (The "Add Money" button), paste this code:
- Add two new forms, "Add.vb" and "Remove.vb"
- In both forms, add the following:
- A Label (change the text to either "How much money would you like to add?" or [...]"would you like to remove?"
- A NumericUpDown control (Change it's maximum value to 9999999999).
- Two buttons ("Ok" and "Cancel").
- For the Ok buttons add the following code:
- For both "Cancel" buttons, put this:

************************************************************************************
The file below is the source code for this project. Please comment and feel free to PM me if you need help!
-Comathi-

- First, as usual, open up Microsoft Visual Basic 2008 or 2010.
- Create a new Windows Forms Application project and name it whatever you would like.
- Before we continue, we have to create the following settings under My.Settings:
- A String setting called "ItemName"
- A Decimal setting called "Cost"
- A Decimal settings called "SavedAmount"
- Now, add the following items to the form:
- A GroupBox (change it's text to "Create a new Savings Watcher").
- 3 Labels (Change their text to "What are you saving up for?", "How much does it cost?" and "How much have you saved so far?").
- A TextBox (Change it's name to "Item").
- Two NumericUpDown (Change their names to "Cost" and "Saved").
- Two buttons (Change their text to "Save" and "Cancel"
It's now time for the first part of the code.
- Under the Form1_Load Event, add this:
Code: Select all
- Then, under the Button1_Click Event (button 1 being the "Save" button), add this: If My.Settings.ItemName = "" Then
Panel1.Hide()
Else
Panel1.Show()
End If
Call UpdateMoney()
Item.Text = My.Settings.ItemName
Cost.Maximum = 9999999999
Cost.Value = My.Settings.Cost
Saved.Maximum = 9999999999
Saved.Value = My.Settings.SavedAmount
Code: Select all
- Finnally, under the Button2_Click Event, add the following: If Item.Text <> "" And Cost.Value <> 0 Then
My.Settings.ItemName = Item.Text
My.Settings.Cost = Cost.Value
My.Settings.SavedAmount = Saved.Value
My.Settings.Save()
Call UpdateMoney()
Panel1.Show()
Else
MsgBox("Please enter the name of the item and a cost for it.", vbOKOnly + vbExclamation, "Error")
End If
Code: Select all
- Don't worry about any errors at this point. We're not quite done. If My.Settings.ItemName = "" Then
End
Else
Panel1.Show()
End If
- Add a Public Sub and call it "UpdateMoney"
- In "UpdateMoney", add this code:
Code: Select all
- That's it for the first part!GroupBox2.Text = "Savings for " & My.Settings.ItemName
Label4.Text = "Cost: " & My.Settings.Cost
Label5.Text = "Saved so far: " & My.Settings.SavedAmount
Try
ProgressBar1.Value = Math.Truncate((My.Settings.SavedAmount / My.Settings.Cost) * 100)
Label6.Text = Math.Truncate((My.Settings.SavedAmount / My.Settings.Cost) * 100) & "% completed..."
Catch ex As Exception
End Try
If My.Settings.Cost = My.Settings.SavedAmount And My.Settings.Cost <> 0 Then
MsgBox("Hurray! You can buy " & My.Settings.ItemName, vbOKOnly + vbExclamation)
ProgressBar1.Value = 100
Label6.Text = "100% completed"
ElseIf My.Settings.SavedAmount > My.Settings.Cost Then
MsgBox("Hurray! You can buy " & My.Settings.ItemName & ". You have " & (My.Settings.SavedAmount - My.Settings.Cost) & " more than you need.", vbOKOnly + vbExclamation)
ProgressBar1.Value = 100
Label6.Text = "100% completed"
Else
End If
- Now, add a panel to the form and make sure it's "Dock" property is set to "Fill", so that the panel fills the form.
- In this panel, add the following controls:
- A GroupBox (Change it's text to "Savings for...").
- A Label (Label4). (Change it's text to "Cost:...").
- Another Label (Label5). (Change it's text to "Saved so far:...").
- Two buttons (Change their texts to "Add Money" and "Remove Money").
- A ProgressBar
- One last Label (Change it's text to "0% completed").
-Two buttons (Change their text to "Settings" and "Delete Savings").
- Now, for the second part of the code.
- In the Button3_Click Event (The "Add Money" button), paste this code:
Code: Select all
- For Button4_Click (The "Remove Money" button), add this: Add.Show()
Code: Select all
- For the "Settings" button (button5), paste this code: Remove.Show()
Code: Select all
- And finnally, in the "Delete Savings" button (button6), add this: Panel1.Hide()
Code: Select all
- We're almost done!!If MsgBox("Are you sure you want to delete your savings?", vbYesNo + vbQuestion, "Delete Savings?") = vbYes Then
My.Settings.Reset()
End
Else
End If
- Add two new forms, "Add.vb" and "Remove.vb"
- In both forms, add the following:
- A Label (change the text to either "How much money would you like to add?" or [...]"would you like to remove?"
- A NumericUpDown control (Change it's maximum value to 9999999999).
- Two buttons ("Ok" and "Cancel").
- For the Ok buttons add the following code:
Code: Select all
*Note*: For the "Remove" form, change "My.settings.SavedAmount+=..." to "My.settings.SavedAmount-=...". My.Settings.SavedAmount += NumericUpDown1.Value
My.Settings.Save()
Call Form1.updateMoney()
Me.Close()
- For both "Cancel" buttons, put this:
Code: Select all
- And Voilà! You are done! Me.Close()

************************************************************************************
The file below is the source code for this project. Please comment and feel free to PM me if you need help!
-Comathi-


Last edited by comathi on Sat Jul 23, 2011 12:09 pm, edited 1 time in total.
Thanks for making a tut so fast comathi!! +rep!
Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
4 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023