Solved

output file creating

Posted on 2003-11-16
11
1,291 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now