VB Program

Dalamar
02-28-2003, 08:10 AM
Hey,
How would you make a high-school scheduling program on visual basic?
If needed how would you input information from an excel sheet to the vb program to read the data for all the courses?
Thanks

Wamphyri
02-28-2003, 08:41 AM
Hey,
How would you make a high-school scheduling program on visual basic?


You'd program it! :) But seriously, you'll have to give more info on how you'd like to set up you scheduling program.


If needed how would you input information from an excel sheet to the vb program to read the data for all the courses?
Thanks

Reading data from Excel to VB is fairly simple. First you need to add a reference to the Microsoft Excel Object Library. It's under Projects -> Reference

Then lets say that you have a textbox in your VB form called TextBox1
and your excel file is C:\MyExcelFile.xls and in cell B1 you have the words Hello World you would retrieve it as follows

Sub GetXLInfo()
Dim xlApp as Excel.Application
Set xlApp = New Excel.Application
'Open Excel File
xlApp.Workbooks.Open Filename:="C:\MyExcelFile.xls"
'Get the Value from cell B1
TextBox1.Text = xlApp.Workbooks("MyExcelFile").Worksheets(1).Cells(1, 2).Value

'Quit excel
xlApp.quit
'Destroy Object
Set xlApp = Nothing
End Sub

Mikecrosoft
02-28-2003, 08:56 AM
Why post this question two times ???


Here is one example of using Excel,

add Project/References/Microsoft Excel X.X Object Library

Add a Command button, and 3 text boxes


Private Sub Command1_Click()
Dim ExcelApp As New Excel.Application
Dim ExcelWB As Excel.Workbook
Dim ExcelWS As Excel.Worksheet

On Error GoTo ExcelErr
Set ExcelApp = GetObject(, "Excel.Application")
ExcelApp.Visible = True

Set ExcelWB = ExcelApp.Workbooks.Open("C:\Excel.xls")
Set ExcelWS = ExcelWB.Worksheets(1)


ExcelWS.Cells(1, 1) = Text1.Text
ExcelWS.Cells(2, 1) = Text2.Text
ExcelWS.Cells(3, 1) = Text3.Text


Exit Sub

ExcelErr:
Select Case Err.Number
Case 429 ' ActiveX Object not found
Set ExcelApp = CreateObject("Excel.Application")
Resume Next
Case Else 'Other Errors
'Error Stuff here

End Select

End Sub

NateBrei
02-28-2003, 02:14 PM
Here's one addition to Mikecrosoft's code solution... Make sure you close your workbook & kill your created objects when you're done with them. Here is an example that could be inserted into Mikecrosoft's example as shown...

'......prior code.......
ExcelWS.Cells(3, 1) = Text3.Text

ExcelWB.Close
ExcelApp.Quit

Set ExcelWS = Nothing
Set ExcelWB = Nothing
Set ExcelApp = Nothing

Exit Sub
'......rest of code......

Hope this helps. BTW...What's with the vb code tags & resulting formatting???
Nate

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum