Jump to content

[Solved] Problem with fileopen or ?


Fire
 Share

Recommended Posts

Hallo Dear Community.

I'm in stuck really.Because 2 hours i'm trying to solve this nasty issuse with my code.

Shortly:

When i call this section 1'st time it does exactly what i want to do.Np there 1'st time.

But when i call it second time it wont work properly:(

It just doubles my data to listview also it just doubles my database.dat file content.(database.dat file content nothing more than RC4 encrypted data)

I think theris something wrong with fileopen() ~ fileclose() and IMHO it cause it.Seems It just "busy" thread or some previously opened file handle.

This is a problematic section of my programm.

Please if u can, advice me what to do?Any right direction please.

Anyway,Thanx in advance.

Case $menuitem2 ;<contextmenuitem for Listview (Called Delete from Database)
;$dbhandle=@scriptdir&"\database" & "\database.dat"
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Problematic Section of my code <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;~ ;----- Problem: if i call this section second time from context menu of Listview it doubles Listview items and database too:(( ;-<<<<(   2xKB =nasty problem:(
        _GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),0)
        $1=_GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),0)
        $2=_GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),1)
        $3=_GUICtrlListView_GetItemText(GUICtrlGetHandle($ListView1),_GUICtrlListView_GetSelectedIndices($ListView1),2)
    _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($ListView1))

For $i=0 To 10000000000

    If _GUICtrlListView_GetItemTextString($ListView1,$i)="||" Then
        $i=10000000000
    Else
        $stra&=_GUICtrlListView_GetItemTextString($ListView1,$i) &"|" & @CRLF
            $strarray=StringSplit($stra,@CRLF,1)
            EndIf
    Next
    

    $sop=FileOpen($dbhandle,66)

    For $i=1 To $strarray[0]

    FileWrite($dbhandle,$strarray[$i] & @CRLF)

Next

FileClose($sop)




$datas=FileRead($dbhandle)



$ops=FileOpen($dbhandle,2)

FileWrite($dbhandle,__StringEncrypt(1,$datas,$pass,2,$flag))
FileClose($ops)
$datas=""


    _GUICtrlListView_DeleteAllItems($ListView1)
            _GUICtrlStatusBar_SetText($StatusBar1,"Decrypting From Database... Please wait...")
            $reread=FileRead($dbhandle)
    $DEcrypt=__StringEncrypt(0, $reread, $pass,2,$flag)

    $avarray=StringSplit($DEcrypt,@CRLF,1)
   $reread=""
    For $i=2 To $avarray[0]
    GUICtrlCreateListViewItem($avarray[$i],$ListView1)
    _GUICtrlStatusBar_SetText($StatusBar1,"Decrypting From Database... Please wait...")
    Next
    _GUICtrlStatusBar_SetText($StatusBar1,"Data was sucessfully Decrypted from Database!")
Edited by Fire
[size="5"] [/size]
Link to comment
Share on other sites

I don't exactly know what you're intending to do, but I somehow suffered for a similiar issue, and solved it by first deleting all the lines of the list view, and then it will replace them instead of doubling them. For your file, try to use FileOpen() on replacing mode, rather than just append to the end of the file. That should do it too.

Link to comment
Share on other sites

Thanks so much for your reply jiglei.I appreciate your help.

Found it what cause it xD

It must be:

For $i=0 To 10000000000

    If _GUICtrlListView_GetItemTextString($ListView1,$i)="||" Then
        $i=10000000000
    Else
        $stra&=_GUICtrlListView_GetItemTextString($ListView1,$i) &"|" & @CRLF
            $strarray=StringSplit($stra,@CRLF,1)
            EndIf
        Next
        _GUICtrlListView_DeleteAllItems($ListView1)
    $datas=""

    $sop=FileOpen($dbhandle,66)

    For $i=1 To $strarray[0]

    FileWrite($dbhandle,$strarray[$i] & @CRLF)

Next
$stra=""

Because when i call it second time $stra is not blank.It holds previous data in self.This cause "double" effect in Listview and in database.dat file.

Thanks so much again.

Solved.

Edited by Fire
[size="5"] [/size]
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...