Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #1811 > unrolled thread

Re: Renaming a Directory in VB6????

Started by"jason@smkzone.com" <jbodine1@yahoo.com>
First post2011-02-03 04:20 -0800
Last post2011-02-03 04:47 -0800
Articles 11 — 6 participants

Back to article view | Back to comp.lang.basic.visual.misc

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Renaming a Directory in VB6???? "jason@smkzone.com" <jbodine1@yahoo.com> - 2011-02-03 04:20 -0800
    Re: Renaming a Directory in VB6???? "jason@smkzone.com" <jbodine1@yahoo.com> - 2011-02-03 14:27 -0800
      Re: Renaming a Directory in VB6???? Steve Rindsberg <steve@rdpslides.com> - 2011-02-11 16:41 -0500
      Re: Renaming a Directory in VB6???? GS <gs@somewhere.net> - 2011-02-04 13:41 -0500
        Re: Renaming a Directory in VB6???? "jason@smkzone.com" <jbodine1@yahoo.com> - 2011-02-05 04:57 -0800
      Re: Renaming a Directory in VB6???? "jason@smkzone.com" <jbodine1@yahoo.com> - 2011-02-04 10:31 -0800
      Re: Renaming a Directory in VB6???? "Bob Butler" <bob_butler@cox.invalid> - 2011-02-03 15:23 -0800
        Re: Renaming a Directory in VB6???? "David Youngblood" <dwy@flash.net> - 2011-02-04 05:44 -0600
        Re: Renaming a Directory in VB6???? "jason@smkzone.com" <jbodine1@yahoo.com> - 2011-02-03 22:22 -0800
      Re: Renaming a Directory in VB6???? Jason Keats <jkeats@melbpcDeleteThis.org.au> - 2011-02-04 23:33 +1100
    Re: Renaming a Directory in VB6???? "jason@smkzone.com" <jbodine1@yahoo.com> - 2011-02-03 04:47 -0800

#1811 — Re: Renaming a Directory in VB6????

From"jason@smkzone.com" <jbodine1@yahoo.com>
Date2011-02-03 04:20 -0800
SubjectRe: Renaming a Directory in VB6????
Message-ID<a9ca46ef-d18c-4e08-ba62-1696a65f906c@m27g2000prj.googlegroups.com>
On Feb 3, 5:34 am, "David Youngblood" <d...@flash.net> wrote:
> "ja...@smkzone.com" <jbodi...@yahoo.com> wrote in message
>
> news:4e20d437-1a2c-4812-a803-55d3121f5600@o7g2000prn.googlegroups.com...
>
> > Garry:
>
> > I just tried adding the trailing backslash.  I'm still getting that
> > runtime error 53.
>
> What are you getting from the datetime picker control. These characters are
> invalid in file/folder names: \ / : * ? < > |. I would suspect that the text
> you are getting from the control has one or more of those characters.
>
> David

You're right.  It has the / in it, like 2/3/2011.  Can I fix that
without modifying the display in the datetime picker controls?

[toc] | [next] | [standalone]


#1812

From"jason@smkzone.com" <jbodine1@yahoo.com>
Date2011-02-03 14:27 -0800
Message-ID<6d23b61f-1d5a-4ced-81dc-426f6852f2bf@u24g2000prn.googlegroups.com>
In reply to#1811
I DO have another "minor" problem though.  The following code is
SUPPOSED to create a separate text file for each entry in my
database.  Instead, it creates ONE file with the info for ALL the
entries! How do I fix this?:

Public Sub AddFiles()
Dim cnn As ADODB.Connection
Dim cmm As ADODB.Command
Dim rss As ADODB.Recordset
Dim fPath As String, folder As String, folder2 As String, fName As
String, fileName As String
Set cnn = New ADODB.Connection
With cnn
   .Provider = "Microsoft.Jet.OLEDB.4.0"
   .CursorLocation = adUseClient
   .Mode = adModeReadWrite
   .Open DBPath
End With
Set cmm = New ADODB.Command
With cmm
   .ActiveConnection = cnn
   .CommandText = "SELECT * FROM Employees;"
   .CommandType = adCmdText
