Advertisement Jump to content
Sign in to follow this  

VB Save text file with variable name

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

If you intended to correct an error in the post then please contact us.

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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!