Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > VB Program


Reply
 
Thread Tools Display Modes
  #1  
Old 02-28-2003, 08:10 AM
Dalamar Dalamar is offline
Freshman
 
Join Date: Feb 2003
Posts: 25
Post VB Program


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
Reply With Quote
  #2  
Old 02-28-2003, 08:41 AM
Wamphyri's Avatar
Wamphyri Wamphyri is offline
Variable not defined

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Ottawa, Ontario
Posts: 4,793
Default

Quote:
Originally Posted by Dalamar
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.

Quote:
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
Code:
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
__________________
-Carl
Reply With Quote
  #3  
Old 02-28-2003, 08:56 AM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default VB Program

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

Code:
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
__________________
Mikecrosoft.NET
* If I stop to ask I will stop to learn
* Just I know that I don't know nothing
Reply With Quote
  #4  
Old 02-28-2003, 02:14 PM
NateBrei's Avatar
NateBrei NateBrei is offline
Contributor
 
Join Date: Jul 2002
Location: Omaha, NE
Posts: 571
Default

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...
Code:
'......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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->