Solved

output file creating

Posted on 2003-11-16
11
1,296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Access combo box help 2 57
vb6 connector to mongodb 2 161
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 64
IF ELSE Statement in Excel Macro VBA 16 98
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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

739 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