473,382 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Calling Functions in VB

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
2 3028
Dököll
2,364 Expert 2GB
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
1,017 Expert 512MB
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

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

Similar topics

2
by: pieter.breed | last post by:
Hi All, Is it possible to export a c# method into a dll in such a way that your "normal" C application can then call this method? To be clear: I am not asking how to use "DllImport" or...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
5
by: Dave | last post by:
does calling a regular function cost any cpu time? In other words, is it faster to write the code of two functions into main(), or is it the exact same thing as calling two functions. I know its...
1
by: Mark Jerde | last post by:
Yesterday I posted the message below to microsoft.public.dotnet.languages.vb and microsoft.public.vc.language. The two replies are also posted. I need to write some ISO C++ functions, more...
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
1
by: H.B. | last post by:
Hi, I need to make a function that can display data on my Managed C++ app and be called by an unmanaged C++ DLL. Something like : void Form1::Form1_Load(System::Object * sender,...
2
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors,...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
10
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.