Results 1 to 5 of 5

Thread: [RESOLVED] Need to convert VB6 code to 2005

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    39

    Resolved [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:
    1. Dim intFileNum      As Integer
    2.  
    3.      intFileNum = FreeFile()                         ' Assign available File Number
    4.  
    5.      strFile = Format(Date, "mm-dd-yyyy")            ' Set Base File Format
    6.  
    7.      strFile = App.Path & "\" + strFile + "-Leaders.txt"   ' Create Log File name
    8.  
    9.  
    10.      Open strFile For Output As #intFileNum          ' Open File for Output
    11.           Write #intFileNum, strSource                ' Write source code
    12.      Close #intFileNum                               ' Close File

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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.

  3. #3
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Need to convert VB6 code to 2005

    Try



    It may do it for you

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. 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:
    1. Dim path As String = String.Format("{0}\{1:yyyyMMdd}-Leaders.txt", Application.StartupPath, Date.Now)
    2.  
    3. IO.File.WriteAllText(path, strSource)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    39

    Thumbs up 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:
    1. 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:
    1. Dim path As String = String.Format("{0}\{1:yyyyMMdd}-Leaders.txt", Application.StartupPath, Date.Now)
    2.  
    3. 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
  •  



Click Here to Expand Forum to Full Width