Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Activate VBA with this code 1

Status
Not open for further replies.

DrMingle

Technical User
May 24, 2009
116
US
What am I missing? I can't seem to run this code. Any help would be appreciated.

Code:
Option Explicit

' Carraghan, R., Pardalos, P. M.: An exact algorithm for the maximum clique problem. Op. Research Letters 9. (1990) 375-382
' converted to the weighted case

Private level_nodes() As Long, nStart() As Long, NodesNum() As Long
Private t As Long, mnMaxClique As Long
Private nLevelWAcc() As Long
'

Public Function Start() As Long
  Dim i As Long, t_minus_1 As Long, wt As Long
  
  ReDim level_nodes(1 To Nodes, 1 To Nodes)
  ReDim NodesNum(1 To Nodes)
  ReDim nStart(1 To Nodes)
  ReDim nLevelWAcc(1 To Nodes)
  mnMaxClique = 0
  
  '''''' each level has its own set of nodes
  For i = 1 To Nodes
   level_nodes(1, i) = i
  Next
  NodesNum(1) = Nodes
  '''''''''''''''''''''''''''''''''
  t = 1
  nStart(t) = 0
  '''''''''''''''''''''''''''''''''''
  While t >= 1
    nStart(t) = nStart(t) + 1
    If NodesNum(t) < nStart(t) Then
      t = t - 1
    Else
      wt = 0
      For i = nStart(t) To NodesNum(t)
        wt = wt + w(level_nodes(t, i))
      Next
    
      ''' Degree control
      If (nLevelWAcc(t) + wt) > mnMaxClique Then
        t_minus_1 = t
        t = t + 1
        nStart(t) = 0
        NodesNum(t) = 0
        nLevelWAcc(t) = nLevelWAcc(t_minus_1) + w(level_nodes(t_minus_1, nStart(t_minus_1)))
        ''' define nodes for the next level
        For i = nStart(t_minus_1) + 1 To NodesNum(t_minus_1)
          If arr(level_nodes(t_minus_1, nStart(t_minus_1)), level_nodes(t_minus_1, i)) Then
            NodesNum(t) = NodesNum(t) + 1
            level_nodes(t, NodesNum(t)) = level_nodes(t_minus_1, i)
          End If
        Next
        If NodesNum(t) = 0 Then
          t = t - 1
          If nLevelWAcc(t + 1) > mnMaxClique Then
            mnMaxClique = nLevelWAcc(t + 1)
          End If
        End If
      Else
        t = t - 1
      End If
    End If
  Wend
  
  Start = mnMaxClique

End Function
 
Thanks Doug for your response.

I am not able to run the macro at all...it doesn't even show up until I try and record/create another macro and then it is there...somehow or another it is hidden.

Any ideas?
 
You can call a function from another VBA routine, or you can enter it on the spreadsheet in the same way as the built in Excel functions, but if you want to run it from the Macro list, or attach it to a button, you will have to either make it a Sub or write a short Sub that calls the function.

Alternatively type =Start() in a worksheet cell, and that will take you into debug mode, with a message that Nodes is not defined.

Doug Jenkins
 


Exactly HOW are you trying to run this code? Please be very specific.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top