vb.net代码,用于通过使用类函数添加两个数字. [英] vb.net code for addition of two number by using class function....

查看:82
本文介绍了vb.net代码,用于通过使用类函数添加两个数字.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨......
plz 请帮我解决这个问题,我没有得到确切的代码来获取输出,方法是使用类函数...将两个数字相加....
这是我的表格代码...

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......

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............

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 如果我遇到了问题,请帮助我...


plz Please help me where i am getting wrong...

推荐答案

尝试一下
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


这样写,我希望会起作用的
write like this i hope it will work
TextBox5.Text =c.addition(a, b).ToString



功能上也有所改变



in function also make change

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


您需要分配结果为一些复数.

尝试C = C.addition(a,b)


TextBox5.Text = c.ToString可能无法给出实际结果.
尝试转换为字符串格式.
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.


这篇关于vb.net代码,用于通过使用类函数添加两个数字.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