read all the first key columns into an array VBA

read all the first key columns into an array VBA

Darkforce_the_ilogic_guy
Advisor Advisor
915 Views
3 Replies
Message 1 of 4

read all the first key columns into an array VBA

Darkforce_the_ilogic_guy
Advisor
Advisor

I have an code can find all my Familie navn(display names) and add it to a list. is there a way to use the display name of the familly to load all the various value that is in the first Key collums  in the family .

 

I do only want the aktive ones ... and only one of each.

 

when you selecet the Display name in the form ... I want it to clear the array and add all the choses form the  first key columns into an arrays in the next list box. please ask if you need more info to help me

bt_0-1602092176488.png

 

0 Likes
916 Views
3 Replies
Replies (3)
Message 2 of 4

Darkforce_the_ilogic_guy
Advisor
Advisor

I have now been enble to make an code that finde the all the collum name... I might be enble to use it fil do what I want ....or almost but it might work... now I can see all of the name ..  and it can finde the header  and with it is at the right one ... can you tell me that I need to do ... to read all the cell ?... if it is possible only the aktive cell... if not I might still help me get one step closer to my program I want to make

 

Private Sub ListBox1_Click()
Dim Msg As String
Dim i As Integer

' Dim selMe As String
'selMe = vbNewLine
Msg = "You selected" & vbNewLine


For i = 0 To ListBox1.ListCount - 1
If ListBox1.selected(i) Then
Msg = Msg & ListBox1.List(i) & vbNewLine
End If
Next i
MsgBox Msg


Dim family As ContentFamily
Dim checkFamily As ContentFamily

'Dim hexHeadNode As ContentTreeViewNode
'Set hexHeadNode = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item("Structural Shapes") '

Dim hexHeadNode As ContentTreeViewNode
Set hexHeadNode = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item("Structural Shapes").ChildNodes.Item("Angles")


' MsgBox ("this is runnning 1")
For Each checkFamily In hexHeadNode.Families
'MsgBox ("this is runnning 2")
' MsgBox ("this is running 2.5 " + "DisplayName " + checkFamily.DisplayName + " Selecet name " + ListBox1.List(0))
If checkFamily.DisplayName = ListBox1.List(0) Then
MsgBox ("this is runnning 3")
MsgBox ("Test " + selMe)
Set family = checkFamily
Exit For
End If
'MsgBox ("this is runnning 4")
Next
MsgBox ("this is runnning 5")




'Find Header Material


Dim oContentTableColumns As ContentTableColumns
Set oContentTableColumns = family.TableColumns

'dump all columns
Dim oContentTableColumn As ContentTableColumn
For Each oContentTableColumn In oContentTableColumns
MsgBox (oContentTableColumn.DisplayHeading)
If oContentTableColumn.DisplayHeading = "Material Type" Then

'See value in this column checck all row

MsgBox ("Read this to an Array for Next Step")

'modify cell
Dim oRow As ContentTableRow
For Each oRow In family.TableRows

'read all cell value of column Material Type
MsgBox (oRow.Item("Material Type").Value)

Next


End If
MsgBox (oContentTableColumn.DisplayHeading)
'Debug.Print "internal name:" & oContentTableColumn.InternalName & "<<<<>>>>display heading:" & oContentTableColumn.DisplayHeading

Next










End Sub
0 Likes
Message 3 of 4

Michael.Navara
Advisor
Advisor

I don't know, what is your goal. But following code shows, how to read distinct values from column.

 

 

Sub ReadContentTableColumnDistinctValues()

    'Get content center family
    '(In my ContentCenter: steel profiles -> angles -> DIN 59370)
    Dim oFamily As ContentFamily
    Set oFamily = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes(3).ChildNodes(9).Families(1)
    
    'Create dictionary object
    'Source: https://stackoverflow.com/questions/36044556/quicker-way-to-get-all-unique-values-of-a-column-in-vba
    Set dict = CreateObject("Scripting.Dictionary")
    
    'Iterate rows in family table and fill dictionary
    Dim row As ContentTableRow
    For Each row In oFamily.TableRows
        Dim cellValue As String
        cellValue = row("MATERIAL").value
        dict(cellValue) = Empty
    Next
    
    'Iterate distinct values and print to immediate window
    Dim distinctValue As Variant
    For Each distinctValue In dict.keys()
        Debug.Print distinctValue
    Next
        
End Sub

 

0 Likes
Message 4 of 4

Darkforce_the_ilogic_guy
Advisor
Advisor

My goal is to try to make an enlangement  to Content Center.  We are using to make get raw material with some Iproperties on it.  so first I kind og simple need to get my Centent centor to work form an User form. 

 

2 step. will be go get som Extranal data about the select Content center part.  Like Price ,  how most we have in stock. location in stock 

 

3. step might been add Data sheel data about the material selecet. .like strenght . bending characteristics, welding properties.  and so on anything the user might need to select the right material 

0 Likes