How can I copy a text from notepad? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

How can I copy a text from notepad?

Post by Marcosa1020 » 15 Apr 2020, 02:46

Hi Everyone,

This script can copy all text from A_file to B_file when A_file is opened, but I want to add some conditions and copy the text to B_file. The text will be stored in B_file, when the condition is like A.PNG.

Thanks in advance for your help^^

Code: Select all

Gui +AlwaysOnTop
Gui, Color, white
Gui, Show, x131 y91 h220 w280, Search_TXT
Gui, Add, Button, x165 y173 w60 h25 , START
Gui, Font, Norm S10 W500 cBlack , Tahoma
Gui, Add, text, x10 y33, A
Gui, Add, text, x10 y103, B
Gui, Add, DropDownList, x30 y30 w50 cblack h130 vcard1, C#1|C#2|C#3|C#4|C#5|C#6
Gui, Add, DropDownList, x90 y30 w50 cblack h130 vcard2, D#1|D#2|D#3|D#4|D#5|D#6
Gui, Add, DropDownList, x30 y100 w50 cblack h130 vcard3, C#1|C#2|C#3|C#4|C#5|C#6
Gui, Add, DropDownList, x90 y100 w50 cblack h130 vcard4, D#1|D#2|D#3|D#4|D#5|D#6

#Persistent
WinGet, a_ID, ID, A
SetTimer, aa, 500
return

aa:
WinGet, a1_ID, ID, A
If ( a_ID != a1_ID )
k_ID = %a1_ID%
Return

ButtonSTART:
if WinExist("A_file")
{
	WinActivate
	WinWaitActive
	Sleep, 50
	Send, ^a
	Sleep, 50
	Clipboard := ""
	Send, ^c
	ClipWait
	FileAppend, %Clipboard%, C:\Users\User\Desktop\B_fail.txt
}



    return
 GuiClose:
ExitApp


A_file.txt:
Field_A, C#1, D#2
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Coni HFK

Field_A, C#2, D#4
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Coni HFK
300.8 8000 C 8500 8800 Coni HKE

Field_A, C#3, D#3
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Error HFK

Field_A, C#4, D#5
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Coni HFK
300.8 8000 C 8500 8800 Coni HKE
300.9 9000 C 9500 9800 Coni OUD
I hope this text in B_file
Field_A, C#2, D#4
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Coni HFK
300.8 8000 C 8500 8800 Coni HKE

Field_A, C#3, D#3
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Error HFK
Attachments
A.PNG
A.PNG (5.93 KiB) Viewed 1350 times

BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: How can I copy a text from notepad?

Post by BNOLI » 15 Apr 2020, 03:06

a) :arrow: FileRead to copy content of file A into a variable
b) push all sections of file A into an array
c) parse the array to identify the correct sections based on the conditions.
d) write found sections into file B

PS. check out GUIs wp/xp/hp (and its smart palls xp+<offset>/...) parameters!
Spoiler
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 15 Apr 2020, 03:46

BNOLI wrote:
15 Apr 2020, 03:06
a) :arrow: FileRead to copy content of file A into a variable
b) push all sections of file A into an array
c) parse the array to identify the correct sections based on the conditions.
d) write found sections into file B

PS. check out GUIs wp/xp/hp (and its smart palls xp+<offset>/...) parameters!
Spoiler
Hi BNOLI,

I need some time to study. Thank you for your reply. :thumbup:

Code: Select all

cIndex := "C#1|C#2|C#3|C#4|C#5|C#6"
dIndex := "D#1|D#2|D#3|D#4|D#5|D#6"

Gui +AlwaysOnTop
Gui, Color, White
Gui, Font, Norm S10 W500 cBlack , Tahoma

Gui, Add, Button,		x165	y173	w60		h25						, START

Gui, Add, Text, 		x10		y33										, A
Gui, Add, Text, 		xp		yp+70									, B

Gui, Add, DropDownList, x30 	y30		w50		h130	cblack	vcard1	, % cIndex		
Gui, Add, DropDownList, xp+60 	yp		wp		h130		cblack	vcard2	, % dIndex
Gui, Add, DropDownList, xp-60 	yp+70	wp		h130		cblack	vcard3	, % cIndex
Gui, Add, DropDownList, xp+60 	yp		wp		h130		cblack	vcard4	, % dIndex

Gui, Show, 				x131	y91		w280	h220					, Search_TXT
Return


#Persistent
WinGet, a_ID, ID, A
SetTimer, aa, 500
return

aa:
WinGet, a1_ID, ID, A
If ( a_ID != a1_ID )
k_ID = %a1_ID%
Return

