# VB Save text file with variable name

This topic is 4561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i am using VB 6.0 and i want to save a text file using a varible as part of the file name. Here is what i currently have:
appPath = App.Path
If Right(appPath, 1) <> "\" Then appPath = appPath & "\"
' Get a free file number
FileNum4 = FreeFile
' Create mood.txt
Open appPath & "mood.txt" For Append As #FileNum4
' Write the contents to mood.txt
Print #FileNum4, mood; ","; FSOUND_Stream_GetTime(stream1)
' Close the file
Close FileNum4

However this creates a file called mood.txt. What i need is songTitle mood.txt where songTitle is a variable. songTitle is a String which usually looks something like this; C:\Documents and Settings\user\Desktop\song.mp3 So i want the file as C:\Documents and Settings\user\Desktop\song.mp3 mood.txt something like that. But using
Open appPath & songTitle & "mood.txt" For Append As #FileNum4

results in a bad filename error. Is there a way around this? Thanks