Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strange number conversion

Status
Not open for further replies.

impulse24

IS-IT--Management
Jul 13, 2001
167
US
Hi,

I have a customer who is providing me files that are name from 1-999. They are asking that the files be renamed. Files are sent to me daily, so I am looking to write a program to do the renaming.

The files would be renamed 1-99, but when it gets to 100 they want to name the file A0, and if its 101 it would be A1, and when it reaches 110, it would be B0. Basically when its a 3 digit number they want to use a 2 digit value. Alpha then numeric, so the total number of files I receive would not exceed 350. I know I could probably use a case statement, but don't want to have 26 separate cases. Is there a more efficient way to do this. Thanks
 
If you are basing the new name on the old name and the old name is something like "999.txt", then you obviously have a problem. If you are just basing it on an internal counter and that counter can never exceed 359 then you could try
[blue][tt]
Const Alpha As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

FileCounter = 0
Do
' ... Get the Next File Name ...
FileCounter = FileCounter + 1
If FileCounter < 100 Then
NewName = Format ( FileCounter, "00" )
Else
Index = Val ( Left ( Format ( FileCounter, "000" ), 2 ) )
AlphaChar = Mid$ ( Alpha, Index, 1 )
NewName = AlphaChar & Right ( Format (FileCounter, "000" ), 1 )
Endif

Name OldName, NewName

Loop
[/tt][/blue]
 
Sorry ... Type[blue][tt]
Const Alpha As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

FileCounter = 0
Do
' ... Get the Next File Name ...
FileCounter = FileCounter + 1
If FileCounter < 100 Then
NewName = Format ( FileCounter, "00" )
Else
Index = Val ( Left ( Format ( FileCounter - 100, "000" ), 2 ) )
AlphaChar = Mid$ ( Alpha, Index, 1 )
NewName = AlphaChar & Right ( Format (FileCounter - 100, "000" ), 1 )
Endif

Name OldName, NewName

Loop
[/tt][/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top