Solved

output file creating

Posted on 2003-11-16
11
1,294 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

789 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