Jump to content

Recommended Posts

Posted

There is data a pair of string and number. This is array1: [string, number]. Could be many string-number, so I use array2: [[string, number], [string, number]...]. Could be many array2, so I created array3 [[[string, number], [string, number]]]. So, right now I have an array size [1][2][2]

 

Local $aArmySet = [[["spy", 1], ["light", 10]], [[1, 1],[1, 1]]] ; I need make it better look
; [[1, 1],[1, 1]] is dummy, I don't need this, but there is error without it. 
; I need to fix that all to work with arrays like [[["spy", 1], ["light", 10]], [["spy", 1], ["light", 10], ["warrior", 5]]]
; array1 always string and number (2 elements)
; array2 includes all array1 and has from 1 to 20 elements
; array3 includees all array2 and has from 1 to unkwnown elements

$setSelector = 0 ; select which element of array I need (I need [["spy", 1], ["light", 10]])

; Script dies below
;MsgBox(0, 'Checking', $setSelector)
   ;$aArmySetCurrent = [$aArmySet[$setSelector]]
   myFunction1 ($aArmySet, $setSelector, $oIE) ; функция заполняет нужные поля
   
func myFunction1 ($aArmySet, $selector, $oIE)
   For $i = 0 To UBound($aArmySet[$selector]) - 1 ; I need calc size for [["spy", 1], ["light", 10]]
      $oInput =_IEGetObjByName($oIE, $aArmySet[$selector][$i][0])
      _IEFormElementSetValue ($oInput, $aArmySet[$selector][$i][1])
   Next
EndFunc

 

Posted

You're mixing up array dimensions.

  On 3/4/2019 at 11:22 AM, AbsorbeR said:

So, right now I have an array size [1][2][2]

Expand  

No, it's [2][2].

To access string of row 0, you do [0][0] which is "spy".
To access value of row 1, you do [1],[1] which is 10.

I recommend you study the help file again.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted
  On 3/4/2019 at 6:10 PM, jchd said:

You're mixing up array dimensions.

No, it's [2][2].

To access string of row 0, you do [0][0] which is "spy".
To access value of row 1, you do [1],[1] which is 10.

I recommend you study the help file again.

Expand  

It's only looks like [2][2], but it's pattern for future. More about task:

1. There is some units: units1, units2, units3 ... unitsN. I use it to detect right input.

2. All units have a quantity to fill: 1 to 24000

3. So, there is pattern with "units, quantity" set

3. Could be various patterns to fill.

Example:

pattern1: unit3, 10; unit6, 5; unit4, 100;

pattern2: unit1, 11; unit3, 101;

pattern3...

So, I think I need 3D array. Do I need it really?

 

Posted
$pattern1 = [[unit1, 5], [unit2, 10]]
$pattern2 = [[unit2, 6], [unit4, 9], [unit5, 11]]
$patternSet = [$pattern1, $pattern2]

I tried a code above.

Posted
  On 3/4/2019 at 7:01 PM, Nine said:

In fact it is closer to a [1][4][2] but should be declare as follow :

Local $aArmySet = [[["spy", 1], ["light", 10], [1, 1],[1, 1]]]

 

Expand  

I don't need  [[1, 1],[1, 1]]. I added it to script didn't report error. While I need how to type $aArmySet =  [[["spy", 1], ["light", 10]]] as 3D array. Tricks didn't work that I tried.

Posted

Things are clearer then. Yes your data seems to be 3D-like-structured. How to organize thing now depends on how you'll be searching for data. More precisely: what will be your search/access criterion?

Also if the various patterns have a variable number of entries, then your code above (array of patterns) may be workable. The drawback is that AutoIt doesn't facilitate direct access in this case.

Last point: if you ever have to store and manage a large volume of such data persistantly, then a database structure will reveal much simpler to work with (e.g. SQlite).

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)
  On 3/4/2019 at 7:08 PM, AbsorbeR said:

I added it to script didn't report error

Expand  

Ya sometimes running from scite does strange thing.  But If you run it from Explorer you will get the error. Anyway, it is not clear what you are trying to do.  Maybe post something more substantial...

Btw, it is a good idea to explicitly declare an array with all its dimensions, you will catch some errors like that.

Edit : my bad I was running your code with explicit declaration as a [1][2][2], and got the error.  In fact your initial declaration is a [2][2][2].  One reason more to declare with explicit dimensions :)

Edited by Nine
Posted
Const $iPatterns = 1
Local $aArmySet[$iPatterns][2][2] = [[["spy", 1], ["light", 10]]]

It works.

 

  On 3/4/2019 at 7:15 PM, Nine said:

Ya sometimes running from scite does strange thing.  But If you run it from Explorer you will get the error. Anyway, it is not clear what you are trying to do.  Maybe post something more substantial...

Btw, it is a good idea to explicitly declare an array with all its dimensions, you will catch some errors like that. 

Expand  

Yeah, good idea, but flexibility decreases.

All code where I use these arrays in the first post. Well, declaration is finished. No, how to send subarray? I want to call function without $setSelector. I tried $aArmySet[1]. How modify this string or should I add something before?

myFunction1 ($aArmySet, $oIE);

 

Posted
  On 3/4/2019 at 7:33 PM, AbsorbeR said:

Yeah, good idea, but flexibility decreases.

Expand  

I disagree but you will find it sooner or later.

  On 3/4/2019 at 7:33 PM, AbsorbeR said:

I want to call function without $setSelector.

Expand  

In that case you will need to create an array of arrays then passing $aArmySet[1] as a parameter would be allowed.

ps.  when passing arrays as parameter of a function, it is a good idea to declare it ByRef.  Autoit won't have to make a copy of the array (saves space and time especially when the array gets big).

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...