INI File Helper

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

INI File Helper

12 Jul 2017, 00:58

I think some newish people to AHK could use this tool to help write their scripts.
So, some of these new people (Or lazy coders, I'm not judging.) might want to use this.
So here it is!
The INI File Helper!

Here's the code. Make sure to keep the whole code for it to work!

Code: Select all

/*
      /=========|
     /          |
    /  HH   HH  |
    |  HH   HH  |
    |  HHHHHHH  |
    |  HH   HH  |
    |  HH   HH  |
    |           |
    |===========|

	AutoHotkey Version:				1.1.26.00
	Language:						English
	Platform:						Win XP, Win 7, Win 8.1, Win 10
	Author:							Delta
	Contact information:			[email protected]

	|=======================================================|
	|	Hotkeys:											|
	|		None											|
	|=======================================================|
*/

#NoEnv
#SingleInstance Force
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
#NoTrayIcon
; #Include <Notify>		; Personal Library, unneeded here.
Process, Priority,, H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode, Input
Menu, Tray, Icon, %A_AHKPath%, 2
; Even though NoTrayIcon is set,
; it still sets the Gui's Icon to be the white file with the capital H

Gui, INI: -MinimizeBox
Gui, INI:Add, Tab3, x0 y0 w470 h330 +0x2, Write|Read

Gui, INI:Tab, Write, 1
Gui, INI:Font,, Segoe UI
Gui, INI:Add, GroupBox, x10 y15 w435 h50, The Text or Variable to Write [Be sure to add the `% signs acordingly!]
Gui, INI:Add, Edit, x20 y35 w415 h20 vOutA, `%Var`%
Gui, INI:Add, GroupBox, x10 y70 w435 h50, The File to Write in
Gui, INI:Add, Edit, x20 y90 w330 h20 vFileA, %A_Desktop%\Config.ini
Gui, INI:Add, Button, x360 y90 w75 h23 vFileSelectA gSelectA, Select File
Gui, INI:Add, GroupBox, x10 y125 w435 h50, The Category to Write in
Gui, INI:Add, Edit, x20 y145 w415 h20 vCatA, Settings
Gui, INI:Add, GroupBox, x10 y180 w435 h50, The Key to Write to
Gui, INI:Add, Edit, x20 y200 w415 h20 vKeyA, KeyA
Gui, INI:Add, Button, x375 y275 w70 h25 gUpdate, Update
Gui, INI:Font,, Consolas
Gui, INI:Add, Edit, x15 y250 w430 h20 vUPWrite ReadOnly

Gui, INI:Tab, Read, 1
Gui, INI:Font,, Segoe UI
Gui, INI:Add, GroupBox, x10 y15 w435 h50, The Text or Variable to Read [There's no need for the `% signs here.]
Gui, INI:Add, Edit, x20 y35 w415 h20 vOutB, Var
Gui, INI:Add, GroupBox, x10 y70 w435 h50, The File to Read From
Gui, INI:Add, Edit, x20 y90 w330 h20 vFileB, %A_Desktop%\Config.ini
Gui, INI:Add, Button, x360 y90 w75 h23 vFileSelectB gSelectB, Select File
Gui, INI:Add, GroupBox, x10 y125 w435 h50, The Category to Read From
Gui, INI:Add, DDL, x20 y145 w415 h200 vCatB, Settings||
Gui, INI:Add, GroupBox, x10 y180 w435 h50, The Key to Read From
Gui, INI:Add, Edit, x20 y200 w415 h20 vKeyB, KeyA
Gui, INI:Add, Button, x375 y275 w70 h25 gUpdate, Update
Gui, INI:Font,, Consolas
Gui, INI:Add, Edit, x15 y250 w430 h20 vUPRead ReadOnly
Gui, INI:Show, w465 h335, INI File Helper
GoSub, Update
Return

Update:
Gui, INI:Submit, NoHide
GuiControl INI:, UPWrite, % "IniWrite, " OutA ", " FileA ", " CatA ", " KeyA
GuiControl INI:, UPRead , % "IniRead, "  OutB ", " FileB ", " CatB ", " KeyB
Return

SelectA:
FileSelectFile, FileA, 8, %A_Desktop%\, Please Create an INI File to Use., Configuration Files (*.ini)
GuiControl, INI:, FileA, % FileA
Return

SelectB:
FileSelectFile, FileB, 8, %A_Desktop%\, Please Create an INI File to Use., Configuration Files (*.ini)
SplitPath, % FileB,,, OutExtension
If (ErrorLevel or (OutExtension != "ini"))
	Return
GuiControl, INI:,FileB, % FileB
IniRead, OutputVarSectionNames, % FileB ; retrieves a linefeed (`n) delimited list of section names
GuiControl, INI:,CatB, % "|" StrReplace(OutputVarSectionNames, "`n", "|") ; fill the drop down list with the section names of the selected ini file
GuiControl, INI:Choose, CatB, 1
Return

Close:
INIGuiClose:
ExitApp
Return
I also added a little AHK Icon for you to enjoy ;)
Last edited by Delta Pythagorean on 13 Jul 2017, 22:15, edited 1 time in total.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
metacognition
Posts: 117
Joined: 22 Oct 2014, 05:57
Location: Alaska
Contact:

Re: INI File Helper

12 Jul 2017, 02:12

Nice icon :)
User avatar
metacognition
Posts: 117
Joined: 22 Oct 2014, 05:57
Location: Alaska
Contact:

