Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Can someone help me with VB.net?
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")
Private Sub Form1_keypress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = Chr(Keys.NumPad1) Then
Answer = 1
ElseIf e.KeyChar = Chr(Keys.NumPad2) Then
Answer = 2