simple excel, types

SioPao

New member
Joined
Dec 7, 2003
Messages
1
Ok, Ive asked for help in another thread, but couldnt really figure out what I wanted to do from that. Basically what I have is a simple program that allows a user to add an expense (such as food, gas, phone, etc) to a spreadsheet. I want the data to be stored in an excel document so that the charting abilities can be used to display, say, a pie chart with the amount ($) separated by the expense types. Its a project for school.

When the user clicks the add button, this is executed:

Code:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
       Try
           If txtAmount.Text = "" Then
               MessageBox.Show("You must enter the amount of the expense to continue", "Missing Amount", MessageBoxButtons.OK, MessageBoxIcon.Error)
           ElseIf cboAddType.Text = "" Then
               MessageBox.Show("You must select or enter a new type of expense from the list", "Select type", MessageBoxButtons.OK, MessageBoxIcon.Error)
           Else
               Call fnTypeIndex()
               intNumExp += 1
               mnuFileSaveAs.Enabled = True
               Me.tbbSave.Enabled = True
               With xlSheet
                   .Cells(intNumExp, intTypeCol) = cboAddType.Text
                   .Cells(intNumExp, intAmountCol) = CDec(txtAmount.Text)
                   .Cells(intNumExp, intDescriptionCol) = txtDescription.Text
                   .Cells(intNumExp, intDateCol) = dtpDate.Value
               End With
               xlBook.SaveAs()
               Call fnClear()
           End If
       Catch ex As InvalidCastException
           MessageBox.Show("You must enter a number in in decimal form without a dollar sign", "Invalid amount", MessageBoxButtons.OK)
       End Try
End Sub



And when the list box selection to view is changed, this function is called:

Code:
Private Sub fnFillDataGrid(ByVal intIndex As Integer)
  Dim dtrRow As DataRow
  Try
        dtrRow = tblDataTable.NewRow()
        With xlSheet
               dtrRow(dtcType) = .Cells(intIndex, intTypeCol)
               dtrRow(dtcAmount) = .Cells(intIndex, intAmountCol)
               dtrRow(dtcDescription) = .Cells(intIndex, intDescriptionCol)
               dtrRow(dtcDate) = .Cells(intIndex, intDateCol)
         End With
         tblDataTable.Rows.Add(dtrRow)
  Catch ex As Exception
         MessageBox.Show("crap")
  End Try
End Sub


The data is to be shown through a datagrid which is linked to tblDataTable as its source. The problem lies with the latter function, in the With block. The ".Cells(intIndex, intTypeCol)" is not the right type i think.

What is displayed from that function:
http://filebox.vt.edu/users/kisbrand/error.PNG
 
Back
Top