Re: INI File Helper

12 Jul 2017, 02:16

Dang, this will come in handy!
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: INI File Helper

12 Jul 2017, 20:19

One suggestion among others possible:

You could make the catB edit control to be a dropdownlist:

Code: Select all

Gui, INI:Add, DropDownList, x20 y145 w415 vCatB,
since you can retrieve a linefeed (`n) delimited list of section names, once an ini file is choosen:

Code: Select all

SelectB:
FileSelectFile, FileB, 8, %A_Desktop%\, Please Create an INI File to Use., Configuration Files (*.ini)
SplitPath, % FileB,,, OutExtension
if (ErrorLevel or (OutExtension <> "ini"))
return
GuiControl, INI:, FileB, % FileB
IniRead, OutputVarSectionNames, % FileB ; retrieves a linefeed (`n) delimited list of section names
GuiControl, INI:, CatB, % "|" . StrReplace(OutputVarSectionNames, "`n", "|") ; fill the drop down list with the section names of the selected ini file
GuiControl, INI:Choose, CatB, 1
Return
my scripts
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: INI File Helper

12 Jul 2017, 21:23

The original was able to handle drag-n-drop onto the script's file icon - I like that better than using the file-browser dialogue.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: INI File Helper

13 Jul 2017, 22:14

A_AhkUser wrote: One suggestion among others possible:
Alright, I just added it to the original code for download.
Thanks for the suggestion!

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: INI File Helper

14 Jul 2017, 09:30

I just noticed running your updated script that, however, this way, it doesn't update the UPRead edit control. Actually, this can be solved by, for example, associating the dropdownlist with the update label as well:

Code: Select all

Gui, INI:Add, DDL, x20 y145 w415 h200 vCatB gUpdate, Settings||
and by making the param3 parameter of the GuiControl, Choose sub-command actually trigger the g-label associated, using the pipe character:

Code: Select all

SelectB:
; ...
GuiControl, INI:Choose, CatB, |1
Return
my scripts
joefiesta
Posts: 494
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: INI File Helper

17 Feb 2018, 10:44

what does this code do? Would you expect me to read the source code for Windows to learn how Windows works?

After having written code for over 40 years, I've learned the value of documenting what I write--even when it is only for myself.
Especially when that 40 year old code still works perfectly fine!
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: INI File Helper

23 Feb 2018, 00:27

joefiesta wrote:what does this code do? Would you expect me to read the source code for Windows to learn how Windows works?

After having written code for over 40 years, I've learned the value of documenting what I write--even when it is only for myself.
Especially when that 40 year old code still works perfectly fine!
I strongly dislike to use comments in my code unless it is to "remove" something from my code, or for a temporary "balance" in my code.
If I ever do add comments to my code, most likely it's for some complicated class/function that needs a bit of explaining to do.