End With
Set rss = New ADODB.Recordset
With rss
   .CursorType = adOpenStatic
   .CursorLocation = adUseClient
   .LockType = adLockOptimistic
   .Open cmm
End With
fPath = App.Path
folder = "\Pay Period\"
folder2 = "Current\"
fileName = rss.Fields(0).Value & ".txt"
fName = Dir(fPath & folder & folder2, vbDirectory)
If fName = "" Then
   Exit Sub
Else
   Dim fName2 As String
   Dim FullPath As String
   FullPath = fPath & folder & folder2 & fileName
   fName2 = Dir(fPath & folder & folder2 & fileName)
   Do Until rss.EOF
      If fName2 = "" Then
         Dim x As Integer
         x = FreeFile
         Open FullPath For Append As #x
         Dim sName As String
         Dim sSSN As String
         Dim sENum As String
         sName = rss.Fields(0).Value
         sSSN = "Social Security Number: " & rss.Fields(1).Value
         sENum = "Employee Number: " & rss.Fields(2).Value
         Write #x, sName & vbCrLf & sSSN & vbCrLf & sENum & vbCrLf
         Close #x
         rss.MoveNext
      End If
   Loop
End If
rss.Close
Set rss = Nothing
Set cmm = Nothing
cnn.Close
Set cnn = Nothing
Exit Sub
End Sub


Thanks
Jason

[toc] | [prev] | [next] | [standalone]


#1817

FromSteve Rindsberg <steve@rdpslides.com>
Date2011-02-11 16:41 -0500
Message-ID<VA.000001a4.5ce0e4d3@rdpslides.com>
In reply to#1812
In article <83438015-00c9-48e8-901c-
0e4f39d665ca@y35g2000prc.googlegroups.com>, Jason@smkzone.com wrote:
> Got that working!
> 
> Now, one last (for now, anyway, lol) annoying issue to deal with.
> 
> I've created the text files for each individual employee. Now, let's
> say it's a female employee and she gets married, or for some reason
> she's had to get a new SSN.  I don't want to overwrite the existing
> file with Output, as the file also contains the clock-in and clock-out
> timestamps for the employee, and I don't want to use Append to write
> to the end of the file.  I need to replace the existing info on a
> specific line with the new info.  How do I do that?  I've looked all
> over the internet and can't seem to find a suitable answer!

Wouldn't it make more sense to generate your own unique ID for each 
employee instead of relying on information that might change?

[toc] | [prev] | [next] | [standalone]


#1822

FromGS <gs@somewhere.net>
Date2011-02-04 13:41 -0500
Message-ID<iihh82$uaf$1@news.eternal-september.org>
In reply to#1812
jason@smkzone.com brought next idea :
> Got that working!
>
> Now, one last (for now, anyway, lol) annoying issue to deal with.
>
> I've created the text files for each individual employee. Now, let's
> say it's a female employee and she gets married, or for some reason
> she's had to get a new SSN.  I don't want to overwrite the existing
> file with Output, as the file also contains the clock-in and clock-out
> timestamps for the employee, and I don't want to use Append to write
> to the end of the file.  I need to replace the existing info on a
> specific line with the new info.  How do I do that?  I've looked all
> over the internet and can't seem to find a suitable answer!
>
> Thanks again, everyone, for being so patient, kind, and helpful!
> Jason

If you're talking about replacing every instance of this info with the 
new info (in a text file), load the entire file into a string var and 
use the Replace() function.

-- 
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc

[toc] | [prev] | [next] | [standalone]


#1870

From"jason@smkzone.com" <jbodine1@yahoo.com>
Date2011-02-05 04:57 -0800
Message-ID<fb12c0df-4e20-491e-bfa6-240d9a360221@q2g2000pre.googlegroups.com>
In reply to#1822
 I don't know how to do that either, lol.

> If you're talking about replacing every instance of this info with the
> new info (in a text file), load the entire file into a string var and
> use the Replace() function.
>
> --
> Garry
>
> Free usenet access athttp://www.eternal-september.org
> ClassicVB Users Regroup! comp.lang.basic.visual.misc

[toc] | [prev] | [next] | [standalone]


#1829