ButtonSTART:
if WinExist("A_file")
{
	WinActivate
	WinWaitActive
	Sleep, 50
	Send, ^a
	Sleep, 50
	Clipboard := ""
	Send, ^c
	ClipWait
	FileAppend, %Clipboard%, C:\Users\User\Desktop\B_fail.txt
    FileRead, Clipboard, C:\Users\User\Desktop\B_fail.txt
    SearchWordArray, [card1, card2]
    
}


    return
	
	 GuiClose:
ExitApp

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 20 Apr 2020, 14:20

Hi everyone,

I still don't understand how to write this program. Can you help me ?

Code: Select all

cIndex := "C#1|C#2|C#3|C#4|C#5|C#6"
dIndex := "D#1|D#2|D#3|D#4|D#5|D#6"

Gui +AlwaysOnTop
Gui, Color, White
Gui, Font, Norm S10 W500 cBlack , Tahoma

Gui, Add, Button,		x165	y173	w60		h25						, START

Gui, Add, Text, 		x10		y33										, A
Gui, Add, Text, 		xp		yp+70									, B

Gui, Add, DropDownList, x30 	y30		w50		h130	cblack	vcard1	, % cIndex		
Gui, Add, DropDownList, xp+60 	yp		wp		h130		cblack	vcard2	, % dIndex
Gui, Add, DropDownList, xp-60 	yp+70	wp		h130		cblack	vcard3	, % cIndex
Gui, Add, DropDownList, xp+60 	yp		wp		h130		cblack	vcard4	, % dIndex

Gui, Show, 				x131	y91		w280	h220					, Search_TXT
Return


#Persistent
WinGet, a_ID, ID, A
SetTimer, aa, 500
return

aa:
WinGet, a1_ID, ID, A
If ( a_ID != a1_ID )
k_ID = %a1_ID%
Return

