Jump to content

2D Array - Output


Recommended Posts

I looked all over the forum, and can't find this anywhere. I am sure that there is a easy way to do this, but I can't find an answer. OK so I am using ChrisL's _sql files. I have created a pretty extensive GUI that I have with a bunch of queries that I use all the time (All Select queries on Win 2000 sql server).

Anyways, this is what I am trying to accomplish. This is what is in the array if I run a query, and I want to be able to get the data out of an array, and be able to work with the part that says 'Test123' and put that alone into clipboard (clipput). Is there an easy way to do this?

[0]|sqldb

[1]|Test123

I know it is a 2D array. I have tried different functions that work with arrays, but most do not work with 2D arrays.

Link to comment
Share on other sites

i guess $var is the array right? If so, I receive the following error:

(1434) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$Info = $aData[0][1]

$Info = ^ ERROR

(I changed $var to $adata, as that is what my array is)

Link to comment
Share on other sites

I have one more question with an array. I have an query that returns a different ammount of rows, and I want to be able use this data in another query that will run just after. So what I want to do is replace @CRLF with ',' so it will look like A01','A02','A03','A04' etc...

The problem is that the amount of rows returned is always different depending on what I run it against.

Any ideas?

[0]|dispo

[1]|A01

[2]|A02

[3]|A03

[4]|A04

[5]|A05

[6]|B01

[7]|B02

[8]|B03

[9]|B04

[10]|B05

[11]|B06

[12]|B07

[13]|B08

[14]|B09

[15]|B10

[16]|B11

[17]|B12

[18]|B13

[19]|B14

[20]|B15

[21]|B16

[22]|B17

[23]|B18

[24]|B19

[25]|B20

[26]|B21

[27]|SAL

Link to comment
Share on other sites

Which variable would be the final variable that would have A01','A02','A03 etc...?

CODE: AutoIt

For $i = 1 To $var[0][0]

$var[$i][1] = StringReplace($var[$i][1], @CRLF, ',') ; or "','"

Next

with this, it would still be the same array.... just changed to what you wanted. It replaces the @CRLF with "."

... did you test it?

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Ya I tried it, but its not working. I even tried this with replacing the 'A' with a 'G' to see if it would work, and the same data is displayed in the array.

It is a 2d array. I think I need to take it out from an array (its only one column that I need to extract). Once I have a variable that has all this data, I can use the string replace.

Link to comment
Share on other sites

Does anyone know why it would not be working? I can provide more code if anyone wants to see what I am doing.

Or does anyone else have a solution to this?

I have an array that looks like this

[0]|dispo

[1]|A01

[2]|A02

[3]|A03

[4]|A04

[5]|A05

And I want for it to look like this

A01','A02','A03','A04','A05

(I would have a variable equal the above so that I can use the data, and not have it in a array)

But there somethimes could be more than 5 in the array.

thanks in advance.

Edited by bartekd
Link to comment
Share on other sites

Here is the script that I am using. I have shortnened it so that it is easier to read as to what I am trying to do.

#include <array.au3>

#include <_sql.au3>

_SQLRegisterErrorHandler();register the error handler to prevent hard crash on COM error

$con = _SQLStartup()

If @error then Msgbox(0,"Error","Error starting ADODB.Connection")

_SQLConnect(-1,"SV50016","rogers_ret",USERNAME,Password)

if @Error then Msgbox(0,"",$SQLErr)

$Query = "select dispo from sv50016.gemmareports2.dbo.tbldispocamp where rpc = '1' and campaign_name = 'ROGERS_RET'"

$data = _SQLExecute(-1,$Query)

$aData = _SQLGetData2D($data)

If NOT @error then

For $i = 1 To $aData[0][0]

$aData[$i][1] = StringReplace($aData[$i][1], @CRLF, ',') ; or "','"

Next

ClipPut($aData)

_arrayDisplay($aData)

Else

Msgbox(0,"Error",$SQLErr)

Endif

_SQLClose()

Edited by bartekd
Link to comment
Share on other sites

YAY, I figured it out. If anyone is curious, this is what I ended up with that worked.

$done = "'"

For $r = 0 To UBound($aData) - 1

For $c = 0 To UBound($aData, 2)

; $r = row, $c = column

$sTemp = $aData[$r][0] & "|"

Next

$sTemp = StringTrimRight($sTemp, 1)

$done = $done & "','" & $sTemp

;MsgBox(1024, "Row " & $r, $sTemp)

Next

ClipPut($done & "'")

I added the above after my code, and it works like a charm. Thanks everyone, especially Valuater for all the help.

Link to comment
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
 Share

  • Recently Browsing   0 members

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