Results 1 to 4 of 4

Thread: Assistance creating a Sub Procedure named “(FundingResource(Balance))” Visual Basic

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    16

    Assistance creating a Sub Procedure named “(FundingResource(Balance))” Visual Basic

    I am working on a program that consists of three event procedures (in other words, three different task buttons: “Select Media and Estimated Fund,” “Add Agencies,” and “Generate Report”).

    When the “Select Media and Estimated Fund” button is clicked, input boxes should pop up and ask user to input a balance and that balance will be put through the formula of (Balance = Balance * (1 + interest rate). The balance the user inputs can not be less that $500.00 or more than $3000.00.

    ( Estimated Budget should be calculated depending on your selection of funding resources (Funding Resource is the type of account they choose, Savings (7% interest rate) and Corporate (5% interest Rate) The calculated results should appear in the disabled textbox right next to the “Estimated Budget” textbox. If you selected two resources, each estimated budget should be summarized together. The calculation process should be called a sub procedure defined as “FundingResource (Balance)” in the event procedure.

    Please be aware of the current year, 2013. Now, the report is prepared in year 2013, but the balance should be calculated for your selected year (e.g., 2015, 2016, 2017). Think about the topic of repetition to determine the ending balance during your selected year.

    I have completed the code I believe but don't know how to put it into a Sub Procedure. The code for the above question is in "btnMediaEstimatedFund".

    Code:
    Public Class Form1
    
    Private Sub btnMediaEstimatedFund_Click(sender As Object, e As EventArgs) Handles btnMediaEstimatedFund.Click
    
        Dim interestRate, balance, initialBalanceSavings, initialBalanceCorporate, finalBalance As Double
    
        txtBoxEstimatedBudget.Enabled = False
        txtBoxAgenciesNeeded.Enabled = False
    
        If radButtonTraditional.Checked Then
    
            txtBoxAgenciesNeeded.Text = 3
    
        ElseIf radButtonEMedia.Checked Then
    
            txtBoxAgenciesNeeded.Text = 2
    
        End If
    
        If checkBoxSavings.Checked Then
    
            interestRate = 0.07
    
        ElseIf checkBoxCorporate.Checked Then
    
            interestRate = 0.05
    
        ElseIf checkBoxCorporate.Checked And checkBoxSavings.Checked Then
    
            interestRate = 0.12
    
        End If
    
        initialBalanceSavings = InputBox("Please Enter a balance for SAVINGS account between $500.00 and $3000.00")
    
        If initialBalanceSavings > 3000 Then
    
            InputBox("Please enter a balance for SAVINGS account equal to or below $3000.00 and no less than $500.00")
    
        ElseIf initialBalanceSavings < 500 Then
    
            InputBox("Please enter a balance for SAVINGS account equal to or above $500.00 and no more than $3000.00")
    
        End If
    
         initialBalanceCorporate = InputBox("Please Enter a balance for CORPORATE account between $500.00 and $3000.00")
    
        If initialBalanceCorporate > 3000 Then
    
            InputBox("Please enter a balance for CORPORATE account equal to or below $3000.000 and no less than $500.00")
    
        ElseIf initialBalanceCorporate < 500 Then
    
            InputBox("Please enter a balance for CORPORATE account equal to or above $500.00 and no more than $3000.00")
    
        Else
    
            finalBalance = initialBalanceCorporate + initialBalanceSavings
            balance = finalBalance * (1 + interestRate)
            txtBoxEstimatedBudget.Text = balance
    
        End If
    
    End Sub
    
    
    Private Sub btnAddAgencies_Click(sender As Object, e As EventArgs) Handles btnAddAgencies.Click
    
        Dim dict As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)()
        dict.Add("U-Ad ($350)", 350)
        dict.Add("Striker ($190)", 190)
        dict.Add("New Ad ($250)", 250)
        dict.Add("Samson ($530)", 530)
        dict.Add("J & R ($420)", 420)
        dict.Add("Victory ($120)", 120)
    
        Dim selectedItems = (From i In lstBoxAgenciesList.SelectedItems).ToArray()
        Dim total As Integer = 0
    
        For Each selectedItem In selectedItems
    
            lstBoxSelectedList.Items.Add(selectedItem)
            lstBoxAgenciesList.Items.Remove(selectedItem)
    
        Next
    
        For Each item In lstBoxSelectedList.Items
    
            total += dict(item)
    
        Next
    
        txtBoxEstimatedCost.Text = FormatCurrency(total.ToString())
    
    End Sub
    
    Private Sub btnGenerateReport_Click(sender As Object, e As EventArgs) Handles btnGenerateReport.Click
    
        Dim employeeLevel, year, selectedMedia, numberOfAgencies As String
        Dim today As Date
    
        today = CStr(dtpToday.Text)
        Name = CStr(txtBoxCreator.Text)
        employeeLevel = CStr(lstBoxResults.Text)
        year = CStr(lstBoxResults.Text)
        selectedMedia = CStr(lstBoxResults.Text)
        numberOfAgencies = CStr(txtBoxAgenciesNeeded.Text)
    
        dtpToday.Text = FormatDateTime(today, DateFormat.ShortDate)
    
        If radButtonManager.Checked Then
    
            employeeLevel = "Manager"
    
        ElseIf radButtonStaff.Checked Then
    
            employeeLevel = "Staff"
    
        End If
    
        If radButton2015.Checked Then
    
            year = "2015"
    
        ElseIf radButton2016.Checked Then
    
            year = "2016"
    
        ElseIf radButton2017.Checked Then
    
            year = "2017"
    
        End If
    
        If radButtonTraditional.Checked Then
    
            selectedMedia = "Traditional Media (TV, Radio)"
    
        ElseIf radButtonEMedia.Checked Then
    
            selectedMedia = "New e-Media (SNS, e-Mail)"
    
        End If
    
        lstBoxResults.Items.Add("=======================================")
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("Date : " & today)
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("Reporting Entity : " & Name)
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("Level of Employee :  " & employeeLevel)
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("=======================================")
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("Year" & " " & year & " " & "Budget of Advertising Report")
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("=======================================")
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("Total Estimated Cost : " & FormatCurrency(txtBoxEstimatedCost.Text))
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("Total Estimated Budget : " & FormatCurrency(txtBoxEstimatedBudget.Text))
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("Selected Media : " & selectedMedia)
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("Number of Agencies Involved : " & numberOfAgencies)
        lstBoxResults.Items.Add(" ")
        lstBoxResults.Items.Add("=======================================")
    
    End Sub
    
    End Class
    Thanks in advance for any help!

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Assistance creating a Sub Procedure named “(FundingResource(Balance))” Visual Bas

    btnEstimatedFunds IS a Sub procedure. That's what that Sub word is in the method signature.

    If you need it in a different Sub Procedure, you would just create one and copy the code in there, but there's no good reason to do that when it is already in one.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    16

    Re: Assistance creating a Sub Procedure named “(FundingResource(Balance))” Visual Bas

    I meant function

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Assistance creating a Sub Procedure named “(FundingResource(Balance))” Visual Bas

    I suggest that you do some reading about functions.

    http://www.homeandlearn.co.uk/net/vbnet.html#Subs
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width