Convert from VB 6

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill nguyen

    #1

    Convert from VB 6

    Can someone please convert the following codes into VB.NET?
    Thanks Bill

    -------------

    ' In general Declarations
    Dim tvn As Node

    Private Sub Command1_Click( )
    Me.MousePointer = vbHourglass

    TreeView1.Nodes .Clear

    ' Pathname to create folder/file list from
    p$ = Dir1.Path
    If Right$(p$, 1) <> "\" Then p$ = p$ + "\"

    Set tvn = TreeView1.Nodes .Add(, tvwParent, p$, p$)

    RecurseFiles2 p$

    Me.MousePointer = vbDefault
    End Sub

    Sub RecurseFiles2(B yVal fPath As String)
    Dim File_Name As String
    Dim File_Read As Integer ' Number of Files Read
    Dim strTempPath As String
    Dim i As Integer

    If Right$(fPath, 1) <> "\" Then fPath = fPath & "\"

    ' to do a pattern match do, or something.
    ' folders won`t be included in the list (not my fault)
    ' File_Name = Dir$(fPath+"\*. exe", vbDirectory)

    File_Name = Dir$(fPath, vbDirectory)
    File_Read = 1

    Do While File_Name <> ""
    If File_Name <> "." And File_Name <> ".." Then
    strTempPath = fPath & File_Name

    If GetAttr(strTemp Path) And vbDirectory Then
    Set tvn = TreeView1.Nodes .Add(fPath, tvwChild, strTempPath +
    "\", File_Name)
    RecurseFiles2 strTempPath ' if a folder, then call this
    routine to scan that folder (recursion)

    File_Name = Dir$(fPath, vbDirectory)
    For i = 2 To File_Read
    File_Name = Dir$
    Next
    Else
    Set tvn = TreeView1.Nodes .Add(fPath, tvwChild, strTempPath,
    File_Name)
    End If
    End If

    File_Name = Dir$
    File_Read = File_Read + 1
    Loop
    End Sub


  • Michael C#

    #2
    Re: Convert from VB 6

    You might start by looking at the FileDialog class in .NET. It encapsulates
    just about everything you're trying to do here. If you want to go it this
    way though, start by getting rid of all those God-awful $'s on your string
    variables. "Node" is now a TreeNode. .MousePointer is now .Cursor with its
    own set of enumerations. Not sure where your Dir1.Path is coming from
    here...

    I just found several other items in MSDN Online Help for VS.NET. Why not
    type some of the items that are giving you errors below into the Search?
    Almost all of them return the relevant help screens.

    "Bill nguyen" <billn_nospam_p lease@jaco.com> wrote in message
    news:%23PQ7b%23 2gFHA.2904@tk2m sftngp13.phx.gb l...[color=blue]
    > Can someone please convert the following codes into VB.NET?
    > Thanks Bill
    >
    > -------------
    >
    > ' In general Declarations
    > Dim tvn As Node
    >
    > Private Sub Command1_Click( )
    > Me.MousePointer = vbHourglass
    >
    > TreeView1.Nodes .Clear
    >
    > ' Pathname to create folder/file list from
    > p$ = Dir1.Path
    > If Right$(p$, 1) <> "\" Then p$ = p$ + "\"
    >
    > Set tvn = TreeView1.Nodes .Add(, tvwParent, p$, p$)
    >
    > RecurseFiles2 p$
    >
    > Me.MousePointer = vbDefault
    > End Sub
    >
    > Sub RecurseFiles2(B yVal fPath As String)
    > Dim File_Name As String
    > Dim File_Read As Integer ' Number of Files Read
    > Dim strTempPath As String
    > Dim i As Integer
    >
    > If Right$(fPath, 1) <> "\" Then fPath = fPath & "\"
    >
    > ' to do a pattern match do, or something.
    > ' folders won`t be included in the list (not my fault)
    > ' File_Name = Dir$(fPath+"\*. exe", vbDirectory)
    >
    > File_Name = Dir$(fPath, vbDirectory)
    > File_Read = 1
    >
    > Do While File_Name <> ""
    > If File_Name <> "." And File_Name <> ".." Then
    > strTempPath = fPath & File_Name
    >
    > If GetAttr(strTemp Path) And vbDirectory Then
    > Set tvn = TreeView1.Nodes .Add(fPath, tvwChild, strTempPath +
    > "\", File_Name)
    > RecurseFiles2 strTempPath ' if a folder, then call this
    > routine to scan that folder (recursion)
    >
    > File_Name = Dir$(fPath, vbDirectory)
    > For i = 2 To File_Read
    > File_Name = Dir$
    > Next
    > Else
    > Set tvn = TreeView1.Nodes .Add(fPath, tvwChild, strTempPath,
    > File_Name)
    > End If
    > End If
    >
    > File_Name = Dir$
    > File_Read = File_Read + 1
    > Loop
    > End Sub
    >
    >[/color]


    Comment

    • Ken Tucker [MVP]

      #3
      Re: Convert from VB 6

      Hi,

      Take a look at the vb power packs folder viewer control.
      http://msdn.microsoft.com/library/de...bpowerpack.asp

      Ken
      -------------------
      "Bill nguyen" <billn_nospam_p lease@jaco.com> wrote in message
      news:%23PQ7b%23 2gFHA.2904@tk2m sftngp13.phx.gb l...
      Can someone please convert the following codes into VB.NET?
      Thanks Bill

      -------------

      ' In general Declarations
      Dim tvn As Node

      Private Sub Command1_Click( )
      Me.MousePointer = vbHourglass

      TreeView1.Nodes .Clear

      ' Pathname to create folder/file list from
      p$ = Dir1.Path
      If Right$(p$, 1) <> "\" Then p$ = p$ + "\"

      Set tvn = TreeView1.Nodes .Add(, tvwParent, p$, p$)

      RecurseFiles2 p$

      Me.MousePointer = vbDefault
      End Sub

      Sub RecurseFiles2(B yVal fPath As String)
      Dim File_Name As String
      Dim File_Read As Integer ' Number of Files Read
      Dim strTempPath As String
      Dim i As Integer

      If Right$(fPath, 1) <> "\" Then fPath = fPath & "\"

      ' to do a pattern match do, or something.
      ' folders won`t be included in the list (not my fault)
      ' File_Name = Dir$(fPath+"\*. exe", vbDirectory)

      File_Name = Dir$(fPath, vbDirectory)
      File_Read = 1

      Do While File_Name <> ""
      If File_Name <> "." And File_Name <> ".." Then
      strTempPath = fPath & File_Name

      If GetAttr(strTemp Path) And vbDirectory Then
      Set tvn = TreeView1.Nodes .Add(fPath, tvwChild, strTempPath +
      "\", File_Name)
      RecurseFiles2 strTempPath ' if a folder, then call this
      routine to scan that folder (recursion)

      File_Name = Dir$(fPath, vbDirectory)
      For i = 2 To File_Read
      File_Name = Dir$
      Next
      Else
      Set tvn = TreeView1.Nodes .Add(fPath, tvwChild, strTempPath,
      File_Name)
      End If
      End If

      File_Name = Dir$
      File_Read = File_Read + 1
      Loop
      End Sub



      Comment

      Working...