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?
Please Help , Im new
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Please Help , Im new
Hi.
Here is a script with some useable commands to solve your issue.
Script and the txt-files has to be in same folder.
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.
Re: Please Help , Im new
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
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
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Please Help , Im new
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.
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.
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Please Help , Im new
There are many ways to same solution.popwojciu wrote:... maybe is it possible to make it with using two clipboards?
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 and logical addendum
Last edited by divanebaba on 15 Feb 2018, 05:46, edited 2 times in total.
Einfach nur ein toller Typ.
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Please Help , Im new
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.popwojciu wrote:... how I can paste txt from clipboard in second line...
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
Einfach nur ein toller Typ.
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Please Help , Im new
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:Both versions are functional. Decide for your own, which version you want to use.
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
Einfach nur ein toller Typ.
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Please Help , Im new
Thanks, but this is not true. I'm just an idiot fooled out of his education.popwojciu wrote:You are amazing !
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
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
Look here for another languages.
Executing a file, look for run command.
Einfach nur ein toller Typ.
Re: Please Help , Im new
Eine buddhistische weisheit: "An zorn festzuhalten heißt gift trinken und erwarten, dass der andere dadurch stirbt.".Thanks, but this is not true. I'm just an idiot fooled out of his education.
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Please Help , Im new
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.
Who is online
Users browsing this forum: dnus, garry, JoeWinograd, yabab33299 and 161 guests