I'm looking to create an array of file names and their modified time. I can build the arrays separately. But how can I build this in a way to be like
[ [file1, modtime1], [file2, modtime2], ...]
Here is the script that builds each individual array.
modTime := []
filenames := []
counter := 1
Full_Path := "C:\Users\me\MyDocs\*.txt"
Loop, %
{
modTime[counter]:=A_LoopFileTimeModified
filenames[counter]:=A_LoopFileFullPath
counter++
}
loop % modTime.MaxIndex()
items.= modTime[A_Index] ","
StringLeft, items, items, Strlen(items)-1
msgbox % items
loop % filenames.MaxIndex()
items.= filenames[A_Index] ","
StringLeft, items, items, Strlen(items)-1
msgbox % items
return
modTime := []
counter := 1
Full_Path = % "C:\Users\me\MyDocs\*.txt"
Loop, % Full_Path
{
SplitPath, % A_LoopFileFullPath, file_name
modTime.Push([file_name, A_LoopFileTimeModified])
counter++
}
For each, element in modTime
items .= element[1] ", " element[2] "`n"
MsgBox, % RTrim(items, "`n")
Related
At the moment I am working on AI in AHK.
Now I have the problem that I don't know how to deal with a matrix. See below an example matrix:
WeightLooper := 1
Loop %NumberOfWeightsLayerTotal%
{
Random, Weight_%WeightLooper%, -1.0, 1.0
WeightLooper := WeightLooper + 1
}
WEIGHTS_1 := Array([Weight_1, Weight_2, Weight_3, Weight_4], [Weight_5, Weight_6, Weight_7, Weight_8], [Weight_9, Weight_10, Weight_11, Weight_12])
TRAINING_INPUTS := []
rows := (LastFilledY - 1)
columns := (LastFilledX - 1)
Xas := 0
Yas := 0
Loop, % rows
{
Xas := 0
Yas := Yas + 1
row := []
Loop, % columns
{
Xas := Xas + 1
row.push(myarray[Yas][Xas])
}
TRAINING_INPUTS.push(row)
}
Now I have a matrix of 3x4. Suppose I want a matrix of 10x10, how do I do that? So basically I want to create a variable matrix.
I ask this because my input (csv file) can vary from 2x2 to 1000000x1000000.
I'd probably recommend pushing a new array into the array in a loop:
WEIGHTS_1 := []
rows := 5
columns := 7
Loop, % rows
{
row := []
Loop, % columns
{
Random, weight, -1.0, 1.0
row.push(weight)
}
WEIGHTS_1.push(row)
}
Example output:
[[-0.678368, -0.768605, -0.274922, 0.049760, -0.133968, -0.876030, -0.235799]
,[-0.296078, 0.359816, -0.461632, 0.788800, -0.707147, -0.200223, -0.473914]
,[0.474090, 0.085090, 0.458321, -0.820574, 0.145089, 0.193249, 0.990545]
,[0.205461, 0.901953, -0.137901, 0.279726, 0.562361, -0.019861, -0.887540]
,[0.504811, -0.876628, -0.127397, 0.156817, 0.873983, 0.859992, -0.879222]]
I have an array [1, 2, 56, 32, 54] or something.
How do i send it to clipboard
1
2
56
32
54
I tried this.
Loop % table.MaxIndex() {
meow := table[A_Index]
Clipboard := meow"`r"
}
table := [1,2,3,4,5,6,7,8,9]
vClipboard := ClipboardAll
Clipboard := ""
Loop, % table.Count()
string := string ? string . ", " . table[A_Index] : table[A_Index]
Clipboard := string
;Do some stuff.
Clipboard := vClipboard ;Restore the Clipboard.
Your problem was trying to loop with table.MaxIndex() which will potentially give you an unexpected amount since you can have an array with 2 values but very far apart in terms of Index i.e.
table := [1]
table[93] := "String"
and also each loop was overwriting your meow value. The method you want to use is concatenate i.e.
meow := "Hello"
meow := meow . "World" or meow .= "World"
I have a script with a list of words inside. I want to create a gui that opens up and allows users to enter words to the list and remove them aswell. Is it possible for the script to edit itself while running? If so, how would I go about doing this. Here is my current script.
Word1 = This
Word2 = Is
Word3 = A
Word4 = Test
Word5 = Script
Word6 = And
Word7 = I
Word8 = Like
Word9 = Apple
Word10 = Pie
Min := 1
Max := 10
Gui, New
Gui, Add, Text,, Please enter a word you wish to add:
Gui, Add, Edit, Word
Gui, Show
MButton::
RandWords := ""
loop,
{
Random N, %Min%, %Max%
if( Last != N )
{
Last := N
break
}
}
RandWords .= Word%N%
Send %RandWords%{!} {enter}
Return
Here is an example how to use arrays to store user input:
store :=
counter := 0
loop, 3
{
InputBox , here , User input , Please enter some text!
store%counter% := here
counter++
}
store1 = This element was deleted!
counter := 0
loop, 3
{
str := store%counter%
MsgBox, %str%
counter++
}
As you can see, store is used as a pseudo array, and is indexed using counter, or integer values.
There is a line that deletes (actually just changes, but you get the idea) the second element. It could have been written like this:
counter := 1
store%counter% = This element was deleted!
Having an issue when attempting to run a Mod formula against a field. I keep receiving the error "String is Not Numeric" and so far I have not been able to get ToNumber to correctly format the field. The field is being generated by adding a static value and three fields that have been padded. Any help would be appreciated.
Combines fields and pads
StringVar strMICR;
StringVar strMICRLINE;
strMICRLINE := Chr(13) & "0603250694";
strMICRLINE := strMICRLINE & Right("000000" & Trim(Split({CUST.C_ID_ALPHA},"-")[1]),6);
strMICRLINE := strMICRLINE & Right("00000000" & ToText({STMT.STMT_NUMBER},0,""),8);
strMICRLINE := strMICRLINE & Right("0000000000" & Replace(ToText({#Total},2,""),".",""),10);
//Uncomment below to test Mod10 Check-digit
//strMICR := mod10("0603250694084469108961440000127874");
//IF NumericText (strMICRLINE)
//THEN ToNumber (strMICRLINE);
Mod10 (strMICRLINE);
MOD10 Function
Function (StringVar input_number)
input_number := replace(input_number, " ", "");
numbervar i := length(input_number);
numbervar sum_val := 0;
stringvar position := "odd";
do (
if position = "odd" then (
sum_val := sum_val + 3*tonumber(input_number[i]);
position := "even" )
else (
sum_val := sum_val + tonumber(input_number[i]);
position := "odd" )
;
i := i-1
) while i > 0;
numbervar remainder_val := Remainder(sum_val, 10);
numbervar check_digit := if remainder_val = 0 then 0 else (10-remainder_val) ;
input_number + ToText(check_digit, 0)
You're attempting to call toNumber() on a string that is not numeric and therefore can't be converted. You need to strip all non-numeric characters out of your string first.
//Formula sample to strip non-numeric characters
local stringvar input := "78906-adf0asdf-234";
local stringvar output;
local numbervar i;
for i:=1 to length(input) do
if numerictext(input[i]) then output:=output&input[i];
output
Then I would highly suggest you use the built in mod function instead of rolling your own.
toNumber({#NumericTextOnly}) mod 10
I am trying to capture the value in <span class="latlon"></span> at http://nominatim.openstreetmap.org/search.php?q=MK3+5JE&viewbox=-147.13%2C72.78%2C147.13%2C-55.67:
For example 51.99,-0.76 in this case:
But whenever I run my AHK script this is the output:
Why does it not read the value in the latlon field?
This is my code so far:
Loop, read, test.csv
{
Loop, parse, A_LoopReadLine, %A_Tab%
{
; Run IE
IE := ComObjCreate("InternetExplorer.Application")
IE.Visible:=True
; Copy current postcode row to clipboard
Clipboard = %A_LoopField%
Postcode = %A_LoopField%
ClipWait
; Debugging - wait 1s then check output
; Sleep 1000
; MsgBox, %Clipboard%
; Navigate to Bing Maps and paste the postcode
IE.Navigate("http://nominatim.openstreetmap.org/")
Sleep 300
Send, ^v
Send {Enter}
; Debugging - wait 1s then check output
; Sleep 1000
; IE.Navigate("javascript: alert(document.getElementsByClassName('name')[0].innerHTML)")
; IE.Navigate("javascript: alert(document.getElementsByClassName('latlon')[0].innerHTML)")
; Collect results
j := 0
i := 1
Addr := {}
while (i <= 1)
{
Sleep 1000
Addr[i] := IE.document.getElementsByClassName("name")[j].innertext
LatLon[i] := IE.document.getElementsByClassName("latlon")[j].innertext
Addr_Object := StrSplit(Addr[i], "`,")
LatLon_Object := StrSplit(LatLon[i], "`,")
If (Substr(Addr[i], 1, 2) = "MK")
{
Addr[i] := Addr_Object[2] . "," . Trim(Addr_Object[3]) . "," . PostCode . "," . LatLon_Object[1] . "," . LatLon_Object[2]
MsgBox, % Addr[i]
}
Else
{
Addr[i] := Addr_Object[1] . "," . Trim(Addr_Object[2]) . "," . PostCode . "," . LatLon_Object[1] . "," . LatLon_Object[2]
MsgBox, % Addr[i]
}
j++
i++
}
; Close IE
IE.quit()
}
}
Content of test.csv:
MK3 5JE
MK1 1AS
Would appreciate any pointers in the right direction.
I think you've got to be a bit more precise... Well, it doesn't hurt to be...
document.getElementById("searchresults").getElementsByClassName("result")[0].getElementsByClassName("latlon")[0].innerHTML
Here's an example:
You can change to loop though all of the results, but in this example, only the first result is retrieved.
SetWorkingDir, %A_scriptdir%
FileRead,data,test.csv
data := StrSplit(data,"`r`n",A_Tab)
Gui Add, ActiveX, xm w640 h480 vWB, Shell.Explorer
ComObjConnect(WB, WB_events) ; Connect WB's events to the WB_events class object.
Gui Show
WB.silent := true ;Surpress JS Error boxes
ProcessDone:=0 ; "Universal" signal
for each, item in data
{
ToolTip Loading...`nPlease wait...
PostCode:=item
WB.Navigate("http://nominatim.openstreetmap.org/search.php?q=" item) ;search it
while (!ProcessDone) {
;wait
}
ProcessDone:=0
}
return
class WB_events
{
DocumentComplete(wb, NewURL)
{
global ProcessDone
global PostCode
while (StrLen(wb.document.getElementById("searchresults").innerHTML)==0) {
;wait
}
/* Information nested as:
#searchresults
.result
.latlon
*/
numResult := wb.document.getElementById("searchresults").getElementsByClassName("result").length
addr := wb.document.getElementById("searchresults").getElementsByClassName("result")[0].getElementsByClassName("name")[0].innerHTML
coords := wb.document.getElementById("searchresults").getElementsByClassName("result")[0].getElementsByClassName("latlon")[0].innerHTML
ToolTip
MsgBox,,OpenStreenMap - First result,Address:`t%addr%`nPostal code:`t%PostCode%`nCoordinates:`t%coords%`nNumber of results:`t%numResult%`nURL: %NewURL%
ProcessDone:=1
}
}
GuiClose:
ExitApp