Sign in to follow this  
Followers 0
strate

File manipulation?

7 posts in this topic

I have two scripts one script (A) will allow many different users to enter information into a file. The information they enter is appeneded to the end of the file. The other program (B ) reads the first line of the file. Then will respond with a msgbox. Heres the problem, Script (B ) when it reads line 1 it needs to remove it from the list and bring everything up. Creating a scroll if you will. So as users are entering information, script B will be processing the oldest information. How do I get the file to roll?

Script A

#include <GUIConstants.au3>
HotKeySet('#x','Admin_Exit')
$Record_File = 'C:\Record File.txt'
While 1
    GUICreate ("Scan Bar-code from Audit Tag:", 320, 30, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 100, -1, 0x0)
    $2D_SCAN_INPUT = GUICtrlCreateInput ("", 10, 5, 300, 20)
    GUICtrlSetState (-1, $GUI_FOCUS)
    GUISetState (@SW_SHOW)
    While 2
        Sleep(50)
        $msg = GUIGetMsg ()
        $CLOSE_SEQUENCE = GUICtrlRead ($2D_SCAN_INPUT)
        Select
            Case $msg = $GUI_EVENT_CLOSE
                MsgBox(48, "Notice", "You have choose to exit.")
                If FileReadLine($Record_File,1) = '' Then 
                    ExitLoop(2)
                Else
                    MsgBox(262144,'Notice','Unable to close. Record file still has entries.')
                EndIf
            Case StringRight($CLOSE_SEQUENCE, 1) = "*"
                $2D_SCAN = GUICtrlRead ($2D_SCAN_INPUT)
                GUIDelete ()
                ExitLoop
        EndSelect
    Wend
    FileWrite($Record_File,$2D_SCAN&@CRLF)
WEnd

Func Admin_Exit()
    $Admin = MsgBox(262144+4,'Notice','This will close the ability to enter files to bo recorded, exit?')
    If $Admin = 6 Then
        Exit
    Else
        Return
    EndIf
EndFunc
Script B
$Record_File = 'C:\Record File.txt'
While 1
    $File_Read = FileReadLine($Record_File,1)
    If StringLen($File_Read) = 0 Then
        MsgBox(0, "Unable to continue", "input was blank.")
        ExitLoop (1)
    EndIf
    If StringInStr($File_Read, "?") = 0 Then
        MsgBox(0, "Unable to record", "Bar-code not formatted correctly.")
        ExitLoop (1)
    EndIf
    $File_Read_Breakdown = StringSplit($File_Read, "?")
    
    $Verify_Entry = MsgBox(6 + 262144, "Verify Entry", "Kit Number: " & $File_Read_Breakdown[1] & Chr(13) & "Quantity:  " & $File_Read_Breakdown[3])
    SoundSetWaveVolume(100)
    SoundPlay(@WindowsDir & "\media\ringin.wav",1)
WEnd

Attached is a copy of the file.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

How do I get the file to roll?

uh.. quit reading the first line all the time.... Below is one way of accomplishing the task.

You could also use a For/Next Loop, and vary that ....

$Record_File = 'C:\Record File.txt'
$line_number = 1
While 1
    $File_Read = FileReadLine($Record_File,$line_number)
    ;you need to test for an error here - look at the helpfile.
    ;you also should probably replace all of those ifs w/ a select/endselect
    If StringLen($File_Read) = 0 Then
        MsgBox(0, "Unable to continue", "input was blank.")
        ExitLoop (1)
    EndIf
    If StringInStr($File_Read, "?") = 0 Then
        MsgBox(0, "Unable to record", "Bar-code not formatted correctly.")
        ExitLoop (1)
    EndIf
    $File_Read_Breakdown = StringSplit($File_Read, "?")
    
    $Verify_Entry = MsgBox(6 + 262144, "Verify Entry", "Kit Number: " & $File_Read_Breakdown[1] & Chr(13) & "Quantity:  " & $File_Read_Breakdown[3])
    SoundSetWaveVolume(100)
    SoundPlay(@WindowsDir & "\media\ringin.wav",1)
     $line_number = $line_number + 1
WEnd
Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Also,

if script a and b can run simultaneously, or multiple A's run simultaneously, you could end up w/ missing or duplicated entries, given that you are dependent on the filesystem to open/close a single file.

You may wish to consider instead a methodology of treating each event generated by any number of Events(A) to be handled as discreet events.

One method of doing this is to write a single (unique) filename per transaction, then loop through the contents of a directory for files to process. Another would be to wait in a loop until a given (constant) filename did NOT exist - this would tell you that the previous event has been processed by B. There are plenty of samples of how to do either of those. Other options are to use a database (adding records in A, flagging them as done in :o or some some form of inter-process communication.

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

Maybe I forgot something... I want line one to be removed from the list, then line 2 to become line 1. Script B will need to run until the record file has nothing in it. Doing this will allow the file to stay small in size.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

One method of doing this is to write a single (unique) filename per transaction, then loop through the contents of a directory for files to process.

I like this idea more I think. I need to read the post about USB devices though to see if I could detect multiple scan guns on a pc.

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I want line one to be removed from the list, then line 2 to become line 1. Script B will need to run until the record file has nothing in it. Doing this will allow the file to stay small in size.

So will writing one line files. Inline file editing is not built into au3 - and you would still have a potential problem w/ potential duplicated / missing entries. Hence,

there is not , AFAIK, a FileDeleteLine() function.

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

So will writing one line files. Inline file editing is not built into au3 - and you would still have a potential problem w/ potential duplicated / missing entries. Hence,

there is not , AFAIK, a FileDeleteLine() function.

That is why I am leaning on your idea of using the directory

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

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