|
-
Nov 7th, 2000, 05:05 PM
#1
Thread Starter
Hyperactive Member
Solving my previous question (and I'm very thankful for that), came up in my head a renaming feature!
I have he same FileListBox named fleNotes and a commandbutton cmdRename.
How can I do the following?:
1. The user clicks on cmdRename
2. The app pops up an InputBox
3. The user types in the new name (let's put in a variable)
4. The fleNotes.ListIndex file is renamed to the new name.
5. Refresh fleNotes
I know how to do 1,2,3,5. No. 4 is my problem!
-
Nov 7th, 2000, 05:18 PM
#2
Add this code to your button
Code:
Private Sub cmdRename_Click()
retval = InputBox("Enter a new name")
If retval <> "" Then Name fleNotes As retval
fleNotes.Refresh
End Sub
-
Nov 7th, 2000, 05:28 PM
#3
Thread Starter
Hyperactive Member
'File Not Found', Megatron...
Any suggestions?
-
Nov 7th, 2000, 06:33 PM
#4
Frenzied Member
Megatron 's code works for me. I know this seems obvious, but are you sure you have an item selected in the list box before you try to rename it???
P.S. What is the code in your footer supposed to mean? And it looks like it wouldn't run anyway...you should say "Next Num" instead of "Next i"
[Edited by seaweed on 11-07-2000 at 06:44 PM]
-
Nov 8th, 2000, 07:17 AM
#5
Thread Starter
Hyperactive Member
Yes I've selected a file and used the code but it shows me that damn error...
-
Nov 8th, 2000, 01:08 PM
#6
Frenzied Member
Another seemingly obvious thing (but I have to mention it since these things are usually the ones that kill us) is that if you are using a DriveListBox and/or a DirListBox (allowing the user to select other folders or drives than the one your application resides in) then you will have to pass this information along with the file name to the Name function.
Example:
Code:
Option Explicit
Private Sub Command1_Click()
Dim NewName As String
NewName = InputBox("Enter a new name")
If NewName <> "" Then Name Dir1 & "\" & File1 As Dir1 & "\" & NewName
File1.Refresh
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
-
Nov 8th, 2000, 01:35 PM
#7
Frenzied Member
Yeah, it's important to pass the Path to the file in both parameters.
Code:
File1 = "C:\MyFolder\Myfile"
File2 = "C:\MyFolder\Myrenamedfile"
Name File1 As File2
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 8th, 2000, 01:40 PM
#8
Frenzied Member
You can also use the Name function to move a file
If you specify a different path in the NewName string, you will end up moving the file to the new folder, along with a new name.
Code:
File1 = "C:\MyFolder\Myfile"
File2 = "C:\MyOtherFolder\MyRenamedFile"
Name File1 As File2
This will move MyFile from MyFolder to MyOtherFolder and rename it to MyRenamedFile.
Pretty cool, huh?
-
Nov 9th, 2000, 02:37 PM
#9
Thread Starter
Hyperactive Member
Originally posted by seaweed
Another seemingly obvious thing (but I have to mention it since these things are usually the ones that kill us) is that if you are using a DriveListBox and/or a DirListBox (allowing the user to select other folders or drives than the one your application resides in) then you will have to pass this information along with the file name to the Name function.
Example:
Code:
Option Explicit
Private Sub Command1_Click()
Dim NewName As String
NewName = InputBox("Enter a new name")
If NewName <> "" Then Name Dir1 & "\" & File1 As Dir1 & "\" & NewName
File1.Refresh
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Hey thanks y'all! This code worked fine!!!
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
|