From"jason@smkzone.com" <jbodine1@yahoo.com>
Date2011-02-04 10:31 -0800
Message-ID<83438015-00c9-48e8-901c-0e4f39d665ca@y35g2000prc.googlegroups.com>
In reply to#1812
Got that working!

Now, one last (for now, anyway, lol) annoying issue to deal with.

I've created the text files for each individual employee. Now, let's
say it's a female employee and she gets married, or for some reason
she's had to get a new SSN.  I don't want to overwrite the existing
file with Output, as the file also contains the clock-in and clock-out
timestamps for the employee, and I don't want to use Append to write
to the end of the file.  I need to replace the existing info on a
specific line with the new info.  How do I do that?  I've looked all
over the internet and can't seem to find a suitable answer!

Thanks again, everyone, for being so patient, kind, and helpful!
Jason

[toc] | [prev] | [next] | [standalone]


#1860

From"Bob Butler" <bob_butler@cox.invalid>
Date2011-02-03 15:23 -0800
Message-ID<iifdfi$bu7$1@news.eternal-september.org>
In reply to#1812
"jason@smkzone.com" <jbodine1@yahoo.com> wrote in message 
news:6d23b61f-1d5a-4ced-81dc-426f6852f2bf@u24g2000prn.googlegroups.com...
>I DO have another "minor" problem though.  The following code is
> SUPPOSED to create a separate text file for each entry in my
> database.  Instead, it creates ONE file with the info for ALL the
> entries! How do I fix this?:
>
> Public Sub AddFiles()
> Dim cnn As ADODB.Connection
> Dim cmm As ADODB.Command
> Dim rss As ADODB.Recordset
> Dim fPath As String, folder As String, folder2 As String, fName As
> String, fileName As String
> Set cnn = New ADODB.Connection
> With cnn
>   .Provider = "Microsoft.Jet.OLEDB.4.0"
>   .CursorLocation = adUseClient
>   .Mode = adModeReadWrite
>   .Open DBPath
> End With
> Set cmm = New ADODB.Command
> With cmm
>   .ActiveConnection = cnn
>   .CommandText = "SELECT * FROM Employees;"
>   .CommandType = adCmdText
> End With
> Set rss = New ADODB.Recordset
> With rss
>   .CursorType = adOpenStatic
>   .CursorLocation = adUseClient
>   .LockType = adLockOptimistic
>   .Open cmm
> End With
> fPath = App.Path
> folder = "\Pay Period\"
> folder2 = "Current\"
> fileName = rss.Fields(0).Value & ".txt"
> If fName = "" Then
>   Exit Sub
> Else
>   Dim fName2 As String
>   Dim FullPath As String
>   Do Until rss.EOF

fName = Dir(fPath & folder & folder2, vbDirectory)
FullPath = fPath & folder & folder2 & fileName
fName2 = Dir(fPath & folder & folder2 & fileName)

>      If fName2 = "" Then
>         Dim x As Integer
>         x = FreeFile
>         Open FullPath For Append As #x
>         Dim sName As String
>         Dim sSSN As String
>         Dim sENum As String
>         sName = rss.Fields(0).Value
>         sSSN = "Social Security Number: " & rss.Fields(1).Value
>         sENum = "Employee Number: " & rss.Fields(2).Value
>         Write #x, sName & vbCrLf & sSSN & vbCrLf & sENum & vbCrLf
>         Close #x
>         rss.MoveNext
>      End If
>   Loop
> End If
> rss.Close
> Set rss = Nothing
> Set cmm = Nothing
> cnn.Close
> Set cnn = Nothing
> Exit Sub
> End Sub

Didn't actually look at it all in detail but at the very least you need to 
build the filename inside the loop

[toc] | [prev] | [next] | [standalone]


#1866

From"David Youngblood" <dwy@flash.net>
Date2011-02-04 05:44 -0600
Message-ID<iigou1$80p$1@news.eternal-september.org>
In reply to#1860
"jason@smkzone.com" <jbodine1@yahoo.com> wrote...
> I've rearranged the code in every configuration I can think of, and
> all I can get is one of two results:
>
> 1. Either one file named Admin.txt with the information for ALL the
> recordset entries, or
> 2. One file named Admin.txt with the info for Admin repeated over and
> over again in an infinite loop.
>
> Since this is a time clock program which will append the clock-in and
> clock-out times of each employee in the database to the text files,
> what I need is to loop through all the records in the recordset and
> create a separate file for each employee.
>
>> Didn't actually look at it all in detail but at the very least you need 
>> to
>> build the filename inside the loop

