Jump to content
Sign in to follow this  

Issue writing and loading file

Recommended Posts

This should be very easy but I can't figure out what is going on. Maybe I've been looking at the code for too long but I've tried everything I can think of. I am creating and saving "projects" in txt format.

This is the function to save the project. I used to have the function overwrite the file but I have now tried to completely delete the file before writing but still no success. The file saving works great. Opening the file after saving will not work.

Func SaveProject()
$tProjectContents = ""
$tProjectPath = FileSaveDialog("Save Project As...", @ScriptDir & "\Projects", "Text files (*.txt)", -1, GUICtrlRead($hProjectList))
If @error Or $tProjectPath = "" Then
  MsgBox(0, "", "Invalid project path")
  Return ""
$tProjectContents &= "[ACCNAME]" & GUICtrlRead($hAccInput) & "[/ACCNAME]" & @CRLF
$tProjectContents &= "[ACCPASS]" & GUICtrlRead($hAccPassInput) & "[/ACCPASS]" & @CRLF
   If FileExists($tProjectPath) Then
 MsgBox(0, "", "Deleted " & $tProjectPath)
   $hOutFile = FileOpen($tProjectPath, 10) ;2=overwrite previous contents + 8=create path
   FileWrite($hOutFile, $tProjectContents)
   If @error Then
 MsgBox(0, "", "Error saving file?")
 Zout("Saved new project: " & $tProjectPath)
 MsgBox(0, "", "Saved " & $tProjectPath)
 $splitFileName = StringSplit($tProjectPath, '\')
 $tFileName = $splitFileName[$splitFileName[0]]
 ;check if filename isnt already there
 If _GUICtrlListBox_FindString($hProjectList, $tFileName, True) = -1 Then
GUICtrlSetData($hProjectList, $tFileName & "|")


This is the function I use to read the files. FileExists returns false for files that are clearly there! $fContents is empty! 

;get project option
Func GetOption($tFile, $OPT)
   If FileExists($tFile) Then
 MsgBox(0, $tFile, "file exists!")
 MsgBox(0, $tFile, "file " & $tFile & " doesn't exist :\")
$hFile = FileOpen($tFile, 0)
$fContents = FileRead($hFile)
MsgBox(0, "debug", "fContents: " & @crlf & $fContents)
$tOpt = _StringBetween($fContents, '[' & $OPT & ']', '[/' & $OPT & ']')
If @error Then
  Return "errorsz"
  Return $tOpt[0]


Hopefully there is some glaring issue with my code or there is some better way of flushing the file :s. Thanks in advance!

Share this post

Link to post
Share on other sites

Without a script to reproduce your issue, and not just snippets, we can't help much.

I'd suggest adding a message box on the Func GetOption, so you can see exactly what the value of $tFile is...maybe you are only including the name, and not the path.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...