Sign in to follow this  
Followers 0
theguy0000

FileWrite not working?

13 posts in this topic

ok, so, i use filewrite to write a bunch of lines to a file. it works, but its all on one line. so, i add @CRLF to the end of every line. it gerates a bank file. no errors, just a blank file.

the file is attached to this post.

thanks!

- Matt


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites



it creates a blank file.


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

it creates a blank file.

<{POST_SNAPBACK}>

You need to close the file before checking its content...

FileClose( $mod )
    While 1
        $chars = FileRead($mod, 1)
        If @error = -1 Then ExitLoop
    Wend
    If $chars = "" Then
        MsgBox (0, "ERROR", "ERROR: could not write to file " & $file & ". MOD creation failed.")
    EndIf

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

error on line 102

$chars = FileRead($mod, 1)

Invalid file handle used.

edit: nevermind, i fixed that

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

ok, i fixed that, but now i have a few more problems.

the MOD creation is successful, it writes to the file perfectly. but, i still get ERROR: could not write to file " & $file & ". MOD creation failed.

here's the code for this error message:

$mod = FileOpen($file, 0)
        If $mod = -1 Then
        MsgBox(48, "Error", "Unable to open file for reading. ABORTING APPLICATION")
        Exit
    EndIf

    While 1
        $chars = FileRead($mod, 1)
        If @error = -1 Then ExitLoop
    Wend
    If $chars = "" Then
        MsgBox (0, "ERROR", "ERROR: could not write to file " & $file & ". MOD creation failed.")
    EndIf

---------------------------------------------------------------

second problem:

ok, here is my GUI:

$modName=GUICtrlCreateInput ( "", 85, 25, 100, 21)
$modNameLabel=GUICtrlCreateLabel ("MOD name: ",  10, 30, 100, 21)
$modAuthor=GUICtrlCreateInput ( "", 85, 50, 100, 21)
$modAuthorLabel=GUICtrlCreateLabel ( "MOD Author: ", 10, 55, 100, 21)
$modEmail=GUICtrlCreateInput ( "", 90, 75, 100, 21)
$modEmailLabel=GUICtrlCreateLabel ( "Author E-mail: ", 10, 80, 100, 21)
$modRealName=GUICtrlCreateInput ( "", 117, 100, 100, 21)
$modRealNameLabel=GUICtrlCreateLabel ( "Author Real Name: ", 10, 105, 120, 21)
$modWebsite=GUICtrlCreateInput ( "", 95, 125, 100, 21)
$modWebsiteLabel=GUICtrlCreateLabel ( "Author website: ", 10, 130, 100, 21)
$modVersion=GUICtrlCreateInput ( "0.0.0", 85, 150, 100, 21)
$modVersionLabel=GUICtrlCreateLabel ( "MOD version: ", 10, 155, 100, 21)
$modDescription=GUICtrlCreateInput ( "", 107, 175, 170, 84)
$modDescriptionLabel=GUICtrlCreateLabel ( "MOD description: ", 10, 180, 100, 21)
$modIncluded=GUICtrlCreateInput ( "", 93, 263, 100, 21)
$modIncludedLabel=GUICtrlCreateLabel ( "Included Files: ", 10, 268, 100, 21)
$modIncludedLabel2=GUICtrlCreateLabel ( "(seperated by commas)", 195, 268, 200, 21)
$modToedit=GUICtrlCreateInput ( "", 85, 288, 100, 21)
$modToeditLabel=GUICtrlCreateLabel ( "Files to Edit: ", 10, 293, 100, 21)

(that is, of course, only part of the GUI.)

here is how it writes to the file:

Func update()
    $fileName=InputBox ( "Save as...", "Type the file name you would like to save the mod as. (don't forget to add .mod or .txt"_
    & " at the end!)")
    global $file=InputBox ( "Save as...", "Type the location of where to save the mod file:", @HomeDrive & @HomePath & "\" & $fileName, "", _
    -1, -1, 0, 0)
    save()
EndFunc
Func save()
    _FileCreate ( $file )
    $mod = FileOpen ( $file, 2 )
