Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi....
plz Please help me out to solve this problem I am nt getting exact code to get output as addition of two numbers by using class function....
this is my code for form......
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       a.Real = Val(TextBox1.Text)
       a.Imaginary = Val(TextBox2.Text)

       b.Real = Val(TextBox3.Text)
       b.Imaginary = Val(TextBox4.Text)
       c.addition(a, b)
       TextBox5.Text = c.ToString
   End Sub

And this s my code for class function............
VB
Public Function addition(ByVal c1 As complexnumber, ByVal c2 As complexnumber) As complexnumber
    Dim result As New complexnumber(c1.Real + c2.Real, c1.Imaginary + c2.Imaginary)
    Return result
End Function>

plz Please help me where i am getting wrong...
Posted
Updated 19-Jun-12 0:56am
v2

Try this
VB
Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim a, b, c As New COmplexNumber
        a.realNum = 1
        a.imaginary = 2
        b.realNum = 2
        b.imaginary = 3

        c = c.Addition(a, b)

        TextBox1.Text = c.realNum & "+i" & c.imaginary
    End Sub
End Class
Public Class COmplexNumber
    Public realNum As Integer
    Public imaginary As Integer
    Public Function Addition(num1 As COmplexNumber, num2 As COmplexNumber) As COmplexNumber
        Dim result As New COmplexNumber
        result.realNum = (num1.realNum + num2.realNum)
        result.imaginary = (num1.imaginary + num2.imaginary)
        Addition = result
    End Function
End Class
 
Share this answer
 
Comments
arizan 19-Jun-12 7:26am    
hey thanx alot it worked.......
Geo Jackson 19-Jun-12 7:27am    
Welcome
write like this i hope it will work
VB
TextBox5.Text =c.addition(a, b).ToString


in function also make change

VB
Public Function addition(ByVal c1 As complexnumber, ByVal c2 As complexnumber) As complexnumber
    Dim result As New complexnumber(c1.Real + c2.Real, c1.Imaginary + c2.Imaginary)
    addition= result
End Function
 
Share this answer
 
v2
Comments
arizan 19-Jun-12 7:08am    
thanx but i am getting an error as "Object reference not set to an instance of an object."
Prosan 19-Jun-12 7:14am    
now your problem will be solved. try it. it will sure work.
arizan 19-Jun-12 7:15am    
thanx but same error again.....
You nee to assign the result to some complex number.

Try C=C.addition(a,b)


TextBox5.Text=c.ToString might not give actual result .
Try Converting to String Format.
 
Share this answer
 
v2
Comments
arizan 19-Jun-12 7:14am    
thanx..
& i have done it... but getting the same error as "Object reference not set to an instance of an object."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900