As Bob said, fileName must be created from within your Do Loop.

Rather than,
fileName = rss.Fields(0).Value & ".txt"
   Do Until rss.EOF
      .... save file fileName
         rss.MoveNext
      End If
   Loop

Use something like,
   Do Until rss.EOF
      fileName = rss.Fields(0).Value & ".txt"
      Debug.print fileName
      .... save file fileName
         rss.MoveNext
      End If
   Loop

David


[toc] | [prev] | [next] | [standalone]


#1877

From"jason@smkzone.com" <jbodine1@yahoo.com>
Date2011-02-03 22:22 -0800
Message-ID<dc7709c7-caa9-45ba-b197-bb1c32f33a70@d17g2000vbn.googlegroups.com>
In reply to#1860
I've rearranged the code in every configuration I can think of, and
all I can get is one of two results:

1. Either one file named Admin.txt with the information for ALL the
recordset entries, or
2. One file named Admin.txt with the info for Admin repeated over and
over again in an infinite loop.

Since this is a time clock program which will append the clock-in and
clock-out times of each employee in the database to the text files,
what I need is to loop through all the records in the recordset and
create a separate file for each employee.

> Didn't actually look at it all in detail but at the very least you need to
> build the filename inside the loop

[toc] | [prev] | [next] | [standalone]


#1867

FromJason Keats <jkeats@melbpcDeleteThis.org.au>
Date2011-02-04 23:33 +1100
Message-ID<TmS2p.9524$MF5.8605@viwinnwfe02.internal.bigpond.com>
In reply to#1812
jason@smkzone.com wrote:
> I DO have another "minor" problem though.  The following code is
> SUPPOSED to create a separate text file for each entry in my
> database.  Instead, it creates ONE file with the info for ALL the
> entries! How do I fix this?:
>
> Public Sub AddFiles()
> Dim cnn As ADODB.Connection
> Dim cmm As ADODB.Command
> Dim rss As ADODB.Recordset
> Dim fPath As String, folder As String, folder2 As String, fName As
> String, fileName As String
> Set cnn = New ADODB.Connection
> With cnn
>     .Provider = "Microsoft.Jet.OLEDB.4.0"
>     .CursorLocation = adUseClient
>     .Mode = adModeReadWrite
>     .Open DBPath
> End With
> Set cmm = New ADODB.Command
> With cmm
>     .ActiveConnection = cnn
>     .CommandText = "SELECT * FROM Employees;"
>     .CommandType = adCmdText
> End With
> Set rss = New ADODB.Recordset
> With rss
>     .CursorType = adOpenStatic
>     .CursorLocation = adUseClient
>     .LockType = adLockOptimistic
>     .Open cmm
> End With
> fPath = App.Path
> folder = "\Pay Period\"
> folder2 = "Current\"
> fileName = rss.Fields(0).Value&  ".txt"
> fName = Dir(fPath&  folder&  folder2, vbDirectory)
> If fName = "" Then
>     Exit Sub
> Else
>     Dim fName2 As String
>     Dim FullPath As String
>     FullPath = fPath&  folder&  folder2&  fileName
>     fName2 = Dir(fPath&  folder&  folder2&  fileName)
>     Do Until rss.EOF
>        If fName2 = "" Then
>           Dim x As Integer
>           x = FreeFile
>           Open FullPath For Append As #x
>           Dim sName As String
>           Dim sSSN As String
>           Dim sENum As String
>           sName = rss.Fields(0).Value
>           sSSN = "Social Security Number: "&  rss.Fields(1).Value
>           sENum = "Employee Number: "&  rss.Fields(2).Value
>           Write #x, sName&  vbCrLf&  sSSN&  vbCrLf&  sENum&  vbCrLf
>           Close #x
>           rss.MoveNext
>        End If
>     Loop
> End If
> rss.Close
> Set rss = Nothing
> Set cmm = Nothing
> cnn.Close
> Set cnn = Nothing
> Exit Sub
> End Sub
>

