Topic
Cutting one dataset into many with certain criteria
- This topic has 2 replies and 2 voices and was last updated 19 years, 2 months ago ago by Kari Koivisto.
-
AuthorPosts
-
02.03.2006 at 23:53 #34079Kari KoivistoParticipant
I have one big dataset, only one column but thousands of rows.
How do I (with macro?) make a criteria something like this:
1. check the value of the row 1, if value is > -0.5 then copy the value to the new dataset.
2. After this check the value of the next row with the same criteria. And also copy the value to the next row of the same dataset.
3. Do this as long as the value stays within the criteria.
4. If value is < -0.5 (for example) then cut (delete) and close the dataset. After this check the next row, do this as long as the value is again > -0.5 then create a new dataset as mentioned in point 1.
Thanks in advance…
Kari
02.03.2006 at 23:53 #34081Kari KoivistoParticipantI have one big dataset, only one column but thousands of rows.
How do I (with macro?) make a criteria something like this:
1. check the value of the row 1, if value is > -0.5 then copy the value to the new dataset.
2. After this check the value of the next row with the same criteria. And also copy the value to the next row of the same dataset.
3. Do this as long as the value stays within the criteria.
4. If value is -0.5 then create a new dataset as mentioned in point 1.
Thanks in advance…
Kari
03.03.2006 at 03:29 #34080Bernhard KantzParticipantYou need to write a macro to be able to create new datasets. Here are the basic steps:
To access the value of an existing dataset in the root folder of the current database you can use the following code:
[code]
Sub AccessValue()
Dim oDataSet As DataSet
Dim vtValue As VariantSet oDataSet = ThisDatabase.RootFolder.Object(“Dataset”)
vtValue = oDataSet.Value(fpDataComponentY)
End Sub
[/code]
To create a new dataset you can use the following code (you can also start macro recording and create a new dataset manually to get some similar code generated):
[code]
Sub CreateNewDataset()
Dim oDataSet As DataSetSet oDataSet = ThisDatabase.RootFolder.Add(“NewDataset”, fpObjectTypeDataSet)
‘ omit the next line if you need an empty dataset
oDataSet.Value = Array(1, 2, 3, 4) ‘ some values
End Sub
[/code]
Appending a value to a dataset basically looks like that:
[code]
Sub AppendValueToDataset()
Dim oDataSet As DataSetSet oDataSet = ThisDatabase.RootFolder.Object(“Dataset”)
With oDataSet
.NumberOfRows = .NumberOfRows + 1
.Value(, , .NumberOfRows) = 12345 ‘ the new value
End With
End Sub
[/code]
The rest is just a matter of running over the retrieved value (using a for loop for instance), append the required values to the dataset you created before and creating new datasets as required.Some related tips: Take a look at the topic [i]Working with Data Sets[/i] in the online help for a complete discussion of FlexPro data access in VBA. You could use FPScript functions to detect the value ranges for the new datasets more effectively (see for instance [b]ValuesAboveLevel[/b] or [b]LevelCrossings[/b]). It is also possible to use the FPScript functions from VBA (see the sample for the [b]FPScriptFunction[/b] property).
Support
support@weisang.com -
AuthorPosts
- You must be logged in to reply to this topic.