Sign in to follow this  
Followers 0
aquilesboy

Selecting lines then copy to a new file

6 posts in this topic

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!

Share this post


Link to post
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?


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Good to know. :)

Best regards.


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

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