The minimum changes you need to make are...

Public Sub AddFiles()
     Dim cnn As ADODB.Connection
     Dim cmm As ADODB.Command
     Dim rss As ADODB.Recordset
     Dim fPath As String, folder As String, folder2 As String, fName As 
String, fileName As String
     Set cnn = New ADODB.Connection
     With cnn
         .Provider = "Microsoft.Jet.OLEDB.4.0"
         .CursorLocation = adUseClient
         .Mode = adModeReadWrite
         .Open DBPath
     End With

     Set cmm = New ADODB.Command
     With cmm
         .ActiveConnection = cnn
         .CommandText = "SELECT * FROM Employees;"
         .CommandType = adCmdText
     End With
     Set rss = New ADODB.Recordset
     With rss
         .CursorType = adOpenStatic
         .CursorLocation = adUseClient
         .LockType = adLockOptimistic
         .Open cmm
     End With
     fPath = App.Path
     folder = "\Pay Period\"
     folder2 = "Current\"
     'fileName = rss.Fields(0).Value & ".txt"
     fName = Dir(fPath & folder & folder2, vbDirectory)
     If fName = "" Then
         'Exit Sub       'prevents closing recordset & connection
     Else
         Dim fName2 As String
         Dim FullPath As String
         'FullPath = fPath & folder & folder2 & fileName
         'fName2 = Dir(fPath & folder & folder2 & fileName)
         Do Until rss.EOF
             fileName = rss.Fields(0).Value & ".txt"             'moved
             FullPath = fPath & folder & folder2 & fileName      'moved
             fName2 = Dir(fPath & folder & folder2 & fileName)   'moved
             If fName2 = "" Then
                 Dim x As Integer
                 x = FreeFile
                 Open FullPath For Append As #x
                 Dim sName As String
                 Dim sSSN As String
                 Dim sENum As String
                 sName = rss.Fields(0).Value
                 sSSN = "Social Security Number: " & rss.Fields(1).Value
                 sENum = "Employee Number: " & rss.Fields(2).Value
                 Write #x, sName & vbCrLf & sSSN & vbCrLf & sENum & vbCrLf
                 Close #x
                 rss.MoveNext
             End If
         Loop
     End If
     rss.Close
     Set rss = Nothing
     Set cmm = Nothing
     cnn.Close
     Set cnn = Nothing
     Exit Sub
End Sub


However, I'd rewrite the above to make it readable.

Oops, what was I thinking...?

Public Sub CreateEmployeeFiles()

     Dim sAppPath As String
     Dim sFolder1 As String
     Dim sFolder2 As String
     Dim sFolder As String

     sAppPath = App.Path
     sFolder1 = "\Pay Period\"
     sFolder2 = "Current\"

     sFolder = sAppPath & sFolder1 & sFolder2

     If Dir(sFolder, vbDirectory) = "" Then
         Debug.Print "Create folder: " & sFolder
         MsgBox sFolder, vbExclamation, "Missing folder..."
         Exit Sub
     End If

     Dim sName As String
     Dim sSSN As String
     Dim sENum As String

     Dim sFullPath As String
     Dim sFilename As String

     Dim cnn As ADODB.Connection
     Dim cmd As ADODB.Command
     Dim rst As ADODB.Recordset

     Set cnn = New ADODB.Connection
     cnn.Open gsConnection

     Set cmd = New ADODB.Command
     With cmd
         .ActiveConnection = cnn
         .CommandText = "SELECT * FROM Employees;"
         .CommandType = adCmdText
     End With

     Set rst = New ADODB.Recordset
     With rst
         .CursorType = adOpenStatic
         .CursorLocation = adUseClient
         .LockType = adLockOptimistic
         .Open cmd

         If .BOF And .EOF Then
             Debug.Print "No records in database"
             Debug.Assert False
         Else
             Do Until .EOF
                 sName = .Fields("Employee_Name").Value & ""
                 sSSN = .Fields("Social_Security_Number").Value & ""
                 sENum = .Fields("Employee_Number").Value & ""

                 sFilename = sName & " " & sENum & ".txt"

                 sFullPath = sFolder & sFilename

                 If Dir(sFullPath) = "" Then     'if file doesn't exist
                     sSSN = "Social Security Number: " & sSSN
                     sENum = "Employee Number: " & sENum

                     Call AppendToFile(sFullPath, sName & vbCrLf & sSSN 
& vbCrLf & sENum & vbCrLf)
                 End If

                 .MoveNext
             Loop
         End If

         .Close
     End With

     Set rst = Nothing

     Set cmd = Nothing

     cnn.Close
     Set cnn = Nothing