ButtonSTART:
if WinExist("A_file")
{
	WinActivate
	WinWaitActive
	Sleep, 50
	Send, ^a
	Sleep, 50
	Clipboard := ""
	Send, ^c
	ClipWait
	Array := Object()
	FileAppend, %Clipboard% C:\Users\User\Desktop\A_file.txt
	FileRead, Array, C:\Users\User\Desktop\A_file.txt
    Loop, read, C:\Users\User\Desktop\A_file.txt, C:\Users\User\Desktop\B_file.txt
{
    if InStr(C:\Users\User\Desktop\A_file.txt, %card1% )
        FileAppend, %A_LoopReadLine%`n
}

}

    return
	
	 GuiClose:
ExitApp

BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: How can I copy a text from notepad?

Post by BNOLI » 20 Apr 2020, 15:50

Without diving deeper into your code ... parameter settings within function(call)s are written in expression-style ...
wrong: InStr(C:\Users\User\Desktop\A_file.txt, %card1%)
right: InStr("C:\Users\User\Desktop\A_file.txt", card1)

https://www.autohotkey.com/docs/Variables.htm#Expressions
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 20 Apr 2020, 17:05

BNOLI wrote:
20 Apr 2020, 15:50
Without diving deeper into your code ... parameter settings within function(call)s are written in expression-style ...
wrong: InStr(C:\Users\User\Desktop\A_file.txt, %card1%)
right: InStr("C:\Users\User\Desktop\A_file.txt", card1)

https://www.autohotkey.com/docs/Variables.htm#Expressions
Hi BNOLI,

Thanks for your reply.

BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: How can I copy a text from notepad?

Post by BNOLI » 21 Apr 2020, 00:45

If I get it right, you wanna ...
a) copy some text
b) drop it to A.txt
c) filter A.text (filter criteria/conditions taken from your Gui)
d) write/append filtered outcome to B.txt

I'd go with filtering the content of the :arrow: ClipBoard (variable) directly, so the creation of A.txt isn't needed (unless you need it for archiving/reference reasons). IMHO, the best way to filter the copied sections is to use (I guess quite simple) RegEx - of which I have no clue about :roll:
To attract a few RegExGurus (REGs ;)) solving that minor issue I'd recommend changing your threads Subject requesting some RegEx support!

Good luck 8-)

OK, ok - I'll make your day ... :shh: (feel free to give some money to a local charity, supporting someone who's currently suffering, thx :thumbup: )
Spoiler
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 23 Apr 2020, 02:20

Hi BNOLI,

First, thanks for your support. You are right, I want to achieve the following four steps.
Step1, copy some text
Step2, drop it to A.txt
Step3, filter A.text (filter criteria/conditions taken from your Gui)
Step4, write/append filtered outcome to B.txt

I hope the copy content to the clipboard then opening A_file, because I want to use it more flexibly, so I modified the code as below.
Copy content data to the clipboard then opening A_file is failed, could you please help me?

Code: Select all

#NoEnv
#SingleInstance, Force

test := 1												
	
	cIndex := "||C#1|C#2|C#3|C#4|C#5|C#6"								
	dIndex := "||D#1|D#2|D#3|D#4|D#5|D#6"
	
	Gui +AlwaysOnTop
	Gui, Color, White
	Gui, Font, Norm S10 W500 cBlack , Tahoma
	
	Gui, Add, Text, 		x10		y18		w10												, A
	Gui, Add, Text, 		xp+146	yp		wp												, B
	Gui, Add, Button,		xp+166	yp-5	w18						gStart					, START
	
	Gui, Add, DropDownList, x30	 	yp+2	w50				cblack			vA1		Choose1	, % cIndex		
	Gui, Add, DropDownList, xp+60 	yp		wp				cblack			vA2		Choose1	, % dIndex
	Gui, Add, DropDownList, xp+90 	yp		wp				cblack			vB1		Choose1	, % cIndex
	Gui, Add, DropDownList, xp+60 	yp		wp				cblack			vB2		Choose1	, % dIndex
	
	Gui, Show, 				x100	y100	w400	h58										, MySearch
	GuiControl, Focus, A1																				
	Return
	
	
	Start:
    Clipboard := "" ; <<<<<<<<<<<< Clear Clipboard
    If (test != 1) ; <<<<<< Start the program
	Send, ^a  
    Sleep, 50
    Send, ^c	;<<<<<<<<<<<<<<< Copy all current content
    ClipWait
	FileAppend, %Clipboard% C:\Users\User\Desktop\A_file.txt ;<<<<<<<<< No file was created ??????????????
		
		Gui, Submit													; transfer GuiVars for further processing
		parse(ClipBoard,A1,A2,B1,B2)								; function call. Parameters: <clipboard content> + <selected values from the gui>
		If FileExist("oFile.txt")									; check for o(utput)File ...
			Run, Notepad.exe oFile.txt								; if exist, show filtered content, but if nothing has matched, no file has been created ...
		Else
			SoundBeep												; ... so let's play some sad noise!
		Gui, Destroy												; get rid of this marvelous gui
		Return
	
	
	parse(Content,sA1,sA2,sB1,sB2) {								; RegEx-free function ahead!
		If FileExist("oFile.txt")									; check for oFile ...
			FileDelete, oFile.txt									; ... and get rid of it.
		Content := StrReplace(Content, "Field_A", "`rField_A")		; MAGIC! Tag `r character to existing empty lines as dummy/unique delimiter
		A := sA1 . ", " . sA2										; concatenate vars to create search pattern eg: "C#1, D#2"
		B := sB1 . ", " . sB2
		Loop, Parse, Content, `r									; parse content for sections using the previously added `r as the delimiter
		{
			If InStr(A_LoopField,A) OR InStr(A_LoopField,B)			; if parsed section contains matching search patterns ...
				FileAppend,% A_LoopField, oFile.txt					; write section to oFile. Mission accomplished. Have fun!
			}
		}

return
	
	 GuiClose:
ExitApp

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 24 Apr 2020, 00:54

Hi everyone,

Since ClipBoard is a variable, I want to copy the current data then parse the array to identify the correct sections based on the conditions.
So I change Code_A to Code_B, if I choose C # 2 in cIndex and C # 4 in dIndex, I will get
Field_A, C#1, D#2Field_A, C#2, D#4Field_A, C#3, D#3Field_A, C#4, D#5
My script cannot run normally, how can I make it work properly? Thanks.


Code_A:

Code: Select all

#NoEnv
#SingleInstance, Force

test := 1												; once you've finished testing: 0

!c::													; press Alt+c to copy your sections to the clipboard												
	If (test != 1)										 
		Send, ^c										; the good old c(ut)
	Else
		ClipBoard =										; if testing we'll push this content to the clipboard 
		(LTrim Comment 
			Field_A, C#1, D#2
			Field_B
			Item1 Item2 Item3 Item4 Item5 Item6 Item7
			300.1 1000 A 1500 1800 Coni AKFJ
			300.2 2000 A 2500 2800 Coni FJRO
			300.3 3000 A 3500 3800 Coni EI
			300.4 4000 B 4500 4800 Coni DJS
			300.5 5000 B 5500 5800 Coni PEJ
			300.6 6000 C 6500 6800 Coni ERE
			300.7 7000 C 7500 7800 Coni HFK
			
			Field_A, C#2, D#4
			Field_B
			Item1 Item2 Item3 Item4 Item5 Item6 Item7
			300.1 1000 A 1500 1800 Coni AKFJ
			300.2 2000 A 2500 2800 Coni FJRO
			300.3 3000 A 3500 3800 Coni EI
			300.4 4000 B 4500 4800 Coni DJS
			300.5 5000 B 5500 5800 Coni PEJ
			300.6 6000 C 6500 6800 Coni ERE
			300.7 7000 C 7500 7800 Coni HFK
			300.8 8000 C 8500 8800 Coni HKE
			
			Field_A, C#3, D#3
			Field_B
			Item1 Item2 Item3 Item4 Item5 Item6 Item7
			300.1 1000 A 1500 1800 Coni AKFJ
			300.2 2000 A 2500 2800 Coni FJRO
			300.3 3000 A 3500 3800 Coni EI
			300.4 4000 B 4500 4800 Coni DJS
			300.5 5000 B 5500 5800 Coni PEJ
			300.6 6000 C 6500 6800 Coni ERE
			300.7 7000 C 7500 7800 Error HFK
			
			Field_A, C#4, D#5
			Field_B
			Item1 Item2 Item3 Item4 Item5 Item6 Item7
			300.1 1000 A 1500 1800 Coni AKFJ
			300.2 2000 A 2500 2800 Coni FJRO
			300.3 3000 A 3500 3800 Coni EI
			300.4 4000 B 4500 4800 Coni DJS
			300.5 5000 B 5500 5800 Coni PEJ
			300.6 6000 C 6500 6800 Coni ERE
			300.7 7000 C 7500 7800 Coni HFK
			300.8 8000 C 8500 8800 Coni HKE
			300.9 9000 C 9500 9800 Coni OUD
		)
	
	ClipWait														; wait till clipboard received content																				
	
	cIndex := "C#1|C#2|C#3|C#4|C#5|C#6"								; let's build the gui 
	dIndex := "D#1|D#2|D#3|D#4|D#5|D#6"
	
	Gui +AlwaysOnTop
	Gui, Color, White
	Gui, Font, Norm S10 W500 cBlack , Tahoma
	
	Gui, Add, Text, 		x10		y18		w10												, A
	Gui, Add, Text, 		xp+146	yp		wp												, B
	Gui, Add, Button,		xp+166	yp-5	w18						gStart					, START
	
	Gui, Add, DropDownList, x30	 	yp+2	w50				cblack			vA1		Choose1	, % cIndex	; pre-selected value per DDL 		
	Gui, Add, DropDownList, xp+60 	yp		wp				cblack			vA2		Choose1	, % dIndex
	Gui, Add, DropDownList, xp+90 	yp		wp				cblack			vB1		Choose1	, % cIndex
	Gui, Add, DropDownList, xp+60 	yp		wp				cblack			vB2		Choose1	, % dIndex
	
	Gui, Show, 				x100	y100	w400	h58										, MySearch
	GuiControl, Focus, A1																				; set focus to first DDL
	Return
	
	
	Start:
		Gui, Submit													; transfer GuiVars for further processing
		parse(ClipBoard,A1,A2,B1,B2)								; function call. Parameters: <clipboard content> + <selected values from the gui>
		If FileExist("oFile.txt")									; check for o(utput)File ...
			Run, Notepad.exe oFile.txt								; if exist, show filtered content, but if nothing has matched, no file has been created ...
		Else
			SoundBeep												; ... so let's play some sad noise!
		Gui, Destroy												; get rid of this marvelous gui
		Return
	
	
	parse(Content,sA1,sA2,sB1,sB2) {								; RegEx-free function ahead!
		If FileExist("oFile.txt")									; check for oFile ...
			FileDelete, oFile.txt									; ... and get rid of it.
		Content := StrReplace(Content, "Field_A", "`rField_A")		; MAGIC! Tag `r character to existing empty lines as dummy/unique delimiter
		A := sA1 . ", " . sA2										; concatenate vars to create search pattern eg: "C#1, D#2"
		B := sB1 . ", " . sB2
		Loop, Parse, Content, `r									; parse content for sections using the previously added `r as the delimiter
		{
			If InStr(A_LoopField,A) OR InStr(A_LoopField,B)			; if parsed section contains matching search patterns ...
				FileAppend,% A_LoopField, oFile.txt					; write section to oFile. Mission accomplished. Have fun!
			}
		}

return
	
	 GuiClose:
ExitApp
Code_B:

Code: Select all

#NoEnv
#SingleInstance, Force											
	
	cIndex := "|C#1|C#2|C#3|C#4|C#5|C#6"								
	dIndex := "|D#1|D#2|D#3|D#4|D#5|D#6"
	
	Gui +AlwaysOnTop
	Gui, Color, White
	Gui, Font, Norm S10 W500 cBlack , Tahoma
	
	Gui, Add, Text, 		x10		y18		w10												, A
	Gui, Add, Text, 		xp+146	yp		wp												, B
	Gui, Add, Button,		xp+166	yp-5	w18						gStart					, START
	
	Gui, Add, DropDownList, x30	 	yp+2	w50				cblack			vA1		Choose1	, % cIndex		
	Gui, Add, DropDownList, xp+60 	yp		wp				cblack			vA2		Choose1	, % dIndex
	Gui, Add, DropDownList, xp+90 	yp		wp				cblack			vB1		Choose1	, % cIndex
	Gui, Add, DropDownList, xp+60 	yp		wp				cblack			vB2		Choose1	, % dIndex
	
	Gui, Show, 				x100	y100	w400	h58										, MySearch
	GuiControl, Focus, A1																				
	Return
	
	
	Start:
	Send, ^a  
    Sleep, 50
    Clipboard := "" ; <<<<<<<<<<<< Clear Clipboard
    Send, ^c	;<<<<<<<<<<<<<<< Copy all current content
    ClipWait
	
		Gui, Submit													; transfer GuiVars for further processing
		parse(ClipBoard,A1,A2,B1,B2)								; function call. Parameters: <clipboard content> + <selected values from the gui>
		If FileExist("oFile.txt")									; check for o(utput)File ...
			Run, Notepad.exe oFile.txt								; if exist, show filtered content, but if nothing has matched, no file has been created ...
		Else
			SoundBeep												; ... so let's play some sad noise!
		Gui, Destroy												; get rid of this marvelous gui
		Return
	
	
	parse(Content,sA1,sA2,sB1,sB2) {								; RegEx-free function ahead!
		If FileExist("oFile.txt")									; check for oFile ...
			FileDelete, oFile.txt									; ... and get rid of it.
		Content := StrReplace(Content, "Field_A", "`rField_A")		; MAGIC! Tag `r character to existing empty lines as dummy/unique delimiter
		A := sA1 . ", " . sA2										; concatenate vars to create search pattern eg: "C#1, D#2"
		B := sB1 . ", " . sB2
		Loop, Parse, Content, `r									; parse content for sections using the previously added `r as the delimiter
		{
			If InStr(A_LoopField,A) OR InStr(A_LoopField,B)			; if parsed section contains matching search patterns ...
				FileAppend,% A_LoopField, oFile.txt					; write section to oFile. Mission accomplished. Have fun!
			}
		}

return
	
	 GuiClose:
ExitApp

BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: How can I copy a text from notepad?

Post by BNOLI » 24 Apr 2020, 02:03

Have you ever used my script posted above? :? It creates the output file (oFile) right after parsing the clipboard content directly based on the selection made in the GUI.
It won't create an output file if the GUI-selected options are not existing in the clipboard's content. Everything you've requested is already there, so what?? :eh:

a) use my script
b) set variable 'test ' to "0" as advised in the script :arrow: test := 1 ; once you've finished testing: 0
c) start the script
d) select your "section text" for the following filtering
e) press Alt+c to copy the selected text to clipboard
f) GUI opens, so select sections to search for and press 'Start'
g) if ...
1) your GUI-selections are not existing within the clipboard's content, you'll hear a beep sound. Or ...
2) your GUI-selection(s) have been found, so the output file (oFile) will be created containing the filtered content and opened in Notepad.

