Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Ok I have a simple VB program (i am a newbie so be gentle with the comments). Basically I have a small interface tha allows the user to browse the directories for a file. They then highlight the file, which appears in text1. In text2 they have an alternative name to the file .Then click the command button which in turn changes the filename from what was in text1 to text2. However I am having a bit of trouble. Everything works fine until I click the change file name, it comes up with the message box to confirm the change and when I do it has a run time error 53 FILE NOT FOUND. All I can think of is that using Name Text1.text As Text2.text is just not working with variable names. The code is below for the command button. If anyone is able to help would be really appreciative.
Private Sub Command1_Click()
If MsgBox("Do you want want to rename " & Text1.Text, vbOKCancel, "Rename?") = vbOK Then
Name Text1.Text As Text2.Text
End IfText1.Text = ""
File1.Refresh
End Sub

I'll assume that you are using a combination of a directory list and a file list control for the user to locate the file. With that assumption, you can use the following code in place of the line starting "Name " :
Name File1.Path & "\" & Text1.Text As File1.Path & "\" & Text2.Text
File1 is the file listbox where the user has selected the file. The problem with the code as you have it is that VB assumes a directory if you omit it when trying to access a file (I think either the root directory or App.Path).
Also, the above code won't work properly if the file is in the root directory (such as C:\). If you want it to, you will need to use this instead:If Right(File1.Path, 1) = "\" Then
Name File1.Path & Text1.Text As File1.Path & Text2.Text
Else
Name File1.Path & "\" & Text1.Text As File1.Path & "\" & Text2.Text
End IfIf you have further questions don't hesitate to ask
-Burbble

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |