DataGridView conversion problems

G

GrispernMix

Imports System.Windows.Forms
Imports System.Convert
Imports Microsoft.VisualBasic.Financial

Public Class Chapter7

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim result As DialogResult
result = MessageBox.Show("Do you really want to quit", "Exit",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If result = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If
End Sub



Private Sub DataGridView1_CellContentClick(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentClick


End Sub

Private Sub btnCreateAccount_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnCreateAccount.Click
DataGridView1.Columns.Add("Column1", "Loan Amount")
DataGridView1.Columns.Add("Column2", "Annual Interest Rate")
DataGridView1.Columns.Add("Column3", "Term in Years")
DataGridView1.Columns.Add("Column4", "Result Cell")
btnCreateAccount.Enabled = False
btnDeleteAccount.Enabled = True
btnAddAccount.Enabled = True
btnCalculate.Enabled = True
End Sub

Private Sub btnAddRow_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnAddAccount.Click
DataGridView1.Rows.Add()

End Sub
Private Sub btnDeleteRow_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnDeleteAccount.Click
DataGridView1.Rows.RemoveAt(0)
End Sub

Private Sub Chapter7_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
btnDeleteAccount.Enabled = False
btnAddAccount.Enabled = False
btnCalculate.Enabled = False
End Sub

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs)
Dim InterestRate As Double
Dim Payments As Integer
Dim LoanAmountP As Double
Dim LoanAmountC As Double
Dim LoanAmountCell As DataGridViewCell 'reference cell
Dim InterestCell As DataGridViewCell 'reference cell
Dim TermCell As DataGridViewCell 'reference cell
Dim ResultCell As DataGridViewCell 'reference cell
Dim MiddleMan As String
LoanAmountCell = DataGridView1.Rows(0).Cells(0)
MiddleMan = LoanAmountCell.ToString

LoanAmountP = ToDouble(MiddleMan) ' converts the string i just
got from the datagridview cell into a double
InterestCell = DataGridView1.Rows(1).Cells(1)
TermCell = DataGridView1.Rows(2).Cells(2)
InterestRate = (ToDouble(InterestCell.ToString) * 0.1) / 12
Payments = CInt(TermCell.ToString) * 12
'LoanAmountP = (LoanAmountP * InterestRate * Payments) -
LoanAmountP
ResultCell = Pmt(InterestRate, Payments, LoanAmountP)




End Sub
End Class

My pmt is having trouble taking the loanAmountP variable, i was
wondering if anyway has any hints on what the problem might be.
 
R

RobinS

You need to post the code for the pmt function.
I'd check and make sure the variable types match.
When you say it's having trouble, what specifically
is it doing, or not doing?

Robin S.
-----------------
 
K

Ken Tucker [MVP]

Hi,

A datagridviewcell's ToString will return the cell type
(datagridviewtextboxcolumn) not is value. Use the cells value instead.

InterestRate = (ToDouble(InterestCell.Value.ToString) * 0.1) / 12
Payments = CInt(TermCell.Value.ToString) * 12

Ken
----------------------
 
K

Ken Tucker [MVP]

Hi,

The DataGridViewCell's ToString method returns the cell type (ie
datagridviewtextboxcell) not its value. Use it's value property instead.

InterestRate = (ToDouble(InterestCell.Value.ToString) * 0.1) / 12
Payments = CInt(TermCell.Value.ToString) * 12

Ken
------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top