Skip to main content

How to use optional field to sort or index?

Hi,
I wanted to use a drop down list to select some columns and these are not mandatory selection, for example there are five criteria's provided, if user selected all 5 criteria (tagged 5 column/fields) I want to use all five fields to sort/create index and perform direct extraction using that index, if user tagged only one column then I need to sort the field using only that criteria and so on...
I am not sure how to use "task.addkey" in these conditions. Can anyone please help me with the code.
 
Thanks in advance,
Vijay
 

Brian Element Mon, 11/09/2015 - 16:31

Hi Vijay,

I am not sure if I understand totally what you are looking for but maybe this example will help you out.  So I am using an array called sFieldname() to hold the fieldnames for the user selected fields.  I then perform an index before performing the extract.  I loop through the array using a For ... next loop adding the contents to the task.AddKey function.  I didn't check for blank entries so if you will have blank entries in the array then you should probably add a function to check such as if sFieldname(i) <> "" then.

I then do the same thing to the extraction so that it will use the index that was just created.

So hope this helps out some.

Brian

Option Explicit

Dim sFieldnames() As String

Sub Main
	Call IndexDatabase()	'Sample-Detailed Sales.IMD
	Call DirectExtraction()	'Sample-Detailed Sales.IMD
End Sub

' Data: Index Database
Function IndexDatabase
	Dim db As database
	Dim task As task
	Dim i As Integer
	Set db = Client.OpenDatabase("My File.IMD")
		Set task = db.Index
			For i = 0 To UBound(sFieldnames)
				task.AddKey sFieldnames(i), "A"
			Next i
		
			task.Index FALSE
		Set task = Nothing
	Set db = Nothing
End Function


' Data: Direct Extraction
Function DirectExtraction
	Dim db As database
	Dim task As task
	Dim dbName As String
	Dim i As Integer
	Set db = Client.OpenDatabase("My File.IMD")
		Set task = db.Extraction
			task.IncludeAllFields
			For i = 0 To UBound(sFieldnames)
				task.AddKey sFieldnames(i), "A"
			Next i
			dbName = "My New File.IMD"
			task.AddExtraction dbName, "", "PROD_CODE = ""05"""
			task.CreateVirtualDatabase = False
			task.PerformTask 1, db.Count
		Set task = Nothing
	Set db = Nothing
	Client.OpenDatabase (dbName)
End Function

 

Walkaway Fri, 11/13/2015 - 06:59

Thanks Brian,
This is what i was looking for. It works.

The website encountered an unexpected error. Try again later.