Jump to content
danusko

list of values to dynamic variable

Recommended Posts

Hi, i try to figured out how to do something like this. 

I have list of  values e.g. in excel. After  i copy it to the clipboard (e.g. list of 4 values) my script will take this 4 values and put each of this value to dynamic variable . 

After this it will be possible to call each of the variable and take out one of you want to use. 

E.g.  i wil have this values

123

321

111

444

 

i wll copy all this to clipboard and then i will be able to call the first value with variable(1) and the second with variable(2) or with loop i will call step by step each of those variables. 

I tried something like this, but i am not so good in arrays :( thx for any help

Opt("WinTitleMatchMode", -2)  ; -2 = subStr, nocase
AutoItSetOption("SendKeyDelay", 10)
Global $ICO[1000]

WinActivate("Excel")
WinWaitActive("Excel")
send("^c")
; upper i copy list of values to clip

#include <Array.au3>
Local $arr = []      ; NOTE this creates an array of size 1 with an empty string


$Pamat = ClipGet() 
_ArrayAdd($arr, $Pamat)
_ArrayAdd($arr, $Pamat)
 Local $ArrayICO = _FileListToArray($Pamat, "*")

For $i = 1 To UBound($ArrayICO) - 1
    ConsoleWrite('arr[' & $i & '] == ' & $ArrayICO[$i] & @CRLF)
Next

MsgBox(0,  "vysledok ",  $arr[2] )  
exit

 

Share this post


Link to post
Share on other sites
Opt("WinTitleMatchMode", -2)  ; -2 = subStr, nocase
AutoItSetOption("SendKeyDelay", 10)
Global $ICO[1000]

WinActivate("Excel")
WinWaitActive("Excel")
send("^c")
; upper i copy list of values to clip

#include <Array.au3>
Local $arr = []      ; NOTE this creates an array of size 1 with an empty string

$values = ClipGet()
$values = StringSplit($values,@CRLF,1)

For $i = 1 To $values[0]
    ConsoleWrite('arr[' & $i-1 & '] = ' & $values[$i] & @CRLF)
Next

MsgBox(0,  "vysledok ",  $arr[2] )
exit

 

Edited by Zedna

Share this post


Link to post
Share on other sites

This code retur error on line 20.

 

Array variable has incorrect number of subscripts or subscripts dimension range exceeded. 

I copied only abou 20 values from excel. :(

Share this post


Link to post
Share on other sites

Here is fixed your example where is copied array $values to array $arr

Local $arr = []      ; NOTE this creates an array of size 1 with an empty string

$values = '1' & @CRLF & '2' & @CRLF & '3'
;~ $values = ClipGet()

$values = StringSplit($values,@CRLF,1)
ReDim $arr[$values[0]]

For $i = 1 To $values[0]
    $arr[$i-1] = $values[$i]
    ConsoleWrite('arr[' & $i-1 & '] = ' & $arr[$i-1] & @CRLF)
Next

MsgBox(0,  "Result 2",  $arr[1] )

 

output:

Quote

    arr[0] = 1
    arr[1] = 2
    arr[2] = 3
 

 

Share this post


Link to post
Share on other sites

Here is simple variant using only/directly array $values:

$values = '1' & @CRLF & '2' & @CRLF & '3'
;~ $values = ClipGet()

$values = StringSplit($values,@CRLF,1)

For $i = 1 To $values[0]
    ConsoleWrite('values[' & $i & '] = ' & $values[$i] & @CRLF)
Next

MsgBox(0,  "Result 2",  $values[2] )

 

output:

Quote

    values[1] = 1
    values[2] = 2
    values[3] = 3

 

Share this post


Link to post
Share on other sites

As Zedna mentioned if you use the Excel udf, you could just use _Excel_RangeRead to read cells, columns etc.. into an array, see help file for more info.

Share this post


Link to post
Share on other sites

Thank you very much, This is exactly what i needed. 

This part of code is for me very helpfull. 

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...