| | |
date and time in file name
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2007
Posts: 5
Reputation:
Solved Threads: 0
You could do something like this (from a snipplet of existing code):
the system.io.file is what you will want to play around with...
Hope this helps.
Dim directoryEntries As String() = System.IO.Directory.GetFileSystemEntries("C:\theDirectory") Dim fileEntries As String() 'Iterates through each directory For Each strDirs As String In directoryEntries 'assign each file to fileentries() fileEntries = System.IO.Directory.GetFiles(strDirs) 'Iterates throught each file For Each strFiles As String In fileEntries Dim fdt As DateTime = System.IO.File.GetLastWriteTime(strFiles) 'Do other stuff... Next Next
the system.io.file is what you will want to play around with...
Hope this helps.
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
I don't think that is what I am looking for. Below is my code-
Yields - MTTLogSent382007_119.txt
Should look like - MTTLogSent03082007_1109.txt
Found solution by playing around with code shortly after posting this. Here is my solution.
vb.net Syntax (Toggle Plain Text)
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click ' Write transactions to text file for audit purposes ' Folder c:\MTTLog Upload must exist on 'c' drive Dim TransLog As String = "c:\MTTap Upload\MTTLogSent" Dim TLDateTime As String Dim TLDay As String Dim TLMonth As Integer Dim TLYear As Integer Dim TLHour As Integer Dim TLMinute As Integer Dim TLDate As String Dim TLTime As String TLDay = DateTime.Now.Day TLMonth = DateTime.Now.Month TLYear = DateTime.Now.Year TLHour = DateTime.Now.Hour TLMinute = DateTime.Now.Minute TLDate = TLMonth.ToString + TLDay.ToString + TLYear.ToString TLTime = TLHour.ToString + TLMinute.ToString TLDateTime = TLDate + "_" + TLTime TransLog = TransLog + TLDateTime + ".txt" FileOpen(1, TransLog, OpenMode.Append) Dim dgvRow As DataGridViewRow Dim SentCnt As String SentCnt = dgView1.SelectedRows.Count lblSent.Text = SentCnt + " Records selected and sent" Dim transrecord As String For Each dgvRow In dgView1.SelectedRows 'Get Transaction column from DataGridView of runninglog table in Access DB TransLogger 'The data in this column is only 122 bytes - MQ Client requires 300 bytes so 'We need to pad the transrecord string before sending to the MQ client transrecord = dgvRow.Cells(7).Value transrecord = transrecord.PadRight(300) ' Write transaction to text file for audit purposes ' To stop logging to the text file, comment out the nextline and the fileclose() line below WriteLine(1, transrecord) Next fileclose()
Yields - MTTLogSent382007_119.txt
Should look like - MTTLogSent03082007_1109.txt
Found solution by playing around with code shortly after posting this. Here is my solution.
vb.net Syntax (Toggle Plain Text)
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click ' Write transactions to text file for audit purposes ' Folder c:\MTTLog Upload must exist on 'c' drive ' Create file name including date and time stamp Dim TransLog As String = "c:\MTTap Upload\MTTLogSent" Dim TLDateTime As String Dim TLDay As String Dim TLMonth As Integer Dim TLYear As Integer Dim TLHour As Integer Dim TLMinute As Integer Dim TLDate As String Dim TLTime As String Dim TLSecond As Integer TLDay = DateTime.Now.Day TLMonth = DateTime.Now.Month TLYear = DateTime.Now.Year TLHour = DateTime.Now.Hour TLMinute = DateTime.Now.Minute TLSecond = DateTime.Now.Second Dim MyDate As New DateTime(TLYear, TLMonth, TLDay, TLHour, TLMinute, TLSecond) Dim MyString As String = MyDate.ToString("MMMddyyyy_HHmmss") TLDate = TLMonth.ToString + TLDay.ToString + TLYear.ToString TLTime = TLHour.ToString + TLMinute.ToString TLDateTime = TLDate + "_" + TLTime TransLog = TransLog + MyString + ".txt" FileOpen(1, TransLog, OpenMode.Append) Dim dgvRow As DataGridViewRow Dim SentCnt As String SentCnt = dgView1.SelectedRows.Count lblSent.Text = SentCnt + " Records selected and sent" Dim transrecord As String For Each dgvRow In dgView1.SelectedRows 'Get Transaction column from DataGridView of runninglog table in Access DB TransLogger 'The data in this column is only 122 bytes - MQ Client requires 300 bytes so 'We need to pad the transrecord string before sending to the MQ client transrecord = dgvRow.Cells(7).Value transrecord = transrecord.PadRight(300) ' Write transaction to text file for audit purposes ' To stop logging to the text file, comment out the nextline and the fileclose() line below WriteLine(1, transrecord) Next fileclose()
Last edited by poppo; Mar 8th, 2007 at 12:54 pm. Reason: found solution
•
•
Join Date: Jun 2007
Posts: 3
Reputation:
Solved Threads: 0
First off I want to say sorry for any breach of posting ethics by noobieness I'm trying to do the something close to this but in VB not VB.net. I thought I had hit the target with the code above but it doesn't work. All I need it to do is create the file with the date and time on it. Ex ReportMMMMDDDDYYYYHHMMSS.pdf
and it gives me error
(303)Error with no ErrorHandler with no BreakOnVBAError = False
Any help would be greaty appreciated (yes flame away if you want to also)
Here is the macro -
Sub main()
Dim dDate As Date
Dim boDP As busobj.DataProvider
Dim sLast As String
Dim sFileName As String
Dim sDir As String
Dim dTime As Integer
Dim MyTime As String
''''''Define the path to save the file to
'sDir = "\\ReportDB\CIC\"
sDir = "D:\ET_REPORTS\"
'Application.Interactive = False
ActiveDocument.Refresh
Set boDP = ActiveDocument.DataProviders.Item(1)
sLast = boDP.LastExecutionDate
MyTime = boDP.LastExecutionTime
'The line below captures the last time the report was refreshed.
dDate = CDate(sLast)
dTime = CDate(MyTime)
sFileName = sDir & ActiveDocument.Name & "(" & CStr(Month(dDate)) & "-" & CStr(Day(dDate)) & "-" & CStr(Year(dDate)) & "_" & CStr(Time(dTime)) & ")" & ".pdf"
ActiveDocument.Reports.Item(1).ExportAsPDF (sFileName)
End Sub
and it gives me error
(303)Error with no ErrorHandler with no BreakOnVBAError = False
Any help would be greaty appreciated (yes flame away if you want to also)
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
With some perseverance, I got my problem solved.
Here is what I ended up with. don't know if this will help you or not. I too am a newbie at vb.net.
code
code=vb.net
' Write transactions to text file for audit purposes
' Folder c:\MTTLog Upload\ must exist on 'c' drive
' Create file name including date and time stamp
' Creates file name as MTTDownLogSent_May212007_135038.txt
Dim TransLog As String = "c:\MTTap Upload\MTTDownLogSent_"
Dim TLDateTime As String
Dim TLDay As String
Dim TLMonth As Integer
Dim TLYear As Integer
Dim TLHour As Integer
Dim TLMinute As Integer
Dim TLDate As String
Dim TLTime As String
Dim TLSecond As Integer
TLDay = DateTime.Now.Day
TLMonth = DateTime.Now.Month
TLYear = DateTime.Now.Year
TLHour = DateTime.Now.Hour
TLMinute = DateTime.Now.Minute
TLSecond = DateTime.Now.Second
Dim MyDate As New DateTime(TLYear, TLMonth, TLDay, TLHour, TLMinute, TLSecond)
Dim MyString As String = MyDate.ToString("MMMddyyyy_HHmmss")
TLDate = TLMonth.ToString + TLDay.ToString + TLYear.ToString
TLTime = TLHour.ToString + TLMinute.ToString
TLDateTime = TLDate + "_" + TLTime
TransLog = TransLog + MyString + ".txt"
FileOpen(1, TransLog, OpenMode.Append)
/code
It may not be the best way to do it, but it worked for what I need.
Bill
Here is what I ended up with. don't know if this will help you or not. I too am a newbie at vb.net.
code
code=vb.net
' Write transactions to text file for audit purposes
' Folder c:\MTTLog Upload\ must exist on 'c' drive
' Create file name including date and time stamp
' Creates file name as MTTDownLogSent_May212007_135038.txt
Dim TransLog As String = "c:\MTTap Upload\MTTDownLogSent_"
Dim TLDateTime As String
Dim TLDay As String
Dim TLMonth As Integer
Dim TLYear As Integer
Dim TLHour As Integer
Dim TLMinute As Integer
Dim TLDate As String
Dim TLTime As String
Dim TLSecond As Integer
TLDay = DateTime.Now.Day
TLMonth = DateTime.Now.Month
TLYear = DateTime.Now.Year
TLHour = DateTime.Now.Hour
TLMinute = DateTime.Now.Minute
TLSecond = DateTime.Now.Second
Dim MyDate As New DateTime(TLYear, TLMonth, TLDay, TLHour, TLMinute, TLSecond)
Dim MyString As String = MyDate.ToString("MMMddyyyy_HHmmss")
TLDate = TLMonth.ToString + TLDay.ToString + TLYear.ToString
TLTime = TLHour.ToString + TLMinute.ToString
TLDateTime = TLDate + "_" + TLTime
TransLog = TransLog + MyString + ".txt"
FileOpen(1, TransLog, OpenMode.Append)
/code
It may not be the best way to do it, but it worked for what I need.
Bill
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Solved Threads: 0
Try this;
The above code will result in JuneFriday2007173710.PDF
VB.NET Syntax (Toggle Plain Text)
sFilename = Format(date,"MMMM") & Format(date,"DDDD") & Format(date,"YYYY") & Format(Time,"HH") & Format(Time,"NN") & Format(Time,"SS") & ".PDF"
The above code will result in JuneFriday2007173710.PDF
![]() |
Similar Threads
- how to set file access time (C)
- How to compare the last two modified date and time of a file (C)
- How to Get Last Accessed/Created/Modified File Date and Time (C)
- inputing system("date /t") and system("time /t") into a file (C++)
Other Threads in the VB.NET Forum
- Previous Thread: update,delete,cancel buttons for datagrid
- Next Thread: RaiseEvent Problems
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code combobox component convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output passingparameters peertopeervideostreaming picturebox picturebox1 port print printing problem problemwithinstallation project remove save searchbox searchvb.net select serial server shutdown soap sorting survey table tcp temperature text textbox timer toolbox trim update updown user validation vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf





