tags:

views:

51

answers:

2

Using VB6

I want to delete the last 5 words of the filename, then i want to give so other filename.\

Code.

Name FileName As NewFileName

The above code is working for rename, but i don't want to rename, i want to delete the last 5 letter of the filename.

Expected Output

Filename

sufeshcdk.txt - I want to take (sufeshcd) only
Modifyulla.txt - I want to take (Modifyul) only

How to do this?

Need VB6 Code Help.

A: 

Untested, but this is the basic idea...

FileNameLength = Len(FileName)
NewFileName = Mid$(FileName, 1, FileNameLength - 5)
Name FileName As NewFileName

edit: fixed the syntax per below comments.

Jakobud
Showing Error as "invalid procedure call or argument". I gave the Filenamelength = myfilename
Gopal
NewFileName = Mid$(FileName, 1, FileNameLength - 5)
Anand
At what line does it give an error? Also, don't forget `Len()`.
Pavel Minaev
I've correctly changed the code , just one comment above :-) VB6 Mid function expects 1 as the start position not O
Anand
+1  A: 

Here you go.

private function RemoveLast5(FileName as string) as String
    if len(FileName) > 5 then 
        RemoveLast5 = left$(FileName, Len(FileName) - 5)
    else
        RemoveLast5 = FileName
    end
end function


dim FileName as string
FileName = "Modifyulla.txt"

dim NewFileName as string 
NewFileName = RemoveLast5(FileName)

Name FileName As NewFileName
AngryHacker