By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,620 Members | 982 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,620 IT Pros & Developers. It's quick & easy.

Calling Functions in VB

P: 9
ption Explicit On
Option Strict On

Public Class MainForm

Private Function CalcResidentialTotalDue() As Decimal
' calculates and returns the total due for a residential customer

' declare constants and variables
Const ResidentialProcessing As Decimal = 4.5D
Const ResidentialBasic As Decimal = 30D
Const ResidentialPremium As Decimal = 5D
Dim premiumChannels As Decimal
Dim charge As Decimal

' residential customers do not have connections
connectionListBox.SelectedIndex = 0

' get number of premium channels
premiumChannels = Convert.ToDecimal(premiumListBox.SelectedItem)

' calculate total due
charge = ResidentialProcessing + ResidentialBasic _
+ ResidentialPremium * premiumChannels

' return the total due
Return charge
End Function

Private Function CalcBusinessTotalDue() As Decimal
' calculates and returns the total due for a business customer

' declare constants and variables
Const BusinessProcessing As Decimal = 16.5D
Const BusinessFirst10Connections As Decimal = 80D
Const BusinessAdditionalConnections As Decimal = 4D
Const BusinessPremiumChannel As Decimal = 50D
Dim connections As Decimal
Dim premiumChannels As Decimal
Dim charge As Decimal
Dim businessBasic As Decimal

' get number of connections
connections = Convert.ToDecimal(connectionListBox.SelectedItem)

' business customers must have at least one connection
If connections = 0 Then
MessageBox.Show("The number of connections must be greater than 0.", _
"Cable Direct", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
' get number of premium channels
premiumChannels = Convert.ToDecimal(premiumListBox.SelectedItem)

' calculate the basic service
If connections <= 10D Then
businessBasic = BusinessFirst10Connections
Else
businessBasic = BusinessFirst10Connections _
+ (connections - 10D) * BusinessAdditionalConnections
End If

' calculate the total due
charge = BusinessProcessing + businessBasic _
+ BusinessPremiumChannel * premiumChannels
End If

' return the total due
Return charge

End Function

Private Sub ClearTotalDue(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles businessRadioButton.Click, residentialRadioButton.Click, _
premiumListBox.SelectedValueChanged, connectionListBox.SelectedValueChanged

totalDueLabel.Text = String.Empty
End Sub

Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' fills the list boxes with values, then selects the first value

For premiumChannel As Integer = 0 To 20
premiumListBox.Items.Add(premiumChannel.ToString)
Next premiumChannel

For connections As Integer = 0 To 100
connectionListBox.Items.Add(connections.ToString)
Next connections

premiumListBox.SelectedIndex = 0
connectionListBox.SelectedIndex = 0
End Sub

Private Sub calcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calcButton.Click
' calculates and displays a customer's bill

Dim totalDue As Decimal

' call appropriate function to calculate the total due







' display the total due
totalDueLabel.Text = totalDue.ToString("C2")
End Sub

Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub

End Class



OK so I feel stupid ..jere I have written all of this code yet I have forgotten how to call a function to get this to calculate


Someone please remind me
Mar 29 '07 #1
Share this Question
Share on Google+
2 Replies


Dököll
Expert 100+
P: 2,364
Hang in there, KellysGirl!

Someone will likely help you. I am also a begginer and do not see what is happening. Perhaps if you add your code within tags/brackets, it will be more readable.

Also, if you would like, try having part of code working, before continuing to other functions...

Please stay tuned as better qualified members here will see your cry for help.

Dököll
Mar 29 '07 #2

iburyak
Expert 100+
P: 1,017
I assume that all functions above in the same form.
If they are in a module they have to be public in order for you to be able to call them.

Depend on type of business Residential or Business you should call following functions:

[PHP]totalDueLabel.Text = CalcResidentialTotalDue

or

totalDueLabel.Text = CalcBusinessTotalDue[/PHP]
Mar 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.