[RESOLVED] Need to convert VB6 code to 2005
I am new to VB 2005, and am trying to update code from an older program of mine.
How would I convert this to 2005?
vb Code:
Dim intFileNum As Integer
intFileNum = FreeFile() ' Assign available File Number
strFile = Format(Date, "mm-dd-yyyy") ' Set Base File Format
strFile = App.Path & "\" + strFile + "-Leaders.txt" ' Create Log File name
Open strFile For Output As #intFileNum ' Open File for Output
Write #intFileNum, strSource ' Write source code
Close #intFileNum ' Close File
Re: Need to convert VB6 code to 2005
The only thing that needs to change afaik is the open/write file actions.
For this, have a look/search for 'StreamReader' (opening files) and 'StreamWriter' examples.
Re: Need to convert VB6 code to 2005
Re: Need to convert VB6 code to 2005
There are various ways you could do it but they all involve a StreamWriter at some level. The easiest way would be to use the File.WriteAllText method, which will open the file, write the text and then close the file all in one line of code.
First of all, I should point out that this is wrong:
vb.net Code:
strFile = Format(Date, "mm-dd-yyyy")
I'm not 100% sure about VB6 but in VB.NET that format would write out the minute, not the month. If you want the month you use upper case M.
Secondly, when embedding dates in file names it is vastly preferable to go from largest to smallest, i.e. year first and day last. That way chronological order matches alphabetical order, which allows you to sort files in Windows Explorer and get them in chronological order.
The end result of all this would be:
vb.net Code:
Dim path As String = String.Format("{0}\{1:yyyyMMdd}-Leaders.txt", Application.StartupPath, Date.Now)
IO.File.WriteAllText(path, strSource)
Re: Need to convert VB6 code to 2005
Quote:
Originally Posted by jmcilhinney
First of all, I should point out that this is wrong:
vb.net Code:
strFile = Format(Date, "mm-dd-yyyy")
I'm not 100% sure about VB6 but in VB.NET that format would write out the minute, not the month. If you want the month you use upper case M.
mm worked fime in VB6 for the month.
Quote:
Originally Posted by jmcilhinney
Secondly, when embedding dates in file names it is vastly preferable to go from largest to smallest, i.e. year first and day last. That way chronological order matches alphabetical order, which allows you to sort files in Windows Explorer and get them in chronological order.
The end result of all this would be:
vb.net Code:
Dim path As String = String.Format("{0}\{1:yyyyMMdd}-Leaders.txt", Application.StartupPath, Date.Now)
IO.File.WriteAllText(path, strSource)
Thanks for the code and the suggested storage format. Worked right the first time!