 |
|
 |
admin Level: Administrator

 Registered: 04-04-2002 Posts: 530
|
Re: Sorting Data
you don't have to open the query inside the For...Next loop or it will restart from the first row of the table...
try something like this:
Dim myarray() As Variant
ReDim Preserve myarray(Module1.totalrem, 1)
adoSortWeight.Open "SELECT * FROM Table_Of_Weightage ORDER BY Rem_Weight DESC", adoConnHomeo
For i = 0 To Module1.totalrem - 1 Step 1
myarray(i, 0) = adoSortWeight!Rem_Abbr
myarray(i, 1) = adoSortWeight!Rem_Weight
frmremedies.lstunsort.AddItem myarray(i, 0) & "----" & myarray(i, 1)
adoSortWeight.MoveNext
Next i
adoSortWeight.Close
|
you can also increment totalrem while you browse your recordset...the code changes this way:
Dim myarray() As Variant
adoSortWeight.Open "SELECT * FROM Table_Of_Weightage ORDER BY Rem_Weight DESC", adoConnHomeo
Module1.totalrem=0
do while not adoSortWeight.EOF
ReDim Preserve myarray(Module1.totalrem, 1)
myarray(Module1.totalrem, 0) = adoSortWeight!Rem_Abbr
myarray(Module1.totalrem, 1) = adoSortWeight!Rem_Weight
frmremedies.lstunsort.AddItem myarray(Module1.totalrem, 0) & "----" & myarray(Module1.totalrem, 1)
Module1.totalrem=Module1.totalrem+1
adoSortWeight.MoveNext
Next i
adoSortWeight.Close
|
[Edited by admin on 21-02-2006 at 05:08 PM GMT]
____________________________
AndreaVB
|
|
21-02-2006 at 04:04 PM |
|
|
niyati Level: Scholar
 Registered: 01-02-2006 Posts: 35
|
Re: Sorting Data
quote: admin wrote:
you don't have to open the query inside the For...Next loop or it will restart from the first row of the table...
try something like this:
Dim myarray() As Variant
ReDim Preserve myarray(Module1.totalrem, 1)
adoSortWeight.Open "SELECT * FROM Table_Of_Weightage ORDER BY Rem_Weight DESC", adoConnHomeo
For i = 0 To Module1.totalrem - 1 Step 1
myarray(i, 0) = adoSortWeight!Rem_Abbr
myarray(i, 1) = adoSortWeight!Rem_Weight
frmremedies.lstunsort.AddItem myarray(i, 0) & "----" & myarray(i, 1)
adoSortWeight.MoveNext
Next i
adoSortWeight.Close
|
you can also increment totalrem while you browse your recordset...the code changes this way:
Dim myarray() As Variant
adoSortWeight.Open "SELECT * FROM Table_Of_Weightage ORDER BY Rem_Weight DESC", adoConnHomeo
Module1.totalrem=0
do while not adoSortWeight.EOF
ReDim Preserve myarray(Module1.totalrem, 1)
myarray(Module1.totalrem, 0) = adoSortWeight!Rem_Abbr
myarray(Module1.totalrem, 1) = adoSortWeight!Rem_Weight
frmremedies.lstunsort.AddItem myarray(Module1.totalrem, 0) & "----" & myarray(Module1.totalrem, 1)
Module1.totalrem=Module1.totalrem+1
adoSortWeight.MoveNext
Next i
adoSortWeight.Close
|
[Edited by admin on 21-02-2006 at 05:08 PM GMT]
Hye
Thankyou so much for you r reply
Yes it is working but now there is another problem which is
in the first time when someone agrees for a symptom to be present... the medicine database is updated and according to your code displayed in the descending order in the listbox i.e 654 medicines.
But that happens the first time.
When once again a new symptom is said yes for then the count of the medicines is getting doubled up i.e 1308 which should not be happening.
That means i have to blank out the array at the end when it is used fully.
Here i wish to get only the latest updations or updated table not the additions of previous ones.
Here is my code now
Dim myarray() As Variant
With adoSortWeight
.CursorLocation = adUseClient
.Open "SELECT Rem_Abbr,Rem_Weight FROM Table_Of_Weightage ORDER BY Rem_Weight DESC", adoConnHomeo, adOpenKeyset, adLockReadOnly
MsgBox .RecordCount
End With
ReDim Preserve myarray(adoSortWeight.RecordCount, 1)
For i = 0 To adoSortWeight.RecordCount - 1 Step 1
myarray(i, 0) = adoSortWeight!Rem_Abbr
myarray(i, 1) = adoSortWeight!Rem_Weight
frmremedies.lstunsort.AddItem myarray(i, 0) & "----" & myarray(i, 1)
adoSortWeight.MoveNext
Next i
MsgBox (frmremedies.lstunsort.ListCount)
adoSortWeight.Close
I should be getting the new updated table only ...
What can i do
Thanks
waiting for your reply
Niyati
|
|
22-02-2006 at 01:47 PM |
|
|
niyati Level: Scholar
 Registered: 01-02-2006 Posts: 35
|
Re: Sorting Data
quote: steve_w wrote:
quote: ...i am going mad..
No more than the rest of us.
Post your code up as it is now and i'll take a look.
Cheers
here is a part of the code...I am sorry for the trouble but you see this is the only way i am trying to learn...
Private Sub cmdYes_Click()
Set adoSortWeight = New ADODB.Recordset
frmremedies.lstunsort.clear
Dim myarray() As Variant
With adoSortWeight
.CursorLocation = adUseClient
.Open "SELECT Rem_Abbr,Rem_Weight FROM Table_Of_Weightage ORDER BY Rem_Weight DESC", adoConnHomeo, adOpenKeyset, adLockReadOnly
MsgBox .RecordCount
End With
ReDim Preserve myarray(adoSortWeight.RecordCount, 1)
For i = 0 To adoSortWeight.RecordCount - 1 Step 1
myarray(i, 0) = adoSortWeight!Rem_Abbr
myarray(i, 1) = adoSortWeight!Rem_Weight
frmremedies.lstunsort.AddItem myarray(i, 0) & " " & myarray(i, 1)
adoSortWeight.MoveNext
Next i
MsgBox (frmremedies.lstunsort.ListCount)
adoSortWeight.Close
'This code is for finding and displaying the new question
QuesIdYes = adoRecQues!Rem_Yes
MsgBox (QuesIdYes)
adoRecQues.Find "Ques_Id_no='" & adoRecQues.Fields("Rem_Yes") & "'", adSearchForward
lblquestions.Caption = adoRecQues!Questions
end sub
Hey i tried something .....new
what i did was that the statement frmremedies.lstunsort.clear i put it right at the start of the click of the yes button...
Howz that?
WIll this give me any kind of bugs later on in the program...
|
|
23-02-2006 at 02:16 PM |
|
|
|
|
 |
 |