• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1303
  • Last Modified:

output file creating

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
whatsgoingon66
Asked:
whatsgoingon66
  • 6
  • 3
  • 2
2 Solutions
 
NBrownohCommented:
   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
 
bingieCommented:
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
 
bingieCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
whatsgoingon66Author Commented:
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
 
bingieCommented:
Sure,

You have to use VbCrLF

Print #FileA, "Hey" + VBCrLF

0
 
bingieCommented:
Thanks!
0
 
NBrownohCommented:
thanks for the points, and thanks to bingie for the help on the file access stuff, im a bit rusty too :)
0
 
bingieCommented:
anytime....
0
 
whatsgoingon66Author Commented:
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
 
bingieCommented:
HA!

Nathan, looks like i goofed!

It should read

   Print #FileA, "Hey" & VBCrLF

NOT

   Print #FileA, "Hey" + VBCrLF

Its getting late here...



0
 
NBrownohCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now