Skip to main content

Extracting blank records in a file

Hi all
 
I have built a script that extracts blank records from each field in a file. It is running without any error but it is not creating the extracted database.
The script is as below. Please help, thanks.
________________________________________________________________________________________
Sub Main
 
'Variable declarations
 
'Database objects needed from active DB
Dim NumFields        As Integer
Dim olddb    As Object
Dim task    As Object
Dim filename        As String
Dim filebar         As Object
Dim fieldAs Object
 
On Error Resume Next
Set filebar = CreateObject ("ideaex.FileExplorer")
filebar.DisplayDialog
filename = filebar.SelectedFile
If filename = "" Then
Exit Sub
End If
 
Set olddb = client.opendatabase(filename) 
Set table =  olddb.tabledef 
numfields = table.count
 
 
For i = 1 To numfields
 
If i<10 Then
j = "00" & i
ElseIf  i>9 And i<100 Then
j = "0" & i
Else
j=i
End If
 
  Set ThisField = Table.GetFieldAt (i)
 
 
If ThisField.IsDate Then
Set db = Client.OpenDatabase(filename)
Set task = db.Extraction
task.AddFieldToInc "NUMBER"  'Replicate to include more fields
task.AddFieldToInc "FIRST_NAME"
task.AddFieldToInc ThisField.Name
dbName = "1_" & j & "_Blank " & ThisField.Name & ".IMD"
task.AddExtraction dbName, "", "ThisField.Name  ==  ""00000000"" "
task.CreateVirtualDatabase = False
task.PerformTask 1, db.Count
 
Else
 
If ThisField.IsNumeric And ThisField.Decimals >= 2  Then
Set db = Client.OpenDatabase(filename)
Set task = olddb.Extraction
task.AddFieldToInc "NUMBER"  'Replicate to include more fields
task.AddFieldToInc "FIRST_NAME"
task.AddFieldToInc ThisField.Name
dbName = "1_" & j & "_Blank " & ThisField.Name & ".IMD"
task.AddExtraction dbName, "", "ThisField.Name  = 0"
task.CreateVirtualDatabase = False
task.PerformTask 1, db.Count
 
Else
 
Set db = Client.OpenDatabase(filename)
Set task = olddb.Extraction
task.AddFieldToInc "NUMBER"  'Replicate to include more fields
task.AddFieldToInc "FIRST_NAME"
task.AddFieldToInc ThisField.Name
dbName = "1_" & j & "_Blank" & ThisField.Name & ".IMD"
task.AddExtraction dbName, "", "ThisField.Name == """" "
task.CreateVirtualDatabase = False
task.PerformTask 1, db.Count
End If
 
End If
 
End If
 
Next i
End Sub
 
 
 

Brian Element Thu, 04/26/2018 - 09:25

Hi imanikarimi and welcome to the site.

One problem I see is that for your extraction equations you have the variable inside the brackets and not outside.  So you need to change all your extraction equations so that the ThisField.Name is outside the brackets such as:

ThisField.Name & " == """" "

Hopefully that will fix your problem.  Right now if you look at the history what you would see as the equation is

ThisField.Name == "" instead of the actual name of the field.

Brian