That's it.

Your script worked fine for me so far ...
a) I've disabled your ^a (select all) bc I'm not a fan of uncontrolled selecting whatever gets the focus triggered via the Start-button of the GUI.
I'd select/copy text to the clipboard before the GUI opens (as done in my script).
I've deleted the leading "|" selector from your DDL-index's as there's already a "Choose1" set as an DDL parameter.
Output worked flawlessly. :| (and again, bc the clipboard will be parsed instead of an input file there's no existing "A.txt")
Last edited by BNOLI on 24 Apr 2020, 02:40, edited 1 time in total.
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 24 Apr 2020, 02:36

BNOLI wrote:
24 Apr 2020, 02:03
Have you ever used my script posted above? :? It creates the output file (oFile) right after parsing the clipboard content directly based on the selection made in the GUI.
It won't create an output file if the GUI-selected options are not existing in the clipboard's content. Everything you've requested is already there, so what?? :eh:

a) use my script
b) set variable 'test ' to "0" as advised in the script :arrow: test := 1 ; once you've finished testing: 0
c) start the script
d) select your "section text" for the following filtering
e) press Alt+c to copy the selected text to clipboard
f) GUI opens, so select sections to search for and press 'Start'
g) if ...
1) your GUI-selections are not existing within the clipboard's content, you'll hear a beep sound. Or ...
2) your GUI-selection(s) have been found, so the output file (oFile) will be created containing the filtered content and opened in Notepad.

