Calling methods

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon

    #1

    Calling methods

    I have a class for complex numbers and an exponential function. This
    event handler does not reach Expz in debug mode:

    z = New Complex(CDbl(Re al.Text), CDbl(Imag.Text) )

    Real.Text = CStr(z.Expz().G etReal())
    Imag.Text = CStr(z.Expz().G etImaginary())

    But when I do this

    z = z.Expz()
    Real.Text = CStr(z.GetReal( ))
    Imag.Text = CStr(z.GetImagi nary())

    Or even this

    Dim w As Complex = z.Expz()
    Real.Text = CStr(z.Expz().G etReal())
    Imag.Text = CStr(z.Expz().G etImaginary())

    it executes the calculation and displays it. What's up here?


    Jon Cosby

    *************** *************** *************** ***************
    Public Class Complex
    Private Shared re As Double
    Private Shared im As Double

    Public Sub New(ByVal x As Double, ByVal y As Double)
    re = x
    im = y
    End Sub

    Public Shared Function Expz() As Complex
    Dim w As Complex

    w = New Complex(Exp(re) * Cos(im), Exp(re) * Sin(im))
    Return w
    End Function

  • Bart Mermuys

    #2
    Re: Calling methods

    Hi,

    "Jon" <nospam@jcosby. com> wrote in message
    news:1128289172 .133613.114630@ g49g2000cwa.goo glegroups.com.. .[color=blue]
    >I have a class for complex numbers and an exponential function. This
    > event handler does not reach Expz in debug mode:
    >
    > z = New Complex(CDbl(Re al.Text), CDbl(Imag.Text) )
    >
    > Real.Text = CStr(z.Expz().G etReal())
    > Imag.Text = CStr(z.Expz().G etImaginary())
    >
    > But when I do this
    >
    > z = z.Expz()
    > Real.Text = CStr(z.GetReal( ))
    > Imag.Text = CStr(z.GetImagi nary())
    >
    > Or even this
    >
    > Dim w As Complex = z.Expz()
    > Real.Text = CStr(z.Expz().G etReal())
    > Imag.Text = CStr(z.Expz().G etImaginary())
    >
    > it executes the calculation and displays it. What's up here?
    >
    >
    > Jon Cosby
    >
    > *************** *************** *************** ***************
    > Public Class Complex
    > Private Shared re As Double
    > Private Shared im As Double[/color]

    Shared means that *all* Complex objects will use the same re and im, i don't
    think that's what you want, each Complex number should have its own re and
    im. Remove "Shared".
    [color=blue]
    >
    > Public Sub New(ByVal x As Double, ByVal y As Double)
    > re = x
    > im = y
    > End Sub
    >
    > Public Shared Function Expz() As Complex
    > Dim w As Complex[/color]

    Same here, The Expz must be applied to one Complex object. Shared methods
    are usually called with the class name like Complex.Expz(). This is not
    what you want here, remove "Shared".


    HTH,
    Greetings

    [color=blue]
    >
    > w = New Complex(Exp(re) * Cos(im), Exp(re) * Sin(im))
    > Return w
    > End Function
    >[/color]


    Comment

    Working...