; Check if file opened for reading OK
    If $mod = -1 Then
        MsgBox(0, "Error", "ERROR: Unable to open file for writing. ABORTING APPLICATION.")
        Exit
    EndIf

    FileWriteLine ( $mod, "##############################################################" )
    FileWriteLine ( $mod, "## MOD Title: " & $modName )
    FileWriteLine ( $mod, "## MOD Author: " & $modAuthor & " < " & $modEmail & " > (" & $modRealName & ") " & $modWebsite )
    FileWriteLine ( $mod, "## MOD Description: " & $modDescription )
    FileWriteLine ( $mod, "## MOD Version: " & $modVersion )
    FileWriteLine ( $mod, "##" )
    FileWriteLine ( $mod, "## Installation Level: (Easy/Intermediate/Advanced)" )
    FileWriteLine ( $mod, "## Installation Time: x Minutes" )
    FileWriteLine ( $mod, "## Files To Edit: " & $modToedit )
    FileWriteLine ( $mod, "## Included Files: " & $modIncluded )
    FileWriteLine ( $mod, "## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2" )
    FileWriteLine ( $mod, "##############################################################" )
    FileWriteLine ( $mod, "## For security purposes, please check: http://www.phpbb.com/mods/" )
    FileWriteLine ( $mod, "## for the latest version of this MOD. Although MODs are checked" )
    FileWriteLine ( $mod, "## before being allowed in the MODs Database there is no guarantee" )
    FileWriteLine ( $mod, "## that there are no security problems within the MOD. No support" )
    FileWriteLine ( $mod, "## will be given for MODs not found within the MODs Database which" )
    FileWriteLine ( $mod, "## can be found at http://www.phpbb.com/mods/" )
    FileWriteLine ( $mod, "##############################################################" )
    FileWriteLine ( $mod, "## Author Notes:" )
    FileWriteLine ( $mod, "## " )
    FileWriteLine ( $mod, "##############################################################" )
    FileWriteLine ( $mod, "## MOD History:" )
    FileWriteLine ( $mod, "## " )
    FileWriteLine ( $mod, "##   " &  @YEAR  & "-" & @MON & "-" & @MDAY & " - Version " & $modVersion)
    FileWriteLine ( $mod, "##     - version notes go here" )
    FileWriteLine ( $mod, "##############################################################" )
    FileWriteLine ( $mod, "## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD" )
    FileWriteLine ( $mod, "##############################################################" )
    FileWriteLine ( $mod, " " )
    FileClose( $mod )

here is what i get in the saved file:

## MOD Title: 5
## MOD Author: 7 < 9 > (11) 13
## MOD Description: 17
## MOD Version: 15

when i enter "msr2 < codewizhelp@yahoo.com > (N/A) http://codewiz.xemoc.net" for the author, "test_description" for the description, "test_name" for MOD title, and "0.0.1 [ALPHA]" for the version. what am i doing wrong?

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

---file attached---


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

You're simply writing the GUI handles to the file and not their data. Using GUICtrlRead($modName) instead of just $modName etc. will fix your problem.

Share this post


Link to post
Share on other sites

thanks for the help!


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

While 1
        $chars = FileRead($mod, 1)
        If @error = -1 Then ExitLoop
    Wend
    If $chars = "" Then
        MsgBox (0, "ERROR", "ERROR: could not write to file " & $file & ". MOD creation failed.")
    EndIf

You are trying to read every character one-by-one from the file. When you reach the end of the file, FileRead() returns "" and sets @error. Therefore you will never get any other response from your script.

Why not use this:

if (fileGetSize($mod) = 0) then; ...

Share this post


Link to post
Share on other sites

ok thanks


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

still get that error.

;
; Start - File Reading
;   
    $mod = FileOpen($file, 0)
        If $mod = -1 Then
        MsgBox(48, "Error", "Unable to open file for reading. ABORTING APPLICATION")
        Exit
    EndIf

    if (fileGetSize($mod) = 0) then
        MsgBox (0, "ERROR", "ERROR: could not write to file " & $file & ". MOD creation failed.")
    EndIf
;
; End - File Reading
;

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

My apologies -- should be fileGetSize($file) and should probably be done while the $file isn't open.

Share this post


Link to post
Share on other sites

works perfectly, thanks a bunch!


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

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  
Followers 0