Link to home
Start Free TrialLog in
Avatar of anandxx
anandxx

asked on

creating data file one per day!!!

OK IM USING VB TO LOG
INFORMATION FORM SERIAL PORT EVERY 15 MINUTES.

THIS INFORMATION WILL BE USED TO CREATE A GRAPH LATER.

I NEED TO SAVE THE INFORMATION 15 MINUTES ONTO

( RECOMMEND A FORMAT) A FILE - PROBLEM IS I NEED TO

SAVE IT TO A FILE ( ONE PER DAY) VIZ

FOR 13 MARCH -  ONE FILE ( CONTANING 15 MIN SLOT DATA FOR 13 MARCH)

SAME FOR 14 MARCH.. ETC.


I USED MDB AND MADE A DATA SET TO TAKE DATA IN.

DONT KNOW HOW TO CREATE A FILE FROM WITH IN VB, OR DO YOU
RECOMMEND OTHER FILE TYPES INSTED OF MDB.


ASHOK
Avatar of hkoldoldguy
hkoldoldguy

Dim fso
Dim FilePath As String
Dim FileInput
Dim dtFileDate As String
Dim sTemp As String
Dim iDay As String
   
Set fso = CreateObject("Scripting.FileSystemObject")
FilePath = App.Path
If Right(FilePath, 1) <> "\" Then
   FilePath = FilePath & "\"
End If
   
If Not fso.FileExists(FilePath & format(now,"yyyymmdd")) Then
   Set log = fso.CreateTextFile(FilePath & format(now,"yyyymmdd")) True)
   log.Write " "
   log.Close
End If
'This should do for adding info to a logfile
'If you want to add it to a mdf where mdf has to
'be an Access database then you have to do a
'lot more....
Public Sub AppLog(strFile as String, strMsg As String)
'''''''''''''''''''
' INPUT: strFile = complete filename without extention
'        strMsg = logmessage
' OUTPUT: Applog("d:\logs\test","show me")
'         adds 01 april 2003 11:08:08 : show me
'         to logfile d:\logs\test20030401.log
'''''''''''''''''''
 Dim intFree As Integer
   
 intFree = FreeFile
 Open strFile & Format(Date, "YYYYMMDD") & ".log" &_
      For Append As #intFree
 Print #intFree, Format(Now, "dd mmm yyyy hh:mm:ss") & _
       & " : " & strMsg
 Close #intFree
   
  Exit Sub
End Sub
anandxx, please don't use all caps !!!
Avatar of anandxx

ASKER

thanks the for the response. sorry about the capitals.


let me try and rephrase the question.

- Yes the data will have to be in a database. (mdb)
  which has fields (time) (date) (number)

- i have made an mdb file COUNT.MDB and am able to
  save into it from VB using a timer (Say 15 min
  interval).

All the above works fine.

However, since it saves to a single file, i will have
relatively huge file in a month or a year.

What im looking to do is instead of saveing to
COUNT.MDB every day, to have a file one per day

say COUNT1.MDB
    COUNT2.MDB

alternatively,  C020403.MDB
                C030403.MDB
                C040403.MDB

WHERE say 02 - date 04 month 03 year.

hope this is more clear.

Regards,

ak
Dear expert(s),

A request has been made to close this Q in CS:
https://www.experts-exchange.com/questions/20582098/can-your-delete-this-questions-havent-got-my-response.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here I have the solution using DAO. You can also use ADOX if you want to but that's a little bit different from DAO. I hope this will help you.

P.s. sorry for the late reaction

' =======================================================
' code in form1 as an example
' form1 is a form with a command button to test the stuff
' =========================================================
Option Explicit

Public gWKS As DAO.Workspace
Public gDB As DAO.Database
Public gRS As DAO.Recordset

Private Sub Command1_Click()
  Dim strDBName As String
   
  strDBName = "c:\log" & Format(Now, "yyyymmdd") & ".mdb"
  OpenDatabase (strDBName)  
  CloseDatabase (strDBName)
   
End Sub

Private Sub OpenDatabase(strDB As String)
  Dim objFSO As Object
  Dim bExists As Boolean, strStamp As String
   
  Set objFSO = CreateObject("Scripting.FileSystemObject")
   
  ' Check if db already exists; if not, create one
  If objFSO.FileExists(strDB) Then
    bExists = True
  Else
    Set gDB = DBEngine.CreateDatabase(strDB, dbLangGeneral)
  End If  
   
  ' Create workspace and open database
  Set gWKS = CreateWorkspace("", "admin", "", dbUseJet)
  Set gDB = gWKS.OpenDatabase(strDB)
       
  ' If new database then generate table
  If bExists Then
    gDB.Execute "insert into LOGDETAILS values ('" & _
                Format(Now, "yyyymmddhhnnss") & _
                "','Database opened')"
  Else
    gDB.Execute "CREATE TABLE LOGDETAILS(" & _
                "Stamp VARCHAR(14) NOT NULL, " & _
                "Detail VARCHAR(40)  NOT NULL)"
  gDB.Execute "insert into LOGDETAILS values ('" & _
                Format(Now, "yyyymmddhhnnss") & _
                "','Database generated')"
  End If
   
  Set objFSO = Nothing

End Sub

Private Sub CloseDatabase(strDB As String)
    gDB.Close
    Set gDB = Nothing
    Set gWKS = Nothing
End Sub

'=========================================================