End Sub

Public Sub AppendToFile(ByVal sFilename As String, ByVal sText As String)
     Dim i As Integer

     i = FreeFile
     Open sFilename For Append As #i
     'Write #i, sText
     Print #i, sText
     Close #i
End Sub


I've used employee_name & " " & employee_number for the filename - to 
cope with those who have the same name.

You may also find Print preferable to Write.


However, in reality, I'm more likely to use something like...

Public Sub CreateEmployeeFiles()

     Dim sAppPath As String
     Dim sFolder1 As String
     Dim sFolder2 As String
     Dim sFolder As String

     sAppPath = App.Path
     sFolder1 = "\Pay Period\"
     sFolder2 = "Current\"

     sFolder = sAppPath & sFolder1 & sFolder2

     If Dir(sFolder, vbDirectory) = "" Then
         Debug.Print "Create folder: " & sFolder
         MsgBox sFolder, vbExclamation, "Missing folder..."
         Exit Sub
     End If

     Dim sName As String
     Dim sSSN As String
     Dim sENum As String

     Dim sFullPath As String
     Dim sFilename As String

     Dim sSQL As String
     Dim rst As ADODB.Recordset

     sSQL = "SELECT * FROM Employees;"

     Set rst = GetAdoRecordset(gsConnection, sSQL)
     With rst
         If .BOF And .EOF Then
             Debug.Print "No records in database"
             Debug.Assert False
         Else
             Do Until .EOF
                 sName = .Fields("Employee_Name").Value & "" 'append 
empty string in case of null
                 sSSN = .Fields("Social_Security_Number").Value & ""
                 sENum = .Fields("Employee_Number").Value & ""

                 sFilename = sName & " " & sENum & ".txt"

                 sFullPath = sFolder & sFilename

                 If Dir(sFullPath) = "" Then     'if file doesn't exist
                     sSSN = "Social Security Number: " & sSSN
                     sENum = "Employee Number: " & sENum

                     Call AppendToFile(sFullPath, sName & vbCrLf & sSSN 
& vbCrLf & sENum & vbCrLf)
                 End If

                 .MoveNext
             Loop
         End If

         .Close
     End With

     Set rst = Nothing

End Sub


That's a bit simpler, don't you think?

Annoyingly, I've left the writing of the GetAdoRecordset function as an 
exercise for the reader. :-)

HTH

[toc] | [prev] | [next] | [standalone]


#1880

From"jason@smkzone.com" <jbodine1@yahoo.com>
Date2011-02-03 04:47 -0800
Message-ID<1d45dee2-b566-46d2-a073-898d2aa4f426@o14g2000prb.googlegroups.com>
In reply to#1811
Ok, answered my own question with that, lol.  Just used the Format()
function.  Works like a charm!



On Feb 3, 6:20 am, "ja...@smkzone.com" <jbodi...@yahoo.com> wrote:
> On Feb 3, 5:34 am, "David Youngblood" <d...@flash.net> wrote:
>
> > "ja...@smkzone.com" <jbodi...@yahoo.com> wrote in message
>
> >news:4e20d437-1a2c-4812-a803-55d3121f5600@o7g2000prn.googlegroups.com...
>
> > > Garry:
>
> > > I just tried adding the trailing backslash.  I'm still getting that
> > > runtime error 53.
>
> > What are you getting from the datetime picker control. These characters are
> > invalid in file/folder names: \ / : * ? < > |. I would suspect that the text
> > you are getting from the control has one or more of those characters.
>
> > David
>
> You're right.  It has the / in it, like 2/3/2011.  Can I fix that
> without modifying the display in the datetime picker controls?

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.basic.visual.misc


csiph-web