Welcome to Dream.In.Code
Become a VB Expert!

Join 149,540 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,506 people online right now. Registration is fast and FREE... Join Now!




Making Object Oriented

 
Reply to this topicStart new topic

Making Object Oriented, Don't understand how to connect everything to make work properly

libby50
19 Nov, 2007 - 06:34 PM
Post #1

New D.I.C Head
*

Joined: 8 Nov, 2007
Posts: 15


My Contributions
Don't know how to make everything work..need advice


CODE

Private Sub CalcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcButton.Click
        Dim Rate As Double
        Dim Nper As Double
        Dim PV As Double
        Dim FV As Double
        Dim Due As DueDate
        Dim returnValue As Double
        

        ' Setting the values to each of our variables.    
        Rate = 0.06
        Nper = 4
        PV = 12000
        FV = 0.0
        Due = DueDate.EndOfPeriod


        returnValue = -Financial.Pmt(Rate, Nper, PV, FV, Due)

        PaymentsLabel.Text = returnValue



    End Sub

End Class


***This is my class called Loan***
CODE
Public Class Loan
    'attributes section
    Private _loan As Decimal
    Private _interest As Decimal
    Private _term As Decimal

End Class

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Making Object Oriented
19 Nov, 2007 - 06:57 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
What exactly are you attempting to do here? Are you trying to make your class into what your CalcButton_click event is doing? Describe the objective and then we can give you an idea how the pieces would fit together.

Thanks! smile.gif
User is offlineProfile CardPM
+Quote Post

libby50
RE: Making Object Oriented
19 Nov, 2007 - 07:05 PM
Post #3

New D.I.C Head
*

Joined: 8 Nov, 2007
Posts: 15


My Contributions
Martyr2...I am trying to make the solution objected -oriented by creating a Class called Loan with instance variables for amount, interest, and term. And I also have to use the Financial.Pmt method to calcaluate the payment...I hope that helps...Thanks in advance



QUOTE(Martyr2 @ 19 Nov, 2007 - 07:57 PM) *

What exactly are you attempting to do here? Are you trying to make your class into what your CalcButton_click event is doing? Describe the objective and then we can give you an idea how the pieces would fit together.

Thanks! smile.gif


User is offlineProfile CardPM
+Quote Post

libby50
RE: Making Object Oriented
26 Nov, 2007 - 04:40 PM
Post #4

New D.I.C Head
*

Joined: 8 Nov, 2007
Posts: 15


My Contributions
Please help..trying to make my class into what the CalcButton_click event is doing? Looking for guidance....Thanks in advance
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Making Object Oriented
26 Nov, 2007 - 08:33 PM
Post #5

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,303



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Put all the code that is inside the button click event into a function of your Loan class that returns the payment value. Then instantiate an object of that class and you will have access to the function that returns the payment amount.

Use code.gif tags when posting code.
User is offlineProfile CardPM
+Quote Post

libby50
RE: Making Object Oriented
27 Nov, 2007 - 09:39 AM
Post #6

New D.I.C Head
*

Joined: 8 Nov, 2007
Posts: 15


My Contributions
Could someone show an example of how to put the code inside the button click event into a function of your Loan class that returns the payment value. Then instantiate an object of that class. VB is very hard for me but I really am trying to learn..Thanks
User is offlineProfile CardPM
+Quote Post

libby50
RE: Making Object Oriented
27 Nov, 2007 - 11:00 AM
Post #7

New D.I.C Head
*

Joined: 8 Nov, 2007
Posts: 15


My Contributions
QUOTE(libby50 @ 27 Nov, 2007 - 10:39 AM) *

Could someone show an example of how to put the code inside the button click event into a function of your Loan class that returns the payment value. Then instantiate an object of that class. VB is very hard for me but I really am trying to learn..Thanks



CODE
Option Explicit On

Imports System.Globalization


Public Class MainForm
    'declare instance variables of Mainform
    Private myCurrent As Loan
    Private myRate As Loan
    Private myNper As Loan
    Private isConverted As Boolean


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'instantiate an objects
        myCurrent = New Loan()
        myRate = New Loan()
        MyNper = New Loan()
    End Sub

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()
    End Sub


    Private Sub ResetButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetButton.Click
        principalTextBox.Clear()
        IntTextBox.Clear()
        TermTextBox.Clear()
    End Sub

    Private Sub CalcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcButton.Click
        Dim Rate As Decimal
        Dim Nper As Double
        Dim PV As Double
        Dim CalculateTotal As Loan
        Dim value As Decimal
        Dim total As Decimal
        Dim Current As Double
        ' Setting the values to each of our variables.    
        Rate = value
        Nper = 4
        PV = value

        If isConverted Then
            'calculate total

            total = CalculateTotal()

            PaymentsLabel.Text = total

        End If



    End Sub

End Class


CLASS PAGE CODE
CODE

Public Class Loan
    'instance variables
    Private _current As Decimal
    Private _rate As Decimal
    Private _nper As Decimal
  
    ' constructor
    Public Sub New(Optional ByVal theCurrent As Decimal = 0, _
                   Optional ByVal theRate As Decimal = 0, _
                   Optional ByVal theNper As Decimal = 0)
        _current = theCurrent
        _rate = theRate
        _nper = theNper
    End Sub

    'Property procedures
    Public Property Current() As Decimal
        Get
            Return _current
        End Get
        Set(ByVal value As Decimal)
            _current = value
        End Set
    End Property


    'Property procedures
    Public Property Rate() As Decimal
        Get
            Return _rate
        End Get
        Set(ByVal value As Decimal)
            _rate = value
        End Set
    End Property


    'Property procedures
    Public Property Nper() As Decimal
        Get
            Return _nper
        End Get
        Set(ByVal value As Decimal)
            _nper = value
        End Set
    End Property


    Public Function CalculateTotal() As Decimal
        Return -Financial.Pmt(Rate, Nper, Current)
    End Function



End Class

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 09:20PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month