.NET General

Moderators: None (Apply to moderate this forum)
Number of threads: 749
Number of posts: 1301

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Can someone help me with VB.net? Posted by DSheen on 15 Jun 2012 at 7:46 AM
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
Next

'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:\Users\JaeHyung Sheen\Documents\Visual Studio 2010\Projects\Data.xlsx")
oExcel.Quit()


'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
Btn1.PerformClick()
Answer = 1
ElseIf e.KeyChar = Chr(Keys.NumPad2) Then
Btn2.PerformClick()
Answer = 2
End If

End Sub

End Class






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.