I need to the add a test folder and then add 4-5 test cases to the folder as long as testfolder is same, then I need to add the next folder and add 4-5 test cases and so on.

My current code has following errors:
1. It is trying to add the folders mutiple times. It should add the folder just once and then add test cases
2. It adds all the test cases to the first folder,

The datapool is something like this
tcFolder tcFolderDesc testCase testCaseDesc
Folder1 folder1desc testcase1 desc1
Folder1 folder2desc testcase2 desc2
Folder1 folder3desc testcase3 desc3
Folder2 folder2desc folder2tc1 des1
Folder2 folder2desc folder2tc2 des2

In above example I want to add folder1 once and add test case1, testcase2, testcase3, Then add folder2 once and add folder2tc1 and folder2tc2 and so on

'$Include "SQAUTIL.SBH"

Sub Main
Dim Result As Integer
Dim dp as Long
Dim tcFolder as string
Dim tcFolderDesc as string
Dim testCase as string
Dim testCaseDesc as string

Dim Lasttcfolder as string

Lasttcfolder = ""

dp = SQADatapoolOpen("completeTM")

For x = 1 to 25
Call SQADatapoolFetch(dp)
Window SetContext, "Caption=selectaccount - Rational TestManager", ""
GenericObject DblClick, "Class=AfxWnd;ClassIndex=3", "Coords=72,40"

Window SetContext, "Caption=Test Plan - GRP;ChildWindow", ""
GenericObject Right_Click, "Class=AfxWnd;ClassIndex=1", "Coords=55,5"
PopupMenuSelect "Insert Test Case Folder..."

Window SetContext, "Caption=New Test Case Folder", ""
Call SQADatapoolValue(dp,1,tcfolder)
InputKeys tcFolder

EditBox Click, "Label=Description:", "Coords=38,33"
Call SQADatapoolValue(dp,2,tcFolderDesc)
InputKeys tcFolderDesc

PushButton Click, "Text=OK"

If tcFolder <> Lasttcfolder Then

Window SetContext, "Caption=selectaccount - Rational TestManager", ""
Window SetContext, "Caption=Test Plan - GRP;ChildWindow", ""
GenericObject Right_Click, "Class=AfxWnd;ClassIndex=1", "Coords=58,25"
PopupMenuSelect "Insert Test Case..."

Window SetContext, "Caption=New Test Case", ""
Call SQADatapoolValue(dp,3,testCase)
InputKeys testCase
EditBox Click, "Label=Description:", "Coords=93,49"
Call SQADatapoolValue(dp,4,testCaseDesc)
InputKeys testCaseDesc
PushButton Click, "Text=OK"
End If

tcFolder = LasttcFolder

Next x

Call SQADatapoolClose(dp)

End Sub