Jump to content

Recommended Posts

Posted (edited)

 

I'm trying to get a bunch of variables with arrays that are setup like this (I know this input sucks - I really don't have a way around it. It's the way it was given to me).

Local $data1 = [1000010, 41, 17]
Local $data2 = [1000010, 41, 16]
Local $data3 = [1000010, 40, 16]
Local $data4 = [1000010, 39, 16]
Local $data5 = [1000010, 38, 16]

Into code which is like this:

$math1 = -($y*100) + ($x*300) + 496
ConsoleWrite($math1)

What I'm attempting to do is something like this, except in a For loop.

$x = $data1[1]
$y = $data1[2]
$math1 = -($y*100) + ($x*300) + 496
ConsoleWrite($math1)

$x = $data2[1]
$y = $data2[2]
$math1 = -($y*100) + ($x*300) + 496
ConsoleWrite($math1)

$x = $data3[1]
$y = $data3[2]
$math1 = -($y*100) + ($x*300) + 496
ConsoleWrite($math1)

Is there a way to get around the imposed limitation above where each variable is $data1, $data2, etc? Thanks.

Edited by Psychobird25
Posted (edited)

do you want to use or don't want to use a "for next" loop ?

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Posted

.... better Execute()

Local $data1 = [1000010, 41, 17]
Local $data2 = [1000010, 41, 16]
Local $data3 = [1000010, 40, 16]
Local $data4 = [1000010, 39, 16]
Local $data5 = [1000010, 38, 16]

For $i = 1 To 5
    $x = Execute('$data' & $i & '[1]')
    $y = Execute('$data' & $i & '[2]')
    $math1 = -($y * 100) + ($x * 300) + 496
    ConsoleWrite($math1 & @CRLF)
Next

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Posted
11 minutes ago, Chimp said:

.... better Execute()

Local $data1 = [1000010, 41, 17]
Local $data2 = [1000010, 41, 16]
Local $data3 = [1000010, 40, 16]
Local $data4 = [1000010, 39, 16]
Local $data5 = [1000010, 38, 16]

For $i = 1 To 5
    $x = Execute('$data' & $i & '[1]')
    $y = Execute('$data' & $i & '[2]')
    $math1 = -($y * 100) + ($x * 300) + 496
    ConsoleWrite($math1 & @CRLF)
Next

 

This works! Thanks

Posted

You don't even need intermediate variables $x, $y, $math1:

Local $data1 = [1000010, 41, 17]
Local $data2 = [1000010, 41, 16]
Local $data3 = [1000010, 40, 16]
Local $data4 = [1000010, 39, 16]
Local $data5 = [1000010, 38, 16]

For $i = 1 To 5
    ConsoleWrite(Execute("$data" & $i & "[1] * 300 - $data" & $i & "[2] * 100 + 496") & @LF)
Next

 

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)

Well, you don't even need to use Execute :

Local $data = [[1000010, 41, 17],[1000010, 41, 16],[1000010, 40, 16],[1000010, 39, 16],[1000010, 38, 16]]
For $i = 0 To UBound($data,1)-1
  ConsoleWrite($data [$i][1]*300 - $data[$i][2]*100 + 496 & @LF)
Next

or you absolutely need to live with the data1...data5

Local $data1 = [1000010, 41, 17]
Local $data2 = [1000010, 41, 16]
Local $data3 = [1000010, 40, 16]
Local $data4 = [1000010, 39, 16]
Local $data5 = [1000010, 38, 16]
Local $data = [$data1,$data2,$data3,$data4,$data5], $dt
For $i = 0 To UBound($data,1)-1
  $dt = $data[$i]
  ConsoleWrite($dt[1]*300 - $dt[2]*100 + 496 & @LF)
Next

 

Edited by Nine
Posted

Changing to input format is kinda cheating ;)

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)

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
×
×
  • Create New...