DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

ArraytoChannels error "Cannot append, because the target channels are not all the same length"

Solved!
Go to solution

Hello!

After the end of my second day of try error, i have to bring this quesiton to the table:

 

I am using ArraytoChannels function to store ADO recordsets as channels. What is strange is that for the first recordset, it works; but for the next time in the loop, it always fails with the error message "Cannot append, because the target channels are not all the same length". 

I confirmed that:

the sizes of the RowData and the ChannelNames are equal,

both pass the isarray =true test,

i change the order of the ChannelNames,  

i reconnected/disconnected from/to the oConnection each time,  nothing changed.

I am  apparently missing something -but going crazy to figure out what! - if anybody can share his/her opinion I will so much appriciate. Here is my code:

 

oTables=Array("WellStates","ChokeData","WellParameters", "FlowData","PumpData","SensorsData", "ModelCalculatedData")

 Call OpenSQLConnection
 Set oRecordset = CreateObject("ADODB.Recordset")
 Call SelectWell
 Call GetWellStateIDs


Data.Root.Clear
for j=0 to ubound(oTables,1)

   sSQLSting = "select * from [" & oTables(j) & "] where [WellStateID] between " & WellStateIDFirst & " and " & WellStateIDLast
   oRecordset.Open sSQLSting, oConnection 
   Dim oFieldNames : Array : ReDim oFieldNames(orecordset.Fields.count-1)
    for i=0 to orecordset.Fields.count-1
       oFieldNames(i)=orecordset.Fields.item(i).name
    next
   oArray=oRecordset.GetRows(-1,0,oFieldNames)
   Set oGroup=Data.Root.ChannelGroups.Add(oTables(j))

   arraytochannels oArray, oFieldNames
   oRecordset.close
   oConnection.Close
next

 

sub GetWellStateIDs
  sSQLSting = "select * from [WellStates] where [wellid]=" & WellID
  oRecordset.Open sSQLSting, oConnection
  oArray=oRecordset.GetRows()
  WellStateIDFirst=oArray(0,0)
  WellStateIDLast=oArray(0,ubound(oArray,2))
  oRecordset.close
end sub


sub OpenSQLConnection
  Set WshNetwork = CreateObject("WScript.Network")
  oComputerName = WshNetwork.ComputerName
  oDB="MX2.Player.DB"
  Set oConnection = CreateObject("ADODB.Connection") 
  oProvider = "Provider=SQLOLEDB.1;Integrated Security =SSPI;PeoExecuteist Security Info=True;Data Source="
  oProvider = oProvider & oComputerName & "\MX;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID="
  oProvider = oProvider & oComputerName & ";Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog="
  oProvider = oProvider & oDB
  oConnection.ConnectionString = oProvider
  oConnection.Open
end sub

0 Kudos
Message 1 of 7
(4,725 Views)

The ArrayToChannels method behaves a little currious.

It just takes the channel name into acount not taking looking for group or anything else.

i used an ugly woraround by appending a string at the end of each channel name and removing it at the end.

 

oTables=Array("WellStates","ChokeData","WellParameters", "FlowData","PumpData","SensorsData", "ModelCalculatedData")

Dim MyArray(1,10000), MyChannels(1), I
For I = 0 to 10000
  MyArray(0,I)=2*Pi*I/10000
  MyArray(1,I)=Sin(2*Pi*I/10000)
Next
MyChannels(0)="X Channel"
MyChannels(1)="Sin Channel"

const uniqueStr = "______"
Data.Root.Clear

for j=0 to ubound(oTables,1)

  Set oGroup=Data.Root.ChannelGroups.Add(oTables(j))
  ogroup.Activate
  dim chList : chList = ArrayToChannels(MyArray, MyChannels)
  dim chRef : for each chRef in chList
    dim chObj : set chObj = data.GetChannels(chRef).Item(1)
    chObj.name = chObj.Name & uniqueStr
  Next
next

dim grpObj : for each grpObj in data.Root.ChannelGroups
  dim chOb : for each chOb in grpObj.Channels
    chOb.Name = left(chOb.Name, len(chOb.Name) - len(uniqueStr))
  Next
Next

The newly created group also has to be marked as active to be used as target.

Hope you can use this example.

 

 

 

 

Message 2 of 7
(4,701 Views)
Solution
Accepted by topic author KorayKinik

Another hint. If you check the DIAdem help for

Microsoft Windows Script Debugger

you are able to install the debugger in DIAdem.

It would potentially have shown you that the command is not working like expected.

 

Sorry for the inconveniance

Andreas

Message 3 of 7
(4,695 Views)
Solution
Accepted by topic author KorayKinik

Found a better solution. It is possible to put the group names into the names field as channel reference.

 

So if you just replace

 

  Set oGroup=Data.Root.ChannelGroups.Add(oTables(j))
  arraytochannels oArray, oFieldNames

by

 

  Set oGroup=Data.Root.ChannelGroups.Add(oTables(j))
  dim newChNames : newChNames = Array()
  redim newChNames(UBound(oFieldNames))
  dim nI : for nI = 0 to Ubound(oFieldNames)
    newChNames(nI) = oGroup.Name & "/" & oFieldNames(nI)
  Next
  arraytochannels oArray, newChNames

 

it should work.

 


 

 

I just append the running example:

oTables=Array("WellStates","ChokeData","WellParameters", "FlowData","PumpData","SensorsData", "ModelCalculatedData")

Dim oArray(1,10000), oFieldNames(1), I
For I = 0 to 10000
  oArray(0,I)=2*Pi*I/10000
  oArray(1,I)=Sin(2*Pi*I/10000)
Next
oFieldNames(0)="X Channel"
oFieldNames(1)="Sin Channel"

Data.Root.Clear

for j=0 to ubound(oTables,1)

  Set oGroup=Data.Root.ChannelGroups.Add(oTables(j))
  dim newChNames : newChNames = Array()
  redim newChNames(UBound(oFieldNames))
  dim nI : for nI = 0 to Ubound(oFieldNames)
    newChNames(nI) = oGroup.Name & "/" & oFieldNames(nI)
  Next
  arraytochannels oArray, newChNames  
next
Message 4 of 7
(4,687 Views)

Hi Andreas,

Many thanks for the prompt and detailed explanation - i will try this now and hopefully this time will make it work.

Cheers! 🙂

0 Kudos
Message 5 of 7
(4,673 Views)

it worked!

thanks again! 

0 Kudos
Message 6 of 7
(4,620 Views)

I came here fighting the same error due to a channel I was trying to create in two different groups with the same name. This solution (adding group names) worked perfectly. Just what I needed!

0 Kudos
Message 7 of 7
(229 Views)