Forum Discussion
jeffrey_crowley
12 years agoContributor
You've got a mix of VB and C or JS and some other issues. See below for individual comments.
I haven't messed with the project variables so I can't help you there but I would recommend a few things. Declare all your variables as a specific type, e.g. Dim i as Integer. It will help you debug problems later when you mistakenly try to assign an Integer to a variable typed as String, etc.
You have nested loops that both loop i. I would change the inner loop to j or whatever your second favorite variable name is.
When you do a For... Next loop, put the variable in the Next. It will make things clearer as your code gets more complex. e.g.
For i = 1 to 10
... do something
Next i <-- variable name goes here, don't just put Next
You have declared FolderList to have 6 (index starts at 0) elements but are only assigning 4. I'm assuming that it's just demo code but just in case.
Your second If doesn't have a condition or an EndIf, I'm assuming you just missed it when you copied pasted code and trimmed it down.
Your second/inner For loop is written in C or JS or some non-VB language. I don't know if TS allows the mix but I wouldn't recommend mixing languages in a file or probably even a project. Just my opinion...
I've pasted some code below that works that has some commented areas that you will need to fix because I'm missing information on what you want done there.
I would suggest that you take the code snippets (like you posted) and put them in a separate file and get a simple example working. It will help you more easily find and fix problems. Also, when you post code here you can post the entire non-working sample rather than a mix of code that clearly was pulled from multiple areas in your code. It will help us help you better/faster.
Sub TestArray()
Dim FolderList(5) As String
Dim i As Integer
Dim j As Integer
Dim Table As Object
FolderList(0) = "NAME1"
FolderList(1) = "NAME2"
FolderList(2) = "NAME3"
FolderList(3) = "NAME4"
' If Not Project.Variables.VariableExists("MyTable") Then
' Call Project.Variables.AddVariable("MyTable", "Table")
' End
'
' If
' Set Table = Project.Variables.VariableByName("MyTable")
For i = 0 To UBound(FolderList)
Log.Message "#" & i & ": " & FolderList(i)
' For j = 0 To tbl.RowCount
' Log.Message (FolderList)
' Next j
Next i
End Sub
... quick edit to remove Debug.Print and replace with Log.Message... I was playing with this in Excel VBA to get it working quickly.
I haven't messed with the project variables so I can't help you there but I would recommend a few things. Declare all your variables as a specific type, e.g. Dim i as Integer. It will help you debug problems later when you mistakenly try to assign an Integer to a variable typed as String, etc.
You have nested loops that both loop i. I would change the inner loop to j or whatever your second favorite variable name is.
When you do a For... Next loop, put the variable in the Next. It will make things clearer as your code gets more complex. e.g.
For i = 1 to 10
... do something
Next i <-- variable name goes here, don't just put Next
You have declared FolderList to have 6 (index starts at 0) elements but are only assigning 4. I'm assuming that it's just demo code but just in case.
Your second If doesn't have a condition or an EndIf, I'm assuming you just missed it when you copied pasted code and trimmed it down.
Your second/inner For loop is written in C or JS or some non-VB language. I don't know if TS allows the mix but I wouldn't recommend mixing languages in a file or probably even a project. Just my opinion...
I've pasted some code below that works that has some commented areas that you will need to fix because I'm missing information on what you want done there.
I would suggest that you take the code snippets (like you posted) and put them in a separate file and get a simple example working. It will help you more easily find and fix problems. Also, when you post code here you can post the entire non-working sample rather than a mix of code that clearly was pulled from multiple areas in your code. It will help us help you better/faster.
Sub TestArray()
Dim FolderList(5) As String
Dim i As Integer
Dim j As Integer
Dim Table As Object
FolderList(0) = "NAME1"
FolderList(1) = "NAME2"
FolderList(2) = "NAME3"
FolderList(3) = "NAME4"
' If Not Project.Variables.VariableExists("MyTable") Then
' Call Project.Variables.AddVariable("MyTable", "Table")
' End
'
' If
' Set Table = Project.Variables.VariableByName("MyTable")
For i = 0 To UBound(FolderList)
Log.Message "#" & i & ": " & FolderList(i)
' For j = 0 To tbl.RowCount
' Log.Message (FolderList)
' Next j
Next i
End Sub
... quick edit to remove Debug.Print and replace with Log.Message... I was playing with this in Excel VBA to get it working quickly.