That's it.
Hi BNOLI,

Yes, I use your script all the time, and I really appreciate your time to help me. Please give me some time to organize my steps, we can confirm which step is wrong, because I have got a bad cold........ Thank you for your support again.

BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: How can I copy a text from notepad?

Post by BNOLI » 24 Apr 2020, 03:01

Code: Select all

	Start:
    Clipboard := "" ; <<<<<<<<<<<< Clear Clipboard
    If (test != 1) ; <<<<<< Start the program		; not really. It was meant to toogle a 'test-scenario' (using a static section-index-clipboard var for testing, see my code)
	Send, ^a  	; ... so you're using it to toogle ctrl+a (select all)  and bc 'test' isn't currently != 1 it won't be executed.
    Sleep, 50
    Send, ^c	;<<<<<<<<<<<<<<< Copy all current content ; so here we go live, but let's guess you have an empty clipboard bc nothing has been selected beforehand!?
    ClipWait
	FileAppend, %Clipboard% C:\Users\User\Desktop\A_file.txt ;<<<<<<<<< No file was created ??????????????	;  Which is correct. Check commands correct syntax (# of commas used)!
	
Since ClipBoard is a variable, I want to copy the current data then parse the array to identify the correct sections based on the conditions.
So I change Code_A to Code_B, if I choose C # 2 in cIndex and C # 4 in dIndex, I will get
Field_A, C#1, D#2Field_A, C#2, D#4Field_A, C#3, D#3Field_A, C#4, D#5
:?: (besides missing EOL chars "`n") Isn't that alraedy solved?? ...
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 24 Apr 2020, 07:34

Hi BNOLI,

Follow this code below and I didn't get anything.... I will organize my steps and let you know, we can confirm which step is wrong.

Code: Select all

	Start:
    Clipboard := "" ; <<<<<<<<<<<< Clear Clipboard
    If (test != 1) ; <<<<<< Start the program		; not really. It was meant to toogle a 'test-scenario' (using a static section-index-clipboard var for testing, see my code)
	Send, ^a  	; ... so you're using it to toogle ctrl+a (select all)  and bc 'test' isn't currently != 1 it won't be executed.
    Sleep, 50
    Send, ^c	;<<<<<<<<<<<<<<< Copy all current content ; so here we go live, but let's guess you have an empty clipboard bc nothing has been selected beforehand!?
    ClipWait
	FileAppend, %Clipboard% C:\Users\User\Desktop\A_file.txt ;<<<<<<<<< No file was created ??????????????	;  Which is correct. Check commands correct syntax (# of commas used)!

BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: How can I copy a text from notepad?

Post by BNOLI » 24 Apr 2020, 07:58

Marcosa1020 wrote:
24 Apr 2020, 07:34
Hi BNOLI,

Follow this code below and I didn't get anything.... I will organize my steps and let you know, we can confirm which step is wrong.
Spoiler
Well, I've already followed/reviewed that code snippet, have you've seen my comments/advise behind yours in the code?
Please review! So far, there's nothing to discuss here?
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 24 Apr 2020, 08:01

BNOLI wrote:
24 Apr 2020, 02:03
Have you ever used my script posted above? :? It creates the output file (oFile) right after parsing the clipboard content directly based on the selection made in the GUI.
It won't create an output file if the GUI-selected options are not existing in the clipboard's content. Everything you've requested is already there, so what?? :eh:

a) use my script
b) set variable 'test ' to "0" as advised in the script :arrow: test := 1 ; once you've finished testing: 0

