Solved

output file creating

Posted on 2003-11-16
11
1,295 Views
Last Modified: 2010-05-01
I am a n00b at vb and I need a vb6.0 to create a log file I have the form pretty together and I got it running evey x minutes with a command button or at a certian time<- I had to make an alarm so I copied that code! My problem is I am not sure how to creat output files in vb6.0 and I need the code also we want to name the text that it creates the time and date cause its going to become a log file of all the users in a computer lab.  Also I don't need the code for this yet but, is it possible to tell VB to open up Excel and use the data in the text file to creat a bunch of graphs and charts...I am still in college and this is my first semester of vb.  They drill us with c++ for 2.5 years.


Thanks for the help,
whatsgoingon
0
Comment
Question by:whatsgoingon66
  • 6
  • 3
  • 2
11 Comments
 
LVL 3

Assisted Solution

by:NBrownoh
NBrownoh earned 45 total points
ID: 9761206
   Dim FileA
    FileA = FreeFile
    Open "C:\Out.log" For Output As FileA
    Print #FileA, "Hey"
    Close FileA

replace "C:\Out.Log" with whatever you want the path to be, it can be a string variable.

replace "Hey" in the Print line to print the text you want to save in the text file.

This is how to read the file then display it in a msgbox:

    FileA = FreeFile
    Open "C:\Out.log" For Input As FileA
    Input #FileA, Tstr
    Close FileA
    MsgBox Tstr
0
 
LVL 11

Expert Comment

by:bingie
ID: 9761242
If you want to log the events you shoud open your file for Append. This will add to the data in the file as oppose to using Output will will overwrite the data.

   Dim FileA
   FileA = FreeFile
   Open "C:\Out.log" For Append As FileA
   Print #FileA, "Hey"
   Close FileA
0
 
LVL 11

Accepted Solution

by:
bingie earned 80 total points
ID: 9761272
For your excel question, you can use the Excel 10.0 Object and thus use any function in excel, for charts or calculation.

Click Project - References - Microsoft Excel 10.0 Object Library


'Paste the following code and run the program

Private Sub CreateChart()
 Dim XLApp As Excel.Application
 Dim XLwb As Excel.Workbook
 Dim XLws As Excel.Worksheet
 Dim XLChart As Excel.Chart
 
 Set XLApp = New Excel.Application
 XLApp.DisplayAlerts = False
 
 'Create new workbook
 Set XLwb = XLApp.Workbooks.Add()
 
 'Get the first worksheet
 Set XLws = XLwb.Worksheets(1)
 
 'Add chart to specific coordinates
 Set XLChart = XLws.ChartObjects.Add(0, 0, 312, 236).Chart
 
 'Specify the chart type
 XLChart.ChartType = xlLine
 
 'Set the data of the chart
 XLChart.SetSourceData XLws.Range("A1:A10")
 
 'Set the title
 XLChart.HasTitle = True
 XLChart.ChartTitle.Caption = "Chart Test"
   
 'Save and close workbook
 XLwb.Close True, App.Path & "\test.xls"
 
 'Close application
 XLApp.Quit

End Sub

Private Sub Form_Load()

CreateChart()

End Sub


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:whatsgoingon66
ID: 9761311
ok thanks guys I just have 1 questions I got the file to write and Append fine but its all on 1 line I though this would make another line. txtlog.Text = txtlog.Text + LF + CR  
My teacher really is useless and I need this for my job(where I am just supposed to be a help desk person for office and e-mail) and I am gonna try and get some more points for you guys thanks alot for the excel question. I miss my C++ got endl ? :) thanks again

later,
whatsgoingon
0
 
LVL 11

Expert Comment

by:bingie
ID: 9761352
Sure,

You have to use VbCrLF

Print #FileA, "Hey" + VBCrLF

0
 
LVL 11

Expert Comment

by:bingie
ID: 9761380
Thanks!
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9761407
thanks for the points, and thanks to bingie for the help on the file access stuff, im a bit rusty too :)
0
 
LVL 11

Expert Comment

by:bingie
ID: 9761416
anytime....
0
 

Author Comment

by:whatsgoingon66
ID: 9761419
well here is something wierd every time I added the line

CreateChart()
it said Expected =

so I changed
Private Sub CreateChart() to
Private Function CreateChart() As Boolean
CreateChart = true

and then it worked fine and created the chart and everything

anyway just though that was some crazy vb crazyness

anyway thanks alot

I hope I gave enough points to everybody If I didn't I am sorry jsut tell me how much I should give for next time

later,
whatsgoingon
0
 
LVL 11

Expert Comment

by:bingie
ID: 9761435
HA!

Nathan, looks like i goofed!

It should read

   Print #FileA, "Hey" & VBCrLF

NOT

   Print #FileA, "Hey" + VBCrLF

Its getting late here...



0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9761485
true true, i only use plus for math stuff anymore, back in the day i used to use it for string manip but liked & better.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question