TheAutomator

easy question about arrays

11 posts in this topic

#1 ·  Posted (edited)

Hi people,

It's been a while :)
I have been scripting in vbscript for some time but now i'm back using AutoIt for a project:

Scripting Adobe Illustrator with AutoIt .
This vb code needs to be converted:

Set appRef = CreateObject("Illustrator.Application")
'Create a new document and assign it to a variable
Set documentRef = appRef.Documents.Add
'Create a new text frame item and assign it to a variable
Set sampleText = documentRef.TextFrames.Add
'Set the contents and position of the TextFrame
sampleText.Position = Array(200, 200)
sampleText.Contents = "Hello World!"

The ... = Array(200,200) part is done in one line in vb, is this possible in AutoIt without declaring an array first?
I know I sound like a newbie but I never had to use arrays this way before..

what i have:

$appRef = ObjCreate("Illustrator.Application")
;Create a new document and assign it to a variable
$documentRef = $appRef.Documents.Add
;Create a new text frame item and assign it to a variable
$sampleText = $documentRef.TextFrames.Add
;Set the contents and position of the TextFrame
ReDim $sampleText.Position[2] = [200, 200] <<<--- doesn't work...
$sampleText.Contents = "Hello World!"

 

Edited by TheAutomator

Share this post


Link to post
Share on other sites



maybe you could "simulate" the VB behaviuor for "Array()" by using a simple function to return a 2 elements array....

$appRef = ObjCreate("Illustrator.Application")
;Create a new document and assign it to a variable
$documentRef = $appRef.Documents.Add
;Create a new text frame item and assign it to a variable
$sampleText = $documentRef.TextFrames.Add
;Set the contents and position of the TextFrame
$sampleText.Position = Array(200, 200)
$sampleText.Contents = "Hello World!"

Func Array($iX, $iY) ; returns a 2 element 1d array
    Local $aArray[2] = [$iX, $iY]
    Return $aArray
EndFunc   ;==>Array

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
7 minutes ago, Chimp said:

maybe you could "simulate" the VB behaviuor for "Array()" by using a simple function to return a 2 elements array....

$appRef = ObjCreate("Illustrator.Application")
;Create a new document and assign it to a variable
$documentRef = $appRef.Documents.Add
;Create a new text frame item and assign it to a variable
$sampleText = $documentRef.TextFrames.Add
;Set the contents and position of the TextFrame
$sampleText.Position = Array(200, 200)
$sampleText.Contents = "Hello World!"

Func Array($iX, $iY) ; returns a 2 element 1d array
    Local $aArray[2] = [$iX, $iY]
    Return $aArray
EndFunc   ;==>Array

 

Yes, I thought about that to.. but I first wanted to know if there wasn't a more direct way.
I suppose that's a no for direct array declaring in AutoIt then? :)

Thanks for the reply btw :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

11 minutes ago, TheAutomator said:

I suppose that's a no for direct array declaring in AutoIt then?

Correct in relation to your syntax, although using StringSplit() should also work here - however this is still calling a function.

Edited by czardas

Share this post


Link to post
Share on other sites

good point,

so you could use for example something like this;

$sampleText.Position = StringSplit('200,200', ',', 3)

p.s. ( little hijacking) )

@czardas,

Since also the StringRegExp function can return an array, what pattern can be used to have an array from a comma delimited list? .....thanks


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Hello. knowing that we're going to use number also we could use

_ArrayDisplay(StringRegExp("200,200", '\d+', 3))

Of course for this Chimp's  suggestion is the correct/clean way to use.

Saludos

Share this post


Link to post
Share on other sites
5 minutes ago, czardas said:

I think I know this. :)

never doubted ...... lol :D

@Danyfirex .... thanks :)

 

p.s.

:think: is there any 'regexp' guru that could came out with an an esotheric pattern to get a multidimensional array as well..... :blink:

1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
2 hours ago, Chimp said:

never doubted

Well as long as there are no missing items in the list, the regexp is fine. :whisper:

Share this post


Link to post
Share on other sites

redim $sample.text.position[200][200]

arrays are [x][y] not [x,y]

