Cancel
Showing results for 
Search instead for 
Did you mean: 

API using MapData Objects

Siemens Creator Siemens Creator
Siemens Creator

Can someone assist with example code of the MapData Object adding data and then retrieving data.  I am having trouble with column indices with jagged data.

For example

[id, value1, ..., valueN]

1, 1, 2, 3  {id=1, N=3}

2, 4  {id=2, N=1}

3, 5, 6  {id=3, N=2}

3 REPLIES

Re: API using MapData Objects

Siemens Creator Siemens Creator
Siemens Creator
Option Explicit On
Sub Main

' The Data
' 1 1 2 3
' 2 4
' 3 5 6

    Dim App As femap.model
	Dim myMap As femap.MapData
	
	Dim rc As Integer
	
	Const zero As Long = 0
	Const one As Long = 1
	Const two As Long = 2
	Const three As Long = 3
	Const four As Long = 4
	Const five As Long = 5
	Const six As Long = 6
	
	Dim val As Long
	Dim n As Long
	
	Set App = feFemap()
	Set myMap = App.feMapData
	
	myMap.Initialize(10)
	
	' This is how I thought you are supposed to use Define*
	n = myMap.DefineInt()
	rc = myMap.SetInt(n, one, one) ' n = 0
	n = myMap.DefineInt()
	rc = myMap.SetInt(n, one, two) ' n = 1
	n = myMap.DefineInt()
	rc = myMap.SetInt(n, one, three) ' n = 2

	' ?????
	' This is where I am lost on how to "reset" the column index
	' Are you supposed "reset"
	' ?????
	rc = myMap.SetInt(zero, two, four)
	rc = myMap.SetInt(zero, three, five)
	rc = myMap.SetInt(one, three, six)

	' ?????
	' How is one supposed to know the column indices on retrieving the data ?
	' Should the column indices be stored in another data structure ?
	' ?????
	rc = myMap.GetInt(zero, one, val) : App.feAppMessage(FCM_NORMAL, "value = " & val)
	rc = myMap.GetInt(one, one, val) : App.feAppMessage(FCM_NORMAL, "value = " & val)
	rc = myMap.GetInt(two, one, val) : App.feAppMessage(FCM_NORMAL, "value = " & val)
	rc = myMap.GetInt(zero, two, val) : App.feAppMessage(FCM_NORMAL, "value = " & val)
	rc = myMap.GetInt(zero, three, val) : App.feAppMessage(FCM_NORMAL, "value = " & val)
	rc = myMap.GetInt(one, three, val) : App.feAppMessage(FCM_NORMAL, "value = " & val)
	
End Sub

Re: API using MapData Objects

Siemens Phenom Siemens Phenom
Siemens Phenom

While you can certainly use MapData to store "jagged data" it doesn't really store things "jagged" internally. When you call a "Define" method that field is created for all possible IDs... so MapData is really more of a sparse array where each column could be a different data type.

 

Each time you call a Define method the return code is the column index of that data field. You must either store that return code to use in later Set/Get methods or simply rely on the fact that the codes will go from 0 to N in the order that you called the various Defines. In most cases you would want to call all of the Defines prior to calling any Set methods. 

 

If you are using MapData to store lists of integers like your example, then for each ID you should just be able to keep calling Get methods with index values starting at 0 and going until you get a return code of FE_NOT_EXIST if you wanted to retrieve the entire list.

 

Hope this helps.

Re: API using MapData Objects

Siemens Creator Siemens Creator
Siemens Creator

Working Sample

 

Option Explicit On
Sub Main

' The Data
' 1 1 2 3
' 2 4
' 3 5 6

    Dim App As femap.model
	Dim myMap As femap.MapData
	
	Dim rc As Integer
	
	Dim theValues As String
	
	Const zero As Long = 0, one As Long = 1, two As Long = 2, three As Long = 3
	Const four As Long = 4, five As Long = 5, six As Long = 6
	
	Dim val As Long, n As Long, columnCounter As Long, idCounter As Long
	
	Set App = feFemap()
	Set myMap = App.feMapData

	myMap.Initialize(10)
	
	n = myMap.DefineInt() : rc = myMap.SetInt(n, one, one)
	n = myMap.DefineInt() : rc = myMap.SetInt(n, one, two)
	n = myMap.DefineInt() : rc = myMap.SetInt(n, one, three)
    n = myMap.DefineInt() : rc = myMap.SetInt(n, two, four)
	n = myMap.DefineInt() : rc = myMap.SetInt(n, three, five)
	n = myMap.DefineInt() : rc = myMap.SetInt(n, three, six)
	
	columnCounter = 0
	For idCounter = 1 To myMap.Count
		rc = FE_OK
		theValues = "  "
		While rc = FE_OK
		    rc = myMap.GetInt(columnCounter, idCounter, val)
			If rc = FE_OK Then
				theValues = theValues & val & "  "
				columnCounter = columnCounter + 1
			End If
		Wend
		App.feAppMessage(FCM_NORMAL, "  " & idCounter & theValues)
	Next idCounter

End Sub