|
-
Jan 12th, 2008, 03:23 AM
#1
Thread Starter
Member
[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
-
Jan 12th, 2008, 05:31 AM
#2
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.
-
Jan 12th, 2008, 05:51 AM
#3
Frenzied Member
Re: Need to convert VB6 code to 2005
Try

It may do it for you
-
Jan 12th, 2008, 06:49 AM
#4
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)
-
Jan 12th, 2008, 12:41 PM
#5
Thread Starter
Member
Re: Need to convert VB6 code to 2005
 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.
 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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|