Skip to main content

Array

Hi, i want to use the fieldsname which i placed in an array to check for each field if it is numeric or not. But for some reason it won't accept the array fieldname to get the field and check if it is numeric or not. Anyone who can help me?
 
------------------------------------------
 Option Explicit
 
Dim A1 As Integer
Dim A2 As Integer
Dim i As Integer
 
Dim DbLetter As String 
Dim Q1 As Integer
Dim Q2 As Integer
 
Dim db As database
Dim table As table
Dim field As field
Dim field_count As Integer
Dim fieldNames() As String
 
Dim FieldNumeric As Boolean 
 
Sub Main
 
Q1 = 1 'Aantal bestanden
DbLetter = "A" 'Start letter databasename
 
For A1 = 1 To Q1
 
Set db = Client.OpenDatabase(DbLetter & " (" & A1 & ").IMD")
Set table = db.TableDef
field_count = table.count
'MsgBox field_count 'Check 
ReDim fieldNames(field_count)
For i = 1 To field_count
Set field = table.GetFieldAt(i)
fieldNames(i) = field.name
Next i
Q2 = field_count
MsgBox Q2
 
For A2 = 0 To Q2
'MsgBox fieldNames(A2) 'Check
 
Set db = Client.OpenDatabase(DbLetter & " (" & A1 & ").IMD")
Set table = db.TableDef
Set field = table.GetField(fieldNames(A2))
FieldNumeric = field.IsNumeric
 
'If FieldNumeric  = True Then
'MsgBox "Numeriek"
'End If
 
Next A2
Next A1
End Sub
 

Brian Element Tue, 06/18/2019 - 11:01

Hi Robert,

The problem is with your second loop.  When you created the fieldNames() array and populated it your first item is 1, but when you are doing the loop to check if it s numeric your first item is 0, 0 exists in your array but it is blank and that is why you are getting the error.  This is a common problem when dealing with arrays and field names, the easiest fix is to make two changes to your code.  Change the second for loop to:

For A2 = 0 to Q2 - 1 ' this will loop through the number of items, if you leave it at 0 you have one items more then field names.

The second is in the Set Field change (A2) to (A2 + 1) , this way on the first round when A2 is 0 you will be looking for item 1 in the array.

Hopefully that helps you out.

Brian

Robert van den… Thu, 06/20/2019 - 08:30

In reply to by Brian Element

Hi Brian, 
 I fixed it a little bit diffrently (see the attached script file) but it is working now without crashing the entire IDEA server. I checked it and it takes the first and last fieldname correctly now.