473,468 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Passing Classes

Public Class fraction
Dim m_numerator As Int16
Dim m_denominator As Int16

Public Event zerodenom()
Public Property numerator() As Int16
Get
Return m_numerator
End Get
Set(ByVal Value As Int16)
Value = m_numerator
End Set
End Property
Public Property denominator() As Int16
Get
Return m_denominator
End Get
Set(ByVal Value As Int16)
Value = m_denominator
End Set
End Property

Public Function reduce(ByVal numerator As Int16, ByVal denominator
As Int16) As Int16
Dim temp As Int16

Do While denominator <> 0
temp = denominator
denominator = numerator Mod denominator
numerator = temp
Loop
Return numerator
End Function
Public Function calculate_common_denominator(ByVal denominator As
Int16, ByVal denominator1 As Int16)
Dim common As Int16
common = denominator * denominator1

Return common
End Function

Public Function add(ByVal frac1 As fraction, ByVal frac2 As
fraction)

How do I pass a class so I can use its members in a function? In here I
need to use frac1.numerator & Denominator frac2.numerator and
denominator how is this done by passing the objects?
John
End Function

End Class

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents btnAdd As System.Windows.Forms.Button
Friend WithEvents txtdenom1 As System.Windows.Forms.TextBox
Friend WithEvents txtnum1 As System.Windows.Forms.TextBox
Friend WithEvents txtdenom2 As System.Windows.Forms.TextBox
Friend WithEvents txtsumnum As System.Windows.Forms.TextBox
Friend WithEvents txtsumdenom As System.Windows.Forms.TextBox
Friend WithEvents txtnum2 As System.Windows.Forms.TextBox
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents ListBox2 As System.Windows.Forms.ListBox
Friend WithEvents ListBox3 As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.txtdenom1 = New System.Windows.Forms.TextBox
Me.txtnum1 = New System.Windows.Forms.TextBox
Me.txtnum2 = New System.Windows.Forms.TextBox
Me.txtdenom2 = New System.Windows.Forms.TextBox
Me.txtsumnum = New System.Windows.Forms.TextBox
Me.txtsumdenom = New System.Windows.Forms.TextBox
Me.btnAdd = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.ListBox2 = New System.Windows.Forms.ListBox
Me.ListBox3 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'txtdenom1
'
Me.txtdenom1.Location = New System.Drawing.Point(8, 112)
Me.txtdenom1.Name = "txtdenom1"
Me.txtdenom1.Size = New System.Drawing.Size(64, 20)
Me.txtdenom1.TabIndex = 0
Me.txtdenom1.Text = ""
'
'txtnum1
'
Me.txtnum1.Location = New System.Drawing.Point(8, 80)
Me.txtnum1.Name = "txtnum1"
Me.txtnum1.Size = New System.Drawing.Size(64, 20)
Me.txtnum1.TabIndex = 1
Me.txtnum1.Text = ""
'
'txtnum2
'
Me.txtnum2.Location = New System.Drawing.Point(144, 80)
Me.txtnum2.Name = "txtnum2"
Me.txtnum2.Size = New System.Drawing.Size(64, 20)
Me.txtnum2.TabIndex = 2
Me.txtnum2.Text = ""
'
'txtdenom2
'
Me.txtdenom2.Location = New System.Drawing.Point(144, 120)
Me.txtdenom2.Name = "txtdenom2"
Me.txtdenom2.Size = New System.Drawing.Size(64, 20)
Me.txtdenom2.TabIndex = 3
Me.txtdenom2.Text = ""
'
'txtsumnum
'
Me.txtsumnum.Location = New System.Drawing.Point(376, 80)
Me.txtsumnum.Name = "txtsumnum"
Me.txtsumnum.Size = New System.Drawing.Size(64, 20)
Me.txtsumnum.TabIndex = 4
Me.txtsumnum.Text = ""
'
'txtsumdenom
'
Me.txtsumdenom.Location = New System.Drawing.Point(376, 112)
Me.txtsumdenom.Name = "txtsumdenom"
Me.txtsumdenom.Size = New System.Drawing.Size(64, 20)
Me.txtsumdenom.TabIndex = 5
Me.txtsumdenom.Text = ""
'
'btnAdd
'
Me.btnAdd.Font = New System.Drawing.Font("Microsoft Sans Serif",
14.25!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnAdd.Location = New System.Drawing.Point(80, 96)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(48, 32)
Me.btnAdd.TabIndex = 6
Me.btnAdd.Text = "+"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif",
15.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(248, 96)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(32, 24)
Me.Label1.TabIndex = 7
Me.Label1.Text = "="
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(368, 104)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(80, 4)
Me.ListBox1.TabIndex = 8
'
'ListBox2
'
Me.ListBox2.Location = New System.Drawing.Point(144, 112)
Me.ListBox2.Name = "ListBox2"
Me.ListBox2.Size = New System.Drawing.Size(72, 4)
Me.ListBox2.TabIndex = 9
'
'ListBox3
'
Me.ListBox3.Location = New System.Drawing.Point(8, 104)
Me.ListBox3.Name = "ListBox3"
Me.ListBox3.Size = New System.Drawing.Size(64, 4)
Me.ListBox3.TabIndex = 10
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(472, 266)
Me.Controls.Add(Me.ListBox3)
Me.Controls.Add(Me.ListBox2)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.txtsumdenom)
Me.Controls.Add(Me.txtsumnum)
Me.Controls.Add(Me.txtdenom2)
Me.Controls.Add(Me.txtnum2)
Me.Controls.Add(Me.txtnum1)
Me.Controls.Add(Me.txtdenom1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim WithEvents clsfraction As New fraction
Dim WithEvents clsfraction1 As New fraction

Dim denominator, denominator1 As Int16



Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Dim common, numer1, numer2, denom, total As Int16
Dim gcd As Int16 'holds value of gcd

numer1 = Val(txtnum1.Text)
numer2 = Val(txtnum2.Text)
denominator = Val(txtdenom1.Text)
denominator1 = Val(txtdenom2.Text)

common = clsfraction.calculate_common_denominator(denominat or,
denominator1)

total = clsfraction.add(clsfraction, clsfraction1)
gcd = clsfraction.reduce(total, common)

common = common / gcd
total = total / gcd

txtsumnum.Text = total
txtsumdenom.Text = common
End Sub

Private Sub clsfraction1_zerodenom() Handles clsfraction1.zerodenom
MessageBox.Show("Error-Zero in the denominator")

End Sub
End Class
Nov 20 '05 #1
6 1199
Dim newClass as new fraction

"RBCC" <pu************@email.com> wrote in message
news:Xn******************************@207.46.248.1 6...
Public Class fraction
Dim m_numerator As Int16
Dim m_denominator As Int16

Public Event zerodenom()
Public Property numerator() As Int16
Get
Return m_numerator
End Get
Set(ByVal Value As Int16)
Value = m_numerator
End Set
End Property
Public Property denominator() As Int16
Get
Return m_denominator
End Get
Set(ByVal Value As Int16)
Value = m_denominator
End Set
End Property

Public Function reduce(ByVal numerator As Int16, ByVal denominator
As Int16) As Int16
Dim temp As Int16

Do While denominator <> 0
temp = denominator
denominator = numerator Mod denominator
numerator = temp
Loop
Return numerator
End Function
Public Function calculate_common_denominator(ByVal denominator As
Int16, ByVal denominator1 As Int16)
Dim common As Int16
common = denominator * denominator1

Return common
End Function

Public Function add(ByVal frac1 As fraction, ByVal frac2 As
fraction)

How do I pass a class so I can use its members in a function? In here I
need to use frac1.numerator & Denominator frac2.numerator and
denominator how is this done by passing the objects?
John
End Function

End Class

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents btnAdd As System.Windows.Forms.Button
Friend WithEvents txtdenom1 As System.Windows.Forms.TextBox
Friend WithEvents txtnum1 As System.Windows.Forms.TextBox
Friend WithEvents txtdenom2 As System.Windows.Forms.TextBox
Friend WithEvents txtsumnum As System.Windows.Forms.TextBox
Friend WithEvents txtsumdenom As System.Windows.Forms.TextBox
Friend WithEvents txtnum2 As System.Windows.Forms.TextBox
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents ListBox2 As System.Windows.Forms.ListBox
Friend WithEvents ListBox3 As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.txtdenom1 = New System.Windows.Forms.TextBox
Me.txtnum1 = New System.Windows.Forms.TextBox
Me.txtnum2 = New System.Windows.Forms.TextBox
Me.txtdenom2 = New System.Windows.Forms.TextBox
Me.txtsumnum = New System.Windows.Forms.TextBox
Me.txtsumdenom = New System.Windows.Forms.TextBox
Me.btnAdd = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.ListBox2 = New System.Windows.Forms.ListBox
Me.ListBox3 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'txtdenom1
'
Me.txtdenom1.Location = New System.Drawing.Point(8, 112)
Me.txtdenom1.Name = "txtdenom1"
Me.txtdenom1.Size = New System.Drawing.Size(64, 20)
Me.txtdenom1.TabIndex = 0
Me.txtdenom1.Text = ""
'
'txtnum1
'
Me.txtnum1.Location = New System.Drawing.Point(8, 80)
Me.txtnum1.Name = "txtnum1"
Me.txtnum1.Size = New System.Drawing.Size(64, 20)
Me.txtnum1.TabIndex = 1
Me.txtnum1.Text = ""
'
'txtnum2
'
Me.txtnum2.Location = New System.Drawing.Point(144, 80)
Me.txtnum2.Name = "txtnum2"
Me.txtnum2.Size = New System.Drawing.Size(64, 20)
Me.txtnum2.TabIndex = 2
Me.txtnum2.Text = ""
'
'txtdenom2
'
Me.txtdenom2.Location = New System.Drawing.Point(144, 120)
Me.txtdenom2.Name = "txtdenom2"
Me.txtdenom2.Size = New System.Drawing.Size(64, 20)
Me.txtdenom2.TabIndex = 3
Me.txtdenom2.Text = ""
'
'txtsumnum
'
Me.txtsumnum.Location = New System.Drawing.Point(376, 80)
Me.txtsumnum.Name = "txtsumnum"
Me.txtsumnum.Size = New System.Drawing.Size(64, 20)
Me.txtsumnum.TabIndex = 4
Me.txtsumnum.Text = ""
'
'txtsumdenom
'
Me.txtsumdenom.Location = New System.Drawing.Point(376, 112)
Me.txtsumdenom.Name = "txtsumdenom"
Me.txtsumdenom.Size = New System.Drawing.Size(64, 20)
Me.txtsumdenom.TabIndex = 5
Me.txtsumdenom.Text = ""
'
'btnAdd
'
Me.btnAdd.Font = New System.Drawing.Font("Microsoft Sans Serif",
14.25!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnAdd.Location = New System.Drawing.Point(80, 96)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(48, 32)
Me.btnAdd.TabIndex = 6
Me.btnAdd.Text = "+"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif",
15.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(248, 96)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(32, 24)
Me.Label1.TabIndex = 7
Me.Label1.Text = "="
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(368, 104)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(80, 4)
Me.ListBox1.TabIndex = 8
'
'ListBox2
'
Me.ListBox2.Location = New System.Drawing.Point(144, 112)
Me.ListBox2.Name = "ListBox2"
Me.ListBox2.Size = New System.Drawing.Size(72, 4)
Me.ListBox2.TabIndex = 9
'
'ListBox3
'
Me.ListBox3.Location = New System.Drawing.Point(8, 104)
Me.ListBox3.Name = "ListBox3"
Me.ListBox3.Size = New System.Drawing.Size(64, 4)
Me.ListBox3.TabIndex = 10
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(472, 266)
Me.Controls.Add(Me.ListBox3)
Me.Controls.Add(Me.ListBox2)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.txtsumdenom)
Me.Controls.Add(Me.txtsumnum)
Me.Controls.Add(Me.txtdenom2)
Me.Controls.Add(Me.txtnum2)
Me.Controls.Add(Me.txtnum1)
Me.Controls.Add(Me.txtdenom1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim WithEvents clsfraction As New fraction
Dim WithEvents clsfraction1 As New fraction

Dim denominator, denominator1 As Int16



Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Dim common, numer1, numer2, denom, total As Int16
Dim gcd As Int16 'holds value of gcd

numer1 = Val(txtnum1.Text)
numer2 = Val(txtnum2.Text)
denominator = Val(txtdenom1.Text)
denominator1 = Val(txtdenom2.Text)

common = clsfraction.calculate_common_denominator(denominat or,
denominator1)

total = clsfraction.add(clsfraction, clsfraction1)
gcd = clsfraction.reduce(total, common)

common = common / gcd
total = total / gcd

txtsumnum.Text = total
txtsumdenom.Text = common
End Sub

Private Sub clsfraction1_zerodenom() Handles clsfraction1.zerodenom
MessageBox.Show("Error-Zero in the denominator")

End Sub
End Class

Nov 20 '05 #2

So where do I put this? In the top of the Form code or the the class
code?
Dim newClass as new fraction?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3
...

Dim Object as myClas

Object = new myClas

SomeFunction(Object

...

Public Function SomeFunction(ByVal Object as myClass) as boolea

' Then you just call the properties or functio
Object.MyFunction(
Object.Name = "This is my object

..

End Function
Nov 20 '05 #4
However, if you use the word Object you must surround in [brackets]

"Sean" <an*******@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
...

Dim Object as myClass

Object = new myClass

SomeFunction(Object)

...
Public Function SomeFunction(ByVal Object as myClass) as boolean

' Then you just call the properties or function
Object.MyFunction()
Object.Name = "This is my object"

...

End Function

Nov 20 '05 #5
Hehe, yeah, was just meant to be pseudo code.....8P
Nov 20 '05 #6
"=?Utf-8?B?U2Vhbg==?=" <an*******@discussions.microsoft.com> wrote in
news:7C**********************************@microsof t.com:
Hehe, yeah, was just meant to be pseudo code.....8P


Does this allow me to use the members of the class seperately?? John
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
25
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
11
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to...
4
by: Ron Rohrssen | last post by:
I want to show a dialog and when the form (dialog) is closed, return to the calling form. The calling form should then be able to pass the child form to another object with the form as a...
3
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing...
3
by: Marc Castrechini | last post by:
First off this is a great reference for passing data between the Data Access and Business Layers:...
10
by: Stan | last post by:
There are two ways to pass structured data to a web service: xml === <Order OrderId="123" OrderAmount="234" /> or class =====
11
by: Macca | last post by:
Hi, I'm writing an application that will pass a large amount of data between classes/functions. In C++ it was more efficient to send a pointer to the object, e.g structure rather than passing...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.