DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing an Array/Vector by field name

Solved!
Go to solution

Hey gents,

 

I was wondering if there is any way to create and then access to the pieces of the arrays/vectors by field names instead of by position.

 

That's what I mean, could I create something similar like this;

     

          Dim MyFriend

                 MyFriend=(name="mike",last="Miller"....)

 

'  and then access by name

 

                someone=MyFriend(name)

 

I'm working with some large arrays and therefore is hard to remember which field is in which position

 

Thanks!!

 

Javier

 

0 Kudos
Message 1 of 4
(5,163 Views)

Hi Javier,

 

I’m not sure whether I understand you correct – so I assume with “array/vector” you meant a channel in DIAdem. If so, you have the DATA-API in DIAdem since several years. Here are some examples (based on the dataset “Example_Data.TDM” which is installed with DIAdem):

 

Dim oMyFriend
set oMyFriend = Data.GetChannel("[1]/Speed")
' ...
msgbox oMyFriend.Size

' ...
' or 
' ...

Dim oMyListOfFriends
set oMyListOfFriends = Data.CreateElementList
oMyListOfFriends.Add(oMyFriend)
oMyListOfFriends.Add(Data.GetChannel("[1]/Torque"))
' ...
msgbox oMyListOfFriends(1).Name
msgbox oMyListOfFriends(oMyListOfFriends.Count).Name

 

 

Do you mean those things?

Greetings

Walter

0 Kudos
Message 2 of 4
(5,152 Views)

There is a dicitionary object that can be used for lookups

Set Dict = CreateObject("Scripting.Dictionary")
Call Dict.Add("Mike", "Miller")

IF Dict.Exists("Mike") THEN
  dim someone : someone = dict.Item("Mike") 
end if

 Compare can be set to text compare. Check dictionary in the DIAdem help.

The second argument can also be a class object which is assigned by use of "set".

Message 3 of 4
(5,151 Views)
Solution
Accepted by topic author Tafalla

Hey AndreasK, thanks!!,

 

The "dictionary" was exactly what I meant, an "associative array". This solves my "problem"!! I used to work with similar sintax in other languages and working w/o it was being painful!!!

 

Walter_Rick thanks also for answering!!!

 

Javier

0 Kudos
Message 4 of 4
(5,135 Views)