c) start the script
d) select your "section text" for the following filtering
e) press Alt+c to copy the selected text to clipboard
f) GUI opens, so select sections to search for and press 'Start'
g) if ...
1) your GUI-selections are not existing within the clipboard's content, you'll hear a beep sound. Or ...
2) your GUI-selection(s) have been found, so the output file (oFile) will be created containing the filtered content and opened in Notepad.

That's it.

Your script worked fine for me so far ...
a) I've disabled your ^a (select all) bc I'm not a fan of uncontrolled selecting whatever gets the focus triggered via the Start-button of the GUI.
I'd select/copy text to the clipboard before the GUI opens (as done in my script).
I've deleted the leading "|" selector from your DDL-index's as there's already a "Choose1" set as an DDL parameter.
Output worked flawlessly. :| (and again, bc the clipboard will be parsed instead of an input file there's no existing "A.txt")
Hi BNOLI,

a) use my script

Code: Select all


#NoEnv
#SingleInstance, Force

test := 1												; once you've finished testing: 0

!c::													; press Alt+c to copy your sections to the clipboard												
	If (test != 1)										 
		Send, ^c										; the good old c(ut)
	Else
		ClipBoard =										; if testing we'll push this content to the clipboard 
		(LTrim Comment 
			Field_A, C#1, D#2
			Field_B
			Item1 Item2 Item3 Item4 Item5 Item6 Item7
			300.1 1000 A 1500 1800 Coni AKFJ
			300.2 2000 A 2500 2800 Coni FJRO
			300.3 3000 A 3500 3800 Coni EI
			300.4 4000 B 4500 4800 Coni DJS
			300.5 5000 B 5500 5800 Coni PEJ
			300.6 6000 C 6500 6800 Coni ERE
			300.7 7000 C 7500 7800 Coni HFK
			
			Field_A, C#2, D#4
			Field_B
			Item1 Item2 Item3 Item4 Item5 Item6 Item7
			300.1 1000 A 1500 1800 Coni AKFJ
			300.2 2000 A 2500 2800 Coni FJRO
			300.3 3000 A 3500 3800 Coni EI
			300.4 4000 B 4500 4800 Coni DJS
			300.5 5000 B 5500 5800 Coni PEJ
			300.6 6000 C 6500 6800 Coni ERE
			300.7 7000 C 7500 7800 Coni HFK
			300.8 8000 C 8500 8800 Coni HKE
			
			Field_A, C#3, D#3
			Field_B
			Item1 Item2 Item3 Item4 Item5 Item6 Item7
			300.1 1000 A 1500 1800 Coni AKFJ
			300.2 2000 A 2500 2800 Coni FJRO
			300.3 3000 A 3500 3800 Coni EI
			300.4 4000 B 4500 4800 Coni DJS
			300.5 5000 B 5500 5800 Coni PEJ
			300.6 6000 C 6500 6800 Coni ERE
			300.7 7000 C 7500 7800 Error HFK
			
			Field_A, C#4, D#5
			Field_B
			Item1 Item2 Item3 Item4 Item5 Item6 Item7
			300.1 1000 A 1500 1800 Coni AKFJ
			300.2 2000 A 2500 2800 Coni FJRO
			300.3 3000 A 3500 3800 Coni EI
			300.4 4000 B 4500 4800 Coni DJS
			300.5 5000 B 5500 5800 Coni PEJ
			300.6 6000 C 6500 6800 Coni ERE
			300.7 7000 C 7500 7800 Coni HFK
			300.8 8000 C 8500 8800 Coni HKE
			300.9 9000 C 9500 9800 Coni OUD
		)
	
	ClipWait														; wait till clipboard received content																				
	
	cIndex := "|C#1|C#2|C#3|C#4|C#5|C#6"								; let's build the gui 
	dIndex := "|D#1|D#2|D#3|D#4|D#5|D#6"
	
	Gui +AlwaysOnTop
	Gui, Color, White
	Gui, Font, Norm S10 W500 cBlack , Tahoma
	
	Gui, Add, Text, 		x10		y18		w10												, A
	Gui, Add, Text, 		xp+146	yp		wp												, B
	Gui, Add, Button,		xp+166	yp-5	w18						gStart					, START
	
	Gui, Add, DropDownList, x30	 	yp+2	w50				cblack			vA1		Choose1	, % cIndex	; pre-selected value per DDL 		
	Gui, Add, DropDownList, xp+60 	yp		wp				cblack			vA2		Choose1	, % dIndex
	Gui, Add, DropDownList, xp+90 	yp		wp				cblack			vB1		Choose1	, % cIndex
	Gui, Add, DropDownList, xp+60 	yp		wp				cblack			vB2		Choose1	, % dIndex
	
	Gui, Show, 				x100	y100	w400	h58										, MySearch
	GuiControl, Focus, A1																				; set focus to first DDL
	Return
	
	
	Start:
		Gui, Submit													; transfer GuiVars for further processing
		parse(ClipBoard,A1,A2,B1,B2)								; function call. Parameters: <clipboard content> + <selected values from the gui>
		If FileExist("oFile.txt")									; check for o(utput)File ...
			Run, Notepad.exe oFile.txt								; if exist, show filtered content, but if nothing has matched, no file has been created ...
		Else
			SoundBeep												; ... so let's play some sad noise!
		Gui, Destroy												; get rid of this marvelous gui
		Return
	
	
	parse(Content,sA1,sA2,sB1,sB2) {								; RegEx-free function ahead!
		If FileExist("oFile.txt")									; check for oFile ...
			FileDelete, oFile.txt									; ... and get rid of it.
		Content := StrReplace(Content, "Field_A", "`rField_A")		; MAGIC! Tag `r character to existing empty lines as dummy/unique delimiter
		A := sA1 . ", " . sA2										; concatenate vars to create search pattern eg: "C#1, D#2"
		B := sB1 . ", " . sB2
		Loop, Parse, Content, `r									; parse content for sections using the previously added `r as the delimiter
		{
			If InStr(A_LoopField,A) OR InStr(A_LoopField,B)			; if parsed section contains matching search patterns ...
				FileAppend,% A_LoopField, oFile.txt					; write section to oFile. Mission accomplished. Have fun!
			}
		}

return
	
	 GuiClose:
ExitApp
b) set variable 'test ' to "0" as advised in the script :arrow: test := 1 ; once you've finished testing: 0 What is this? Do I need to do anything with coding?
c) start the script Starting
d) select your "section text" for the following filtering I modified my notepad 300.1 => "300.1"
Image
e) press Alt+c to copy the selected text to clipboard
Image
f) GUI opens, so select sections to search for and press 'Start'
g) if ...
1) your GUI-selections are not existing within the clipboard's content, you'll hear a beep sound. Or ...
2) your GUI-selection(s) have been found, so the output file (oFile) will be created containing the filtered content and opened in Notepad.
I got this, Please help me confirm my steps, many thanks
Image
Attachments
3.PNG
3.PNG (20.99 KiB) Viewed 986 times
2.PNG
2.PNG (28.32 KiB) Viewed 986 times
1.PNG
1.PNG (22.61 KiB) Viewed 986 times

BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: How can I copy a text from notepad?  Topic is solved

Post by BNOLI » 24 Apr 2020, 10:55

Enabled Test (Test := 1). Processing data from within the script.
Spoiler
Worked fine from the beginning.

Disabled Test (Test := 0). Working with external data.
Spoiler
Needed the following change ...

Code change: changed from "`r" (carriage return) to "~" (tilde) character to split sections, used at StrReplace.
And yes, RegEx would definitely the better thing to do.
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 24 Apr 2020, 19:58

BNOLI wrote:
24 Apr 2020, 10:55
Enabled Test (Test := 1). Processing data from within the script.
Spoiler
Worked fine from the beginning.

Disabled Test (Test := 0). Working with external data.
Spoiler
Needed the following change ...

Code change: changed from "`r" (carriage return) to "~" (tilde) character to split sections, used at StrReplace.
And yes, RegEx would definitely the better thing to do.
Hi BNOLI,

Thank you so much.

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 27 Apr 2020, 08:34

Hi BNOLI,

I found if that text is repeated, it will be read repeatedly.

When I select C#2 and D#4 in cIndex and then press start.

Field_A, C#1, D#2
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Coni HFK

Field_A, C#2, D#4
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Coni HFK
300.8 8000 C 8500 8800 Coni HKE

Field_A, C#2, D#4
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Error HFK


I can got these in the oFile.

Field_A, C#2, D#4
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Coni HFK
300.8 8000 C 8500 8800 Coni HKE

Field_A, C#2, D#4
Field_B
Item1 Item2 Item3 Item4 Item5 Item6 Item7
300.1 1000 A 1500 1800 Coni AKFJ
300.2 2000 A 2500 2800 Coni FJRO
300.3 3000 A 3500 3800 Coni EI
300.4 4000 B 4500 4800 Coni DJS
300.5 5000 B 5500 5800 Coni PEJ
300.6 6000 C 6500 6800 Coni ERE
300.7 7000 C 7500 7800 Error HFK


How can I avoid duplication and get the last content ?? Thanks in advance.

BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: How can I copy a text from notepad?

Post by BNOLI » 27 Apr 2020, 09:52

Was it said in your initial post that you will have duplicate sections within your source?? :wtf:
Well, you can use AHK's :arrow: Sort command 'to sort this out' ;) #
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Marcosa1020
Posts: 160
Joined: 23 Sep 2015, 19:15

Re: How can I copy a text from notepad?

Post by Marcosa1020 » 27 Apr 2020, 15:29

BNOLI wrote:
27 Apr 2020, 09:52
Was it said in your initial post that you will have duplicate sections within your source?? :wtf:
Well, you can use AHK's :arrow: Sort command 'to sort this out' ;) #
Hi BNOLI,

Sorry....... I didn't think would happen. I tried to add sort, A_LoopField, r to the code but failed in execution......

Post Reply

Return to “Ask For Help”