Sign in to follow this  
Followers 0
onestcoder

File Read / Write

3 posts in this topic

What I'm tring to do is check to see if the text file already has a line writen as the first line. if it is not there then write it, but if it is skip writting it.

Func _write()
$start = 0
$file3 = FileOpen(@ScriptDir & "\Database\" & "Database.txt", 9)
    $check = FileReadLine($file3, 1)
    If $check = "Date,Customer,Quote #,Quantity,Cost,Price,Each,Margin,Profit,Tax,Price w/ tax,Description,Colors" Then
        $start = 1
    EndIf
    If $start = 1 Then
        FileWriteLine($file3, "Date,Customer,Quote #,Quantity,Cost,Price,Each,Margin,Profit,Tax,Price w/ tax,Description,Colors")
    EndIf
    FileWriteLine($file3, @MDAY & @MON & @YEAR & "," & $customer_inputr & "," & $quotenumber_inputr & "," & $qty_inputr & "," & $cost_inputr & "," & $xx & "," & $xx_me & "," & $margin_inputr & "," & $xx_m & "," & $xx_t & "," & $xx_s & "," & $b_descripr & "," & $colors_fr & "/" & $colors_br)
    FileClose($file)
EndFunc

Need a website: http://www.iconixmarketing.com

Share this post


Link to post
Share on other sites



What I'm tring to do is check to see if the text file already has a line writen as the first line. if it is not there then write it, but if it is skip writting it.

Func _write()
$start = 0
$file3 = FileOpen(@ScriptDir & "\Database\" & "Database.txt", 9)
    $check = FileReadLine($file3, 1)
    If $check = "Date,Customer,Quote #,Quantity,Cost,Price,Each,Margin,Profit,Tax,Price w/ tax,Description,Colors" Then
        $start = 1
    EndIf
    If $start = 1 Then
        FileWriteLine($file3, "Date,Customer,Quote #,Quantity,Cost,Price,Each,Margin,Profit,Tax,Price w/ tax,Description,Colors")
    EndIf
    FileWriteLine($file3, @MDAY & @MON & @YEAR & "," & $customer_inputr & "," & $quotenumber_inputr & "," & $qty_inputr & "," & $cost_inputr & "," & $xx & "," & $xx_me & "," & $margin_inputr & "," & $xx_m & "," & $xx_t & "," & $xx_s & "," & $b_descripr & "," & $colors_fr & "/" & $colors_br)
    FileClose($file)
EndFunc
I don't understand one thing, how you can read and write a file in same time?

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Func _write()
$start = 0
$file3 = FileOpen(@ScriptDir & "\Database\" & "Database.txt", 9)
    $check = FileReadLine($file3, 1)
    If $check = "Date,Customer,Quote #,Quantity,Cost,Price,Each,Margin,Profit,Tax,Price w/ tax,Description,Colors" Then
        $start = 1
    EndIf
    If $start = 1 Then
        FileWriteLine($file3, "Date,Customer,Quote #,Quantity,Cost,Price,Each,Margin,Profit,Tax,Price w/ tax,Description,Colors")
    EndIf
    FileWriteLine($file3, @MDAY & @MON & @YEAR & "," & $customer_inputr & "," & $quotenumber_inputr & "," & $qty_inputr & "," & $cost_inputr & "," & $xx & "," & $xx_me & "," & $margin_inputr & "," & $xx_m & "," & $xx_t & "," & $xx_s & "," & $b_descripr & "," & $colors_fr & "/" & $colors_br)
    FileClose($file)
EndFunc
From the looks of it you're telling the program that if the line IS there to write it again. Try

Func _write()
$start = 0
$file3 = FileOpen(@ScriptDir & "\Database\" & "Database.txt", 9)
    $check = FileReadLine($file3, 1)
    If $check = "Date,Customer,Quote #,Quantity,Cost,Price,Each,Margin,Profit,Tax,Price w/ tax,Description,Colors" Then
        $start = 1
    EndIf
    If $start = 0 Then
        FileWriteLine($file3, "Date,Customer,Quote #,Quantity,Cost,Price,Each,Margin,Profit,Tax,Price w/ tax,Description,Colors")
    EndIf
    FileWriteLine($file3, @MDAY & @MON & @YEAR & "," & $customer_inputr & "," & $quotenumber_inputr & "," & $qty_inputr & "," & $cost_inputr & "," & $xx & "," & $xx_me & "," & $margin_inputr & "," & $xx_m & "," & $xx_t & "," & $xx_s & "," & $b_descripr & "," & $colors_fr & "/" & $colors_br)
    FileClose($file)
EndFunc
Edited by dbzfanatic

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