Just my humble 2 cents

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

  • Similar Content

    • NiftRex
      By NiftRex
      I'm trying to get an array from a website so that I can just get the url, but I am not sure how. I read a bit of arrays but I have a feeling I'd have to be writing a lot more than what I should be. I will include the script I have so far and the API url for what I want.
       
      API: https://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1 (I want the 'url' array that contains the url)
       
      Code:
      #include <MsgBoxConstants.au3> #include <Inet.au3> #include <Array.au3> $site = _INetGetSource('http://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1') MsgBox($MB_SYSTEMMODAL, "Title", $site[1])  
    • rcmaehl
      By rcmaehl
      Alright, currently I'm trying to merge two loops:
       
      Local $aArray[99][13] For $iLoop = 1 to 100 $aArray[$iLoop - 1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop) If @error <> 0 Then ReDim $aArray[$iLoop - 1][13] ExitLoop EndIf Next For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 1 to 12 $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop Next Next  
      into one. Here's what I have so far:
       
      Local $aArray[99][13] For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 0 to 12 ConsoleWrite("Loop1 = " & $iLoop1 & ", Loop2 = " & $iLoop2 & @CRLF) If $iLoop2 = 0 Then $aArray[$iLoop1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop1 + 1) If @error <> 0 Then ReDim $aArray[$iLoop1 + 1][13] ExitLoop EndIf Else $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop EndIf Next Next And it keeps error-ing out trying to exceed the dimension range of the array. Does the Loop not recheck the size of the array after the original check or am I doing something else wrong.
       
      Thanks.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to use SQLite for managing some data, and, I would like to display my "retrieved" data, but I'm trying to do a select from 2 table, and seems to not work properly...
      What I'd like to do is retrieve data from 2 tables and display in a listview...
      I tried with:
      Local $aRisultato, $iRighe, $iColonne, $iRVal $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell, Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then ;_SQLite_Display2DResult($aRisultato) _ArrayDisplay($aRisultato) EndIf ... but it displays a single record 41 times, and it does this thing for every record in the database...
      What do you need to help me?
      Thanks  

      EDIT:
      Managed with a double If and double query like this:
       
      $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then Local $aRisultatoRockwell = $aRisultato $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then _ArrayConcatenate($aRisultato, $aRisultatoRockwell) Local $i, $sRiga, $s_LV_Item For $i = 1 To Ubound($aRisultato) - 1 $sRiga = $aRisultato[$i][0] & "|" & _ $aRisultato[$i][1] & "|" & _ $aRisultato[$i][2] & "|" & _ $aRisultato[$i][3] & "|" & _ $aRisultato[$i][4] & "|" & _ $aRisultato[$i][5] & "|" & _ $aRisultato[$i][6] & "|" & _ $aRisultato[$i][7] & "|" & _ $aRisultato[$i][8] & "|" & _ $aRisultato[$i][9] & "|" & _ $aRisultato[$i][10] & "|" & _ $aRisultato[$i][11] $s_LV_Item = GUICtrlCreateListViewItem($sRiga, $lv_Lista) Next And so, the listview is created
      If anyone has another more efficient way, I'm here Thanks guys  
       
    • Dent
      By Dent
      I just can't get my head around what I'm trying to do.
      Ok so I read all the links in a webpage into a 1D array, I then make the array unique as there are some duplicates.
      I then find all the entries I want from the array and put the number of the row for those entries into another 1D array.
      So I now have two arrays; one has unique links, the other has the numbers of the rows for the links I actually want.
      Using the second array I would like to amend the first array, or create a third, with just the links I actually want.
      Confused? Welcome to my world.
      I'll put the relevant section of code below to show where I am up to.
      I've left the _ArrayDisplay in the above code which I am using to check the code does what I wanted. So the above code works fine, I'm just stumped on how to extract the links from $aLinks that I want.
      $oLinks = _IELinkGetCollection($oIE) Local $aLinks[1] = ["Link"] For $oLink in $oLinks _ArrayAdd($aLinks, $oLink.href) Next ;_ArrayDisplay($aLinks) $aLinks = _ArrayUnique($aLinks) ;_ArrayDisplay($aLinks) $aLinksToClick = _ArrayFindAll($aLinks, "azref", 0, 0, 0, 3) ;_ArrayDisplay($aLinksToClick) Local $aSortedLinks[1] = ["Sorted Links"] For $i = 0 To UBound($aLinksToClick) - 1 $Blah = _ArrayExtract($aLinks, $aLinksToClick[$i], $aLinksToClick[$i]) _ArrayAdd($aSortedLinks, $Blah) Next  
    • Dent
      By Dent
      I've been searching for a solution on the forum and came across a partial solution in this topic...

      My problem is that I have a 2D array; column one has the description (a string) of the integer in column two. I want to sort this array by the value of column two from highest to lowest. Only my _ArraySort produces a strange result.
      Here is the code and the output before and after...
      Local $PensionsOne = ($MonthlyPensionIncomeOne + $MonthlyPensionCreditIncomeOne) Local $SecondEmploymentOne = ($SecondSalaryOne + $SecondBonusOne + $SecondOvertimeOne + $SecondCommissionOne) Local $aGetHighestFiveAdditionalIncomesForAppOne[8][2] = [ _ ["Occupational pension income", $PensionsOne], _ ["2nd job", $SecondEmploymentOne], _ ["Working Tax Credits", $MonthlyUniversalTaxCreditIncomeOne], _ ["Disability living allowance", $MonthlyStateDisabilityIncomeOne], _ ["Investment or dividend income", $MonthlyInvestmentIncomeOne], _ ["Maintenance", $MonthlyMaintenanceIncomeOne], _ ["Rental income", $MonthlyUnencumberedRentalIncomeOne], _ ["Self-employed income", $SecondNetPreTaxProfitLatestYrOne]] _ArrayDisplay($aGetHighestFiveAdditionalIncomesForAppOne) _ArraySort($aGetHighestFiveAdditionalIncomesForAppOne, 0, 0, 2) _ArrayDisplay($aGetHighestFiveAdditionalIncomesForAppOne)