Can someone help me with

I have tried to make this program work. My client needs it print the answers (1 or 2) into the column of starting of A2 of Excel...but it isn't working...can anybody please help me?

Public Class Form1
Dim Answer As Integer
Dim Time As Integer
Dim startTime As DateTime

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

'Start a new workbook in Excel
oExcel = CreateObject("EXCEL.Application")
oBook = oExcel.Workbooks.Add

'Create an array with 2 columns and 100 rows
Dim DataArray(0 To 100, 0 To 1) As Object
Dim r As Integer
For r = 1 To 100
DataArray(r, 1) = Answer
DataArray(r, 2) = Time

'Add headers to the worksheet on row 1
oSheet = oBook.Worksheets(1)
Dim Header(0 To 1) As String
Header(0) = "Subject's Answers"
Header(1) = "Time"
oSheet.Range("A1").Value = Header(0)
oSheet.Range("B1").Value = Header(1)

'Transfer the array to the worksheet starting at cell A2
oSheet.Range("A2:B2").Resize(100, 3).Value = DataArray

'Save the Workbook and Quit Excel
oBook.SaveAs("C:UsersJaeHyung SheenDocumentsVisual Studio 2010ProjectsData.xlsx")

'Stop Watch

End Sub

Private Sub Form1_keypress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
'Pressing Buttons
If e.KeyChar = Chr(Keys.NumPad1) Then
Answer = 1
ElseIf e.KeyChar = Chr(Keys.NumPad2) Then
Answer = 2
End If

End Sub

End Class

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!