Jump to content
Sign in to follow this  
blantek212

Part of script in txt file

Recommended Posts

Hello,
I would like write script in autoit, but some part of script must be editable, and this part I would like put in txt file.
That solution give me possibility to editing/change  script without compile script every time when I change lines inside.
I'm confused, is it possible to do?

 

$part_name="fan"
$part_number="22"
$part_place="WS"
$part_end="2"

$handle=FileOpen("C:\temp\Missing_positions.txt",1)


;read script from script.txt
;start txt file
If $part_name="fan" Then
    FileWrite($handle,"780001"&@CRLF)
EndIf

If $part_name="fan" Then
    If $part_number="33" Then
        FileWrite($handle,"780002"&@CRLF)
    EndIf
    If $part_number="22" Then
        If $part_end="1"Then
            FileWrite($handle,"780003"&@CRLF)
        EndIf
        If $part_end="2"Then
            FileWrite($handle,"780008"&@CRLF)
        EndIf
    EndIf
EndIf
;end txt file

FileClose($handle)
MsgBox(0,"Info","Ready")

Everything between ";start txt file" and ";end txt file" I would like have in file "script.txt"
Every number "780...." which meet the conditions, I would like have save in "Missing_positions.txt" file.

Share this post


Link to post
Share on other sites

Exactly what parts of those lines would you need to change?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I would rethink your strategy about saving a small part of code into a  separate file (like you want).  But you it is possible to do so with #include "partofmyscript.txt" inserted where you want it to be.

Maybe you could use some .ini file to hold the variables you wish to have instead of using #include...

 

 

Edited by Nine

Share this post


Link to post
Share on other sites
10 minutes ago, blantek212 said:

Everything between ";start txt file" and ";end txt file" I would like have in file "script.txt"
Every number "780...." which meet the conditions, I would like have save in "Missing_positions.txt" file.

@BrewManNH

 


My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

These conditions will be totally different each time, different number, different structure if.....

If $part_name="fan" Then
    FileWrite($handle,"780001"&@CRLF)
EndIf

If $part_name="fan" Then
    If $part_number="33" Then
        FileWrite($handle,"780002"&@CRLF)
    EndIf
    If $part_number="22" Then
        If $part_end="1"Then
            FileWrite($handle,"780003"&@CRLF)
        EndIf
        If $part_end="2"Then
            FileWrite($handle,"780008"&@CRLF)
        EndIf
    EndIf
EndIf

 

Only  this paremeters are fixed

$part_name="fan"
$part_number="22"
$part_place="WS"
$part_end="2"

$handle=FileOpen("C:\temp\Missing_positions.txt",1)

 

Share this post


Link to post
Share on other sites

@caramen I'm well aware of what he wrote, don't act stupid.

If you're looking to change the actual code, and not just the numbers used in it, then it wouldn't be possible without doing something like this (from the help file):

Quote

Run a script using another compiled script:

Compiled.exe [/ErrorStdOut] /AutoIt3ExecuteScript file [params ...]
                Execute another AutoIt script file from a compiled AutoIt3 executable. 

Compiled.exe [/ErrorStdOut] /AutoIt3ExecuteLine "command line"
                Execute one line of code as with AutoIt3.exe above. 

This means that there is no need to have a copy of AutoIt3.exe in addition to the compiled file - the interpreter stub of the compiled file will replace it.  So as long as there is at least one compiled script available, other AutoIt scripts can be run without the need to have AutoIt3.exe on the machine., either pre-installed or added via FileInstall.

You'd have to have some way to pass values back and forth between the 2 separate scripts if needed. The variables that won't change can be put into an INI file and read by the second script using IniRead. That should work to do what you're looking to do. Just make sure that the part you mentioned doesn't reference any variable names in the first script unless they're also added to the second script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewManNH Hey go f... Yourself. I tryed to point you to let you help him as you wish. Call me stupid with no reason ??? I am pissed off, of guys like you now. 

You are the second guy to do this and this time it wont pass. 

 

