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
Contributors
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

MySavings *Tutorial*
comathi
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:
Code: Select all
 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
- Then, under the Button1_Click Event (button 1 being the "Save" button), add this:
Code: Select all
 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
- Finnally, under the Button2_Click Event, add the following:
Code: Select all
 If My.Settings.ItemName = "" Then
            End
        Else
            Panel1.Show()
        End If
- Don't worry about any errors at this point. We're not quite done.

- Add a Public Sub and call it "UpdateMoney"

- In "UpdateMoney", add this code:
Code: Select all
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
- That's it for the first part!

- 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
 Add.Show()
- For Button4_Click (The "Remove Money" button), add this:
Code: Select all
 Remove.Show()
- For the "Settings" button (button5), paste this code:
Code: Select all
  Panel1.Hide()
- And finnally, in the "Delete Savings" button (button6), add this:
Code: Select all
If MsgBox("Are you sure you want to delete your savings?", vbYesNo + vbQuestion, "Delete Savings?") = vbYes Then
            My.Settings.Reset()
            End
        Else

        End If
- We're almost done!!


- 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
 My.Settings.SavedAmount += NumericUpDown1.Value
        My.Settings.Save()
        Call Form1.updateMoney()
        Me.Close()
*Note*: For the "Remove" form, change "My.settings.SavedAmount+=..." to "My.settings.SavedAmount-=...".

- For both "Cancel" buttons, put this:
Code: Select all
Me.Close()
- And Voilà! You are done! :D

************************************************************************************

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

-Comathi- :D :D
Last edited by comathi on Sat Jul 23, 2011 12:09 pm, edited 1 time in total.
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: MySavings *Tutorial*
XTechVB
the Archive is empty dude,.
You can find me on Facebook or on Skype mihai_92b
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: MySavings *Tutorial*
comathi
My bad. I re-uploaded it! :D
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Re: MySavings *Tutorial*
clanc789
Thanks for making a tut so fast comathi!! +rep!
Practice makes perfect!

VIP since: 6-10-2011
4 posts Page 1 of 1
Return to “Tutorials”