Problem that i still dont know.

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 1679 Views - Last Post: 20 March 2013 - 09:55 AM Rate Topic: -----

#1 egeboy099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-September 12

Problem that i still dont know.

Posted 19 March 2013 - 06:09 AM

this is just simple program that i edited.

here is goes :
only 1 Form.

this is a loan application.

the user input's a principal amount , interest and # of months
the calculate button works
but the schedule contains an error.

Public Class Loan_Calculation

    Private Sub objPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
        Select Case Asc(e.KeyChar)
            Case 48 To 57
            Case 46, 8
            Case Else
                e.Handled = True
        End Select
    End Sub

Private Sub InterestPayment()
    Dim intAmount As Double = 0
    Dim principal As Double = Me.txtPrincipal.Text
    Dim intInterestRate As Double = Me.txtInterest.Text
    Dim principalPayment As Double = 0

    intAmount = (principal * intInterestRate * 0.01) / 12
    principalPayment = principal / CDbl(Me.txtPeriod.Text)
    txtMonthlyInterestPayment.Text = FormatCurrency(intAmount, 2)

    Me.txtMonthlyPrincipalPayment.Text = principalPayment

    Dim intPay As Double = CDbl(Me.txtMonthlyInterestPayment.Text)
    Dim principalpay As Double = Me.txtMonthlyPrincipalPayment.Text
    Dim TotalPayment As Double = intPay + principalpay

    Me.txtTotalPayment.Text = FormatCurrency(TotalPayment, 2)
End Sub

Private Sub btnCalculation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculation.Click
    If Not IsNumeric(Me.txtPrincipal.Text) Then
        MsgBox("Invalid principal value.", MsgBoxStyle.Exclamation, "Invalid Value")
        Return
    End If

    If Not IsNumeric(Me.txtPeriod.Text) Then
        MsgBox("Invalid period value.", MsgBoxStyle.Exclamation, "Invalid Period")
        Return
    End If

    If Not IsNumeric(Me.txtInterest.Text) Then
        MsgBox("Invalid interest rate value.", MsgBoxStyle.Exclamation, "Invalid Interest Rate")
        Return
    End If

    InterestPayment()
End Sub

Private Sub txtPrincipal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPrincipal.KeyPress
    objPress(sender, e)
End Sub

Private Sub txtInterest_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtInterest.KeyPress
    objPress(sender, e)
End Sub

Private Sub txtPeriod_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPeriod.KeyPress
    objPress(sender, e)
End Sub

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

Public Class Schedule

    Dim dPrincipal As Double = 0
    Dim dIntInterestRate As Double = 0
    Dim iPeriod As Integer
    Dim dtValueDate As Date
    Dim sType As String = ""

    Public WriteOnly Property Principal() As Double
        Set(ByVal value As Double)
            dPrincipal = value
        End Set
    End Property

    Public WriteOnly Property InterestRate() As Double
        Set(ByVal value As Double)
            dIntInterestRate = value
        End Set
    End Property

    Public WriteOnly Property Period() As Integer
        Set(ByVal value As Integer)
            iPeriod = value
        End Set
    End Property

    Public WriteOnly Property ValueDate() As Date
        Set(ByVal value As Date)
            dtValueDate = value
        End Set
    End Property

    Public WriteOnly Property LoanType() As String
        Set(ByVal value As String)
            sType = value
        End Set
    End Property

    Public Sub GenerateScheule()
        Dim monthlyInt As Double = 0
        Dim monthlyPrincipal As Double = 0
        Dim dtDate As Date
        Dim total As Double

        monthlyInt = (dPrincipal * dIntInterestRate * 0.01) / 12
        monthlyPrincipal = dPrincipal / iPeriod

        For i As Integer = 1 To iPeriod
            dtDate = dtValueDate.AddMonths(i)

            total = monthlyPrincipal + monthlyInt

            Loan_Calculation.dgvLoanSchedule.Rows.Add(i, Format(dtDate, "dd/MMM/yyyy"), FormatCurrency(monthlyInt, 2), FormatCurrency(monthlyPrincipal, 2), FormatCurrency(total, 2))

            dPrincipal -= monthlyPrincipal
            monthlyPrincipal = dPrincipal / iPeriod
            monthlyInt = (dPrincipal * dIntInterestRate * 0.01) / 12

        Next
    End Sub

End Class

Private Sub btnSchedule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSchedule.Click
        Schedule()
    End Sub
End Class





here's the error.

Private Sub btnSchedule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSchedule.Click
        Schedule()
    End Sub
End Class



Schedule() - i dont know whats the error behind this... i just needed to display the items in the datagridview.

attachment - just view the picture.

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Problem that i still dont know.

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Problem that i still dont know.

Posted 19 March 2013 - 06:24 AM

That's not an error, it's a call to a subroutine.

Are you receiving any error messages?
If so, it would be good to know what they are.

Is it not producing the results you expect?

EDIT: actually after a closer look, that is a class and cannot be called in that manner.
You would want to instantiate it and fill it's properties with the required information from your textboxes and then process the GenerateSchedule method.

This post has been edited by CharlieMay: 19 March 2013 - 06:39 AM

Was This Post Helpful? 0
  • +
  • -

#3 egeboy099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-September 12

Re: Problem that i still dont know.

Posted 19 March 2013 - 07:08 AM

View PostCharlieMay, on 19 March 2013 - 06:24 AM, said:

That's not an error, it's a call to a subroutine.

Are you receiving any error messages?
If so, it would be good to know what they are.

Is it not producing the results you expect?

EDIT: actually after a closer look, that is a class and cannot be called in that manner.
You would want to instantiate it and fill it's properties with the required information from your textboxes and then process the GenerateSchedule method.