You can PM me if you got a problem with me. 

 

Remind Rethink your words OK?! COMON

 

Edited by caramen

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Temper temper. My question to him was to try and find out what EXACTLY was going to be changed in between those 2 lines. Without that information, I would have had to give numerous examples that weren't relevant to the OP. Once I found out EXACTLY what he needed to change, my answer was direct and to the point. 

Your quote was insulting, I was fully aware of what he wrote, but it was unclear, so I asked for clarification. Your post was useless information, and you were the one trying to "look smart" when actually you were the exact opposite.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I guess you like public. What you want ? Cheers when you call me stupid ? I dont care what was the purpose, you used these words first. 

I feel the word "stupid" insulting too. 

You are a pretty good coder but, I often question myself. I recommand you to do same. 

Unless you know how people are. Rethink the thermes you're using. 

And again you can PM me, in stead of polluting this thread./

End of story.  


My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
3 hours ago, Nine said:

I would rethink your strategy about saving a small part of code into a  separate file (like you want).  But you it is possible to do so with #include "partofmyscript.txt" inserted where you want it to be.

 

 

 

I made test with #include "partofmyscript.txt", it work nice,
 but there is any way after compile script to exe file, to update this partofmyscript.txt for every time when I run exe file?
I need this in case when I modyfi partofmyscript.txt.

I check, I can use also .au3 file instead .txt

 

Share this post


Link to post
Share on other sites
1 hour ago, blantek212 said:

I made test with #include "partofmyscript.txt", it work nice,
 but there is any way after compile script to exe file, to update this partofmyscript.txt for every time when I run exe file?
I need this in case when I modyfi partofmyscript.txt.

I check, I can use also .au3 file instead .txt

Once compiled...let me think

Edited by Nine

Share this post


Link to post
Share on other sites
1 hour ago, blantek212 said:

 but there is any way after compile script to exe file, to update this partofmyscript.txt for every time when I run exe file?
I need this in case when I modyfi partofmyscript.txt.

Look at my post above, it tells you how to do that by running that part of the script as a separate script. I did forget to mention, you will need to add the following line to allow it to execute that script.

#pragma compile(AutoItExecuteAllowed, true)

NOTE: BTW, you can't use #include to add the code to a compiled script. #includes are only added when the script is compiled, after that the included file is part of the main script inside the exe. 

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Maybe you could have a .txt file with what you need/edit it as you wish, then as soon as the script starts it could rename the txt file to .au3 and that was afterwards pointed as an include.


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

Share this post


Link to post
Share on other sites

As @BrewManNH said. I didn't find any other way...

Here how to get the right exe to use :

#pragma compile(AutoItExecuteAllowed, true)

Local $BaseExe = @Compiled ? @ScriptName : @AutoItExe
Run ($BaseExe & " /AutoIt3ExecuteScript PartOfMyScript.au3")

Now you will have to pass the required variables to PartOfMyScript.au3.  You can use CmdLine[ ] array to do that...

Share this post


Link to post
Share on other sites

@Nine Some days ago. Jos pointed me on somthing similar. let me find...

 

 

Edited by caramen

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
On 22.01.2019 at 9:27 PM, Nine said:

As @BrewManNH said. I didn't find any other way...

Here how to get the right exe to use :

#pragma compile(AutoItExecuteAllowed, true)

Local $BaseExe = @Compiled ? @ScriptName : @AutoItExe
Run ($BaseExe & " /AutoIt3ExecuteScript PartOfMyScript.au3")

Now you will have to pass the required variables to PartOfMyScript.au3.  You can use CmdLine[ ] array to do that...

Great, that's what I was looking for :)
CmdLine also work fine.

Nine  BrewManNH

Thanks for help.

Share this post


Link to post
Share on other sites
19 hours ago, blantek212 said:

CmdLine also work fine.

The only limitation of passing the values via the commandline would be that there's no easy way to pass back the results, if those values get changed in the external script. Probably not an issue in this case because the values don't change, but for anyone else looking at this in the future, it's a point to remember.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...