Jump to content

Selecting lines then copy to a new file


Go to solution Solved by careca,

Recommended Posts

Hello there again,

Ok I will try my best to explain because english is not my main language, so patience comes great ...

Continuing with my yesterday post, in the below code I'm able to select a name from a ComboBox then search for that name in $aArray and have a sucesfull return, till there everything is right.

Now I'm trying to select a text wich starts 4 lines before where my search is located ($iIndex),  then select 23 lines down....and finally, copy this selection to a new .txt file.

Honestly I dont have any idea how to do it, I have searched all day in forum, tried some examples but I cant get it done.

The code that I need comes after the "$select = $iIndex - 4" line. 

Func _Buttonprint()
Global $name = GUICtrlRead($Combo1)
If $name = "Choose an employee" Then
    MsgBox(16,"Error", "You have to select an employee")
Else
Global $aArray
_FileReadToArray($file, $aArray)
_ArrayTrim ($aArray,$trim,1)
$iStart = 0
While 1
   Global $iIndex = _ArraySearch($aArray, $name, $iStart)
    If $iIndex = -1 Then ExitLoop
        $sLine = $aArray[$iIndex]
    
        If $sLine = "" Then
            MsgBox(0,"Error", "You have to select an employee")
        Else
            $anws = MsgBox(4,"Choose", "Ticket from:" &  $name & @LF & "¿Is that correct?" & " on line " & $iIndex)
            If $anws = 6 Then
                
                $select = $iIndex - 4 ;I use this line cuz the text that I need start 4 lines before where my $iIndex is.
MsgBox(0,"Print","Printing....")
            EndIf
        EndIf
    $iStart = $iIndex
    
    If $iStart > $aArray[0] Then ExitLoop                

EndIf
EndFunc

 Any advice, help?

I hope I explained well.

Thanks in advance!

Link to comment
Share on other sites

You are missing Wend in your code.

You should read up on FileOpen and FileWrite in the Help file.

Outside of that, it is not totally clear to me what you are aiming at.

Not knowing that, INI functions may even be relevant for your overall objective?

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Always 23 lines long and 4 before result of $select?

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • Solution

Had to create an array of numbers for test

Local $select = 8

;======================================================
;Had to create an array of text for test
#include <Array.au3>
$File = @ScriptDir& '\Sample.txt'
$FileOpen = FileOpen($File)
$FileRead = FileReadToArray($FileOpen)
FileClose($FileOpen)
;_ArrayDisplay($FileRead)
;======================================================

$FileTxt = @ScriptDir& '\NewFile.txt'
$FileTxtOpen = FileOpen($FileTxt, 2)

Work()

Func Work()
For $Line = $select - 5 To $select + 18
    ConsoleWrite('Line '&$Line&' = '& $FileRead[$Line] &@CRLF)
    $FileTxtWrite = FileWriteLine($FileTxtOpen, $FileRead[$Line])
Next
FileClose($FileTxtOpen)
EndFunc

EDIT: $select, not $index

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

You are missing Wend in your code.

You should read up on FileOpen and FileWrite in the Help file.

Outside of that, it is not totally clear to me what you are aiming at.

Not knowing that, INI functions may even be relevant for your overall objective?

Yeah I missed to write that, but I had it. :) Thanks!

Had to create an array of numbers for test

Local $select = 8

;======================================================
;Had to create an array of text for test
#include <Array.au3>
$File = @ScriptDir& '\Sample.txt'
$FileOpen = FileOpen($File)
$FileRead = FileReadToArray($FileOpen)
FileClose($FileOpen)
;_ArrayDisplay($FileRead)
;======================================================

$FileTxt = @ScriptDir& '\NewFile.txt'
$FileTxtOpen = FileOpen($FileTxt, 2)

Work()

Func Work()
For $Line = $select - 5 To $select + 18
    ConsoleWrite('Line '&$Line&' = '& $FileRead[$Line] &@CRLF)
    $FileTxtWrite = FileWriteLine($FileTxtOpen, $FileRead[$Line])
Next
FileClose($FileTxtOpen)
EndFunc

EDIT: $select, not $index

Careca, Finally got it!...I used your code with some corrections in variables and it worked exactly like I wanted!

Thanks you very much guys for all the help you gave me, with this I finalized my project :)

See you around!

Link to comment
Share on other sites

Good to know. :)

Best regards.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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...