Hi everyone!
I'm trying to get data from database table and using cursor to hold the records.
My data in table record is like..
There are 2 features I need to implement when adding new records containing with "S"
Example of records
1. When adding data contain with "S" should be in the top most record. (I think I got this)
2. When there already record contain with "S" it should be sorted by its numeric value (difficult for me)
Note that the numeric value between P and S is incremental.
This is how I derive #1 requirement, it might be lengthy(hope there is a better way).
Hope anyone can help me out how to solve it.
Thank you in advance
I'm trying to get data from database table and using cursor to hold the records.
My data in table record is like..
B4X:
P1
P2
P3
P4
P5
P6
Example of records
B4X:
P7S
P8S
P9S
P1
P2
P3
P4
P5
P6
2. When there already record contain with "S" it should be sorted by its numeric value (difficult for me)
Note that the numeric value between P and S is incremental.
This is how I derive #1 requirement, it might be lengthy(hope there is a better way).
B4X:
Sub Button1_Click
'=================Exploring Array===============================
Dim Result,sizeIndex As String
Dim Cursor1 As Cursor
Dim SenrCtr As Int = 0
'del = DBUtils.ExecuteMap(SQL, "SELECT qp ,status FROM Quep",Null)
Cursor1 = SQL.ExecQuery("SELECT qp ,status FROM Quep") '' Query from Table
sizeIndex = Cursor1.RowCount '' indetify the size of records from table
For i = 0 To Cursor1.RowCount - 1 '' Iterate all records
Cursor1.Position = i '' Get Cursor position
Result = Cursor1.GetString("qp") '' Get values in column qp
Msgbox(Cursor1.GetString("qp") ,"Total " & sizeIndex) '' Display in Messagebox
If Result.Contains("S") Then '' Test if it contains specific value
SenrCtr = SenrCtr + 1 '' Identify number of 'S' in record
End If
Next
''--------------------------------------------------------------
If SenrCtr > 0 Then
''--------
Else
Msgbox(sizeIndex & " Getting ready to insert", "")
Dim myarray1(sizeIndex+1) As String
Dim i As Int
For i = 0 To sizeIndex
If i = 0 Then
myarray1(i) = "MyInsert"
Msgbox(i & " " & myarray1(i),"")
Else
Cursor1.Position = i-1
myarray1(i) = Cursor1.GetString("qp")
Msgbox(i & " " & myarray1(i),"")
End If
Next
Cursor1.Close
''----------------Display The array!---------
For i = 0 To sizeIndex
Msgbox(i & " New added data in Array " & myarray1(i) ,"")
Next
End If
End Sub
Thank you in advance
Last edited: