Storing String for Array in a .ini file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fenchai
Posts: 292
Joined: 28 Mar 2016, 07:57

Storing String for Array in a .ini file

22 Apr 2019, 23:08

I am trying to implement a Combobox that shows the last 15 or N amount of results which are stored on a .ini file.
But I am now trying to figure out how I would do something like if already have 15 items, then pop item 1 and store last item to item 15. Hopefully, this is understandable.

OR if there is a better way to do this. I am all open to suggestions.
  • - Entry of data must be from an Enter or NumpadEnter Hotkey.
  • - Must be with Combobox
This is the script I have been playing around with. It works just fine BUT it does not stop at 15... I need it to keep recycling when it reaches 15 items...

Code: Select all

#NoEnv
#SingleInstance Force
#Persistent
SetWorkingDir %A_ScriptDir%
SendMode, Input

q::
IniRead, tempVar,save.ini,Values,ItemList
MyArray := StrSplit(tempVar,"|")
Gui, Destroy
Gui, -ToolWindow -SysMenu -Caption AlwaysOnTop
Gui, Add, Combobox, y20 vVar, % tempVar
GuiControl, Text, Var, % MyArray[MyArray.MaxIndex()]
Gui, Show, AutoSize, Test
return

GuiEscape:
Gui, Destroy
return

#IfWinActive, Test

Enter::
NumpadEnter::
Gui, Submit
if (tempVar = "") {
    IniWrite, % Var,save.ini,Values,ItemList
    return
}
If (InStr(tempVar,"|")) {
    IniWrite, % tempVar "|" Var,save.ini,Values,ItemList
} else {
    IniWrite, % tempVar "|" Var,save.ini,Values,ItemList
}
return
Thanks for reading :)
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Storing String for Array in a .ini file

23 Apr 2019, 01:30

You're reading the values from tempVar into an array, which is good, but then you're not really operating on the array and, when you write to the INI, you're writing with tempVar. I think that you should use array functions like MyArray.Push() to MyArray.Pop() to add and remove elements from the array, check the length with MyArray.MaxIndex() and, then, when you're ready to write to the INI file, use a For loop with the array in order to rebuild the pipe-separated string.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Storing String for Array in a .ini file

23 Apr 2019, 02:21

This is what I had in mind:

Code: Select all

#NoEnv
#SingleInstance Force
#Persistent
SetWorkingDir %A_ScriptDir%
SendMode, Input

IniRead, tempVar,save.ini,Values,ItemList
MyArray := StrSplit(tempVar,"|")

q::
Gui, Destroy
Gui, -ToolWindow -SysMenu -Caption AlwaysOnTop
Gui, Add, Combobox, y20 vVar, % tempVar
Gui, Show, AutoSize, Test
return

GuiEscape:
Gui, Destroy
return

#IfWinActive, Test

Enter::
NumpadEnter::
Gui, Submit
MyArray.Push(Var)
If(MyArray.MaxIndex() > 15)
    MyArray.RemoveAt(1)
newVar := ""
For index, element in MyArray
    newVar .= element "|"
IniWrite, %newVar%, save.ini, Values, ItemList
return
fenchai
Posts: 292
Joined: 28 Mar 2016, 07:57

Re: Storing String for Array in a .ini file

23 Apr 2019, 09:51

Osprey wrote:
23 Apr 2019, 02:21
This is what I had in mind:

Code: Select all

#NoEnv
#SingleInstance Force
#Persistent
SetWorkingDir %A_ScriptDir%
SendMode, Input

IniRead, tempVar,save.ini,Values,ItemList
MyArray := StrSplit(tempVar,"|")

q::
Gui, Destroy
Gui, -ToolWindow -SysMenu -Caption AlwaysOnTop
Gui, Add, Combobox, y20 vVar, % tempVar
Gui, Show, AutoSize, Test
return

GuiEscape:
Gui, Destroy
return

#IfWinActive, Test

Enter::
NumpadEnter::
Gui, Submit
MyArray.Push(Var)
If(MyArray.MaxIndex() > 15)
    MyArray.RemoveAt(1)
newVar := ""
For index, element in MyArray
    newVar .= element "|"
IniWrite, %newVar%, save.ini, Values, ItemList
return
I see what you did. That looks great! It gets to the point. But there is a small problem. When you Iniwrite the values, you add "|" at the end of the string. This causes an Error if var is empty at start. Also It eliminates the possibility of using array.maxindex because the last element is empty. Why not make it to be "|" + element?
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Storing String for Array in a .ini file  Topic is solved

23 Apr 2019, 11:43

Code: Select all

newVar .= (newvar ? "|" : "") element
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
fenchai
Posts: 292
Joined: 28 Mar 2016, 07:57

Re: Storing String for Array in a .ini file

23 Apr 2019, 12:34

thank you both :) that did it

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput and 330 guests