If anything, with 40+ years of coding experience, you should know to read into the code itself and see what commands does what and why the programmer chose the parameters that they did.

This code was meant for the newer people that just simply need a bit of help with some daily commands to use. I personally don't need it as for I use JSON (I prefer not to use XML as for the large file sizes) to do my saving and reading when it comes to user set variables/"save for later" variables.

TL;DR:
I really don't understand what all the fuss is all about, I'm simply allowing users to use my code for which I have made. If they want to look into the source code, they may want to see how it works, but AHK already allows to see what commands are being executed, line by line, using this command: ListLines.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: INI File Helper

23 Feb 2018, 00:43

I think Joe's point might rather be that your original post doesn't state what your script actually does. A "helper" can be a lot of things. At least, this is what I thought when I first read this thread. Is it a library, a class, functions, a GUI of some kind, can I read and/or write ini files? What are the features?

I still don't know what your script does, partly because I don't feel a personal need for a "helper". But I might be wrong - a INI library would be useful, even if there are already others.
I would probably be able to understand the script by reading the source code - but then again, a beginner might not be. Therefore, I would welcome a little description of the actual goal of this script and what it does - because it could make this forum better.

edited
User avatar
kunkel321
Posts: 974
Joined: 30 Nov 2015, 21:19

Re: INI File Helper

24 Feb 2018, 19:00

Cool thanks! I will likely use this!
ste(phen|ve) kunkel
shipaddicted
Posts: 89
Joined: 15 Jul 2016, 19:57

Re: INI File Helper

30 Dec 2019, 20:56

I have to agree with joefiesta. I understand that you don't like to "comment" your code. I don't either. I like it to look as clean as possible -- often to my own detriment. I'll go back and look at it again months later to edit, and I have to literally study it to figure out WTH I was thinking when I wrote it!

You said yourself you are sharing this code in order to help newer people who might like the assistance in writing their own code. As such, you should understand that we all don't have 40 years of code-writing under our belts and can't see at a glance what your script was trying to accomplish or how it might be helpful to us. And the fact that we don't know what it is or does could also be a roadblock to downloading it and giving it a try. (I love and use daily CodeQuickTester, so it's not a huge deal to just cut and paste and see what happens, but newbies who haven't learned of this awesome little app may not know how to quickly take a random script for a test drive.)

If you don't like to comment your code, consider piggybacking a .txt file or a subsection in the code, separate from the code itself, that explains what it does and/or ideas for how to use it.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: INI File Helper

30 Dec 2019, 22:33

shipaddicted wrote:
30 Dec 2019, 20:56
I have to agree with joefiesta. I understand that you don't like to "comment" your code. I don't either. I like it to look as clean as possible -- often to my own detriment. I'll go back and look at it again months later to edit, and I have to literally study it to figure out WTH I was thinking when I wrote it!

You said yourself you are sharing this code in order to help newer people who might like the assistance in writing their own code. As such, you should understand that we all don't have 40 years of code-writing under our belts and can't see at a glance what your script was trying to accomplish or how it might be helpful to us. And the fact that we don't know what it is or does could also be a roadblock to downloading it and giving it a try. (I love and use daily CodeQuickTester, so it's not a huge deal to just cut and paste and see what happens, but newbies who haven't learned of this awesome little app may not know how to quickly take a random script for a test drive.)

If you don't like to comment your code, consider piggybacking a .txt file or a subsection in the code, separate from the code itself, that explains what it does and/or ideas for how to use it.
A. This is a year old thread.
B. I don't comment my code unless it's not self explanatory.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

shipaddicted
Posts: 89
Joined: 15 Jul 2016, 19:57

Re: INI File Helper

31 Dec 2019, 17:38

Thanks for the calendar update. However, as I was searching for INI related topics, yours came up. I responded. It doesn't make my opinion any less valid just because of the age of the thread.

Again, your code may NOT be self explanatory to a newbie. I was merely suggesting if you wanted to be helpful, be helpful.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gwarble, peter_ahk and 121 guests