heres the error :

Error	1	'GenerateScheule' is not declared. It may be inaccessible due to its protection level.	


Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Problem that i still dont know.

Posted 19 March 2013 - 07:29 AM

So you've made changes from the original code you provided?

Where are you calling GenerateScheule?

Show me that block of code.
Was This Post Helpful? 0
  • +
  • -

#5 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Problem that i still dont know.

Posted 19 March 2013 - 02:10 PM

Hmm... I would also point out that in the (original) code, your btnSchedule_Click handler is in between 2 End Class statements.
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Problem that i still dont know.

Posted 19 March 2013 - 02:31 PM

Yea, I saw that too lar3ry but then it appears OP has a class inside the form class. The error tells me that some code changes have been made since the initial post because to use Schedule() in that way would be a different error than what listed.
Was This Post Helpful? 0
  • +
  • -

#7 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Problem that i still dont know.

Posted 19 March 2013 - 10:06 PM

View PostCharlieMay, on 19 March 2013 - 03:31 PM, said:

Yea, I saw that too lar3ry but then it appears OP has a class inside the form class.

I'm surprised that a Class within another Class is legal. I did a little research, and found that it is indeed legal, but some of the comments I saw said that it should be declared as Private, making it accessible only to the outer Class. I do see that in this case, nothing else is likely to try to access it, but it still seems a little iffy to me.

Anyway, yes, I too am awaiting his changed code.

This post has been edited by lar3ry: 19 March 2013 - 10:07 PM

Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,450
  • Joined: 29-May 08

Re: Problem that i still dont know.

Posted 19 March 2013 - 10:34 PM

@lar3ry:- There a current topic that touch on Inner Classes (here), if your interested.

This post has been edited by AdamSpeight2008: 19 March 2013 - 10:37 PM

Was This Post Helpful? 0
  • +
  • -

#9 egeboy099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-September 12

Re: Problem that i still dont know.

Posted 20 March 2013 - 03:01 AM

View Postlar3ry, on 19 March 2013 - 10:06 PM, said:

View PostCharlieMay, on 19 March 2013 - 03:31 PM, said:

Yea, I saw that too lar3ry but then it appears OP has a class inside the form class.

I'm surprised that a Class within another Class is legal. I did a little research, and found that it is indeed legal, but some of the comments I saw said that it should be declared as Private, making it accessible only to the outer Class. I do see that in this case, nothing else is likely to try to access it, but it still seems a little iffy to me.

Anyway, yes, I too am awaiting his changed code.


sorry but im here to know how to correct this.

so what should i do now?
Was This Post Helpful? 0
  • +
  • -

#10 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Problem that i still dont know.

Posted 20 March 2013 - 03:30 AM

egeboy099 i'm still waiting for the code where you're using the GenerateSchule method that is throwing that error.
Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,450
  • Joined: 29-May 08

Re: Problem that i still dont know.

Posted 20 March 2013 - 04:05 AM

What do think
Private Sub btnSchedule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSchedule.Click
        Schedule()
    End Sub
End Class



should do?
Was This Post Helpful? 0
  • +
  • -

#12 egeboy099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-September 12

Re: Problem that i still dont know.

Posted 20 March 2013 - 05:24 AM

View PostAdamSpeight2008, on 20 March 2013 - 04:05 AM, said:

What do think
Private Sub btnSchedule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSchedule.Click
        Schedule()
    End Sub
End Class



should do?


even i change it to : GenerateScheule()

still not working.... GenerateScheule() has a blue line.
Was This Post Helpful? 0
  • +
  • -

#13 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Problem that i still dont know.

Posted 20 March 2013 - 06:09 AM

because you need to instantiate that object
Dim ASchedule As New Schedule

Then you can pass your values into the properties
ASchedule.Principal = txtPrincipal.Text

..Repeat for all the properties you need.

Then after you've done all that, execute the method that will take those properties and perform an action.
ASchedule.GenerateSechule

You're trying to call it like a subroutine when it's not, it's a class (a new type) that has a method (the generatescheule sub) that you can perform. But as with any object, you need to create a NEW one first.

This post has been edited by CharlieMay: 20 March 2013 - 06:10 AM

Was This Post Helpful? 0
  • +
  • -

#14 egeboy099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-September 12

Re: Problem that i still dont know.

Posted 20 March 2013 - 08:10 AM

View PostCharlieMay, on 20 March 2013 - 06:09 AM, said:

because you need to instantiate that object
Dim ASchedule As New Schedule

Then you can pass your values into the properties
ASchedule.Principal = txtPrincipal.Text

..Repeat for all the properties you need.

Then after you've done all that, execute the method that will take those properties and perform an action.
ASchedule.GenerateSechule

You're trying to call it like a subroutine when it's not, it's a class (a new type) that has a method (the generatescheule sub) that you can perform. But as with any object, you need to create a NEW one first.


i tried this but this is too confusing for me.

can you make it more simple.
Was This Post Helpful? 0
  • +
  • -

#15 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Problem that i still dont know.

Posted 20 March 2013 - 08:24 AM

I'm afraid that without me actually just fixing the code you supplied in your first post, that it's doesn't get much easier than what I just explained.

Have you even tried putting that information into your Schedule Button?

Here's a tip, don't copy and paste it, type it in there and when you get to the second line to the point of typing ASchedule. you should have an eye-opening experience as to what you need to do.

If that's not enough, then I suggest you go to the VB.Net FAQ & Resources topic that AdamSpeight2008 has pinned to the top of the forum and work through the first entry "Just Started VB.Net? Stuck?" because it appears there's a lot of the basics that you're not understanding yet.

This post has been edited by CharlieMay: 20 March 2013 - 08:25 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2