Adding custom rows on summarization

14 posts / 0 new
Last post
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Sorry, I hadn't realized it was for a SmartAnalzyer app, now I understand.

So there is only 8 items. Then I would suggest that your script had a section that creates a new database and adds the categories.  Below is some sample code to do that.  You can copy it and modify it.  Then you can do the join to have a file with a 0 for records if there is no items.

Let me know how it goes.

Brian

Option Explicit

Sub Main

	Call createDatabase
	Call addData
	Client.OpenDatabase "SampleData.IMD"

End Sub 

Function createDatabase
	Dim NewTable As Table
	Dim db As database
	Dim AddedField As field
	Set NewTable = Client.NewTableDef
	
	' Define a field for the table.
	Set AddedField = NewTable.NewField
		AddedField.Name = "Category"
		AddedField.Type = WI_CHAR_FIELD
		AddedField.Length = 20
		' Add the field to the table.
		NewTable.AppendField AddedField
	Set AddedField = Nothing
	
	' Create the database.
	Set db = Client.NewDatabase("SampleData.IMD", "", NewTable)
	Set NewTable = Nothing
	Set db = Nothing

End Function

Function addData
	Dim db As Database
	Dim Table As Table
	Dim rs As RecordSet
	Dim rec As Record
	Dim i As Integer
	' Create a table.
	
		
	' Obtain the recordset.
	Set db = client.OpenDatabase("SampleData.IMD")
		Set table = db.TableDef
			table.Protect = False
			Set rs = db.RecordSet
			' Obtain a new record.
			For i = 1 To 8
				Set rec = rs.NewRecord
				' Use the field name method to add data.
				rec.SetCharValue "Category", "Category" & i
				rs.AppendRecord rec
			Next i
			
			' Protect the table before you commit it.
			
			table.Protect = True
			
			' Commit the database.
			
			db.CommitDatabase
			
			' Open the database.
			
			Client.OpenDatabase "SampleData.IMD"
			
			' Clear memory
		Set table = Nothing
		db.close
	Set db = Nothing
	Set rs = Nothing
	Set rec =  Nothing
End Function

 

mohamed
Offline
Joined: 07/27/2015 - 03:45

Hi Brian,
This is what I was looking for.
Thanks a lot
Shafeer

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Glad to help.  so just out of curiousity are you using SmartAnalyzer apps within your company?

Pages