-
Feb 16th, 2017, 09:38 PM
#1
Thread Starter
Addicted Member
[RESOLVED] how to fetch data to msflexgrid at the same time
Hi, I am using stored procedure to get data and present them to msflexgrid upon form load.
My problem is, I fetch data for 6 msflexgrid and so my sub code calls them like
call getrequestfile
call getprocessrequestfile
call getwithresultsfile
etc....
In that way, it takes time to load all of them. So my question is, what way could I do so that all of the msflexgrid will be filled at the same time.
Regards,
-
Feb 17th, 2017, 04:09 AM
#2
Re: how to fetch data to msflexgrid at the same time
We know nothing about your project, so need more info...
-
Feb 17th, 2017, 06:40 AM
#3
Thread Starter
Addicted Member
Re: how to fetch data to msflexgrid at the same time
Hi gibra, what information do you need more?
Basically, my problem is, I just need to get the data for each msflexgrid at the same time because each call to fill each of the msflexgrid will spend around 2 seconds or more depending of the number of records.
-
Feb 17th, 2017, 07:01 AM
#4
Re: how to fetch data to msflexgrid at the same time
agree with gibra....how about showing your six functions?
-
Feb 17th, 2017, 07:10 AM
#5
Re: how to fetch data to msflexgrid at the same time
it sounds like the subs get the data and fill the grids... so the "Solution" is ... don't do that... jsut get the data and put it somewhere safe, then add it (assuming binding and not a loop and add method) later in the code...
-tg
-
Feb 17th, 2017, 07:57 AM
#6
Re: how to fetch data to msflexgrid at the same time
How is the data presented to the user?
6 grids on a single form?
You could after the first set of data is loaded already show the form and start loading the content of the other 5 grids.
-
Feb 17th, 2017, 08:03 AM
#7
Re: how to fetch data to msflexgrid at the same time
Originally Posted by genlight
Hi gibra, what information do you need more?
Basically, my problem is, I just need to get the data for each msflexgrid at the same time because each call to fill each of the msflexgrid will spend around 2 seconds or more depending of the number of records.
Your explanation has no meaning.
If you want to be helped, you must illustrate the scenario; especially where data and how to recover them.
You use a MSFlexGrid or a MSHFlexGrid?
-
Feb 17th, 2017, 08:38 AM
#8
Re: how to fetch data to msflexgrid at the same time
My guess would be that it is reading a text file one line or worse one field at a time and stuffing it into the grid.
As to the solution reading the entire file at once will speed it up but you can't do all these things at once. VB is a single threaded system which means it does one thing at a time. You can add multithreading but you still only have one thread for the UI so even then you can not use multiple threads to effect the UI.
What you can do is write the code in such a way that speed is not an issue but since you have shown no code it is hard to give any suggestions as to what you are doing wrong. All we can do is guess.
-
Feb 17th, 2017, 09:04 AM
#9
Thread Starter
Addicted Member
Re: how to fetch data to msflexgrid at the same time
Hi,
My data comes from mysql database. I am on mobile now do I cant give the code I used.
What I did was on form load, I call 6 sub routine procedures that uses recordset and stored procedure to fetch the records and place to msflexgrid. all of the msflexgrid are on one form. its like what arnoutdv said, but that causes loading data to msflexgrid one by one while I need to populate all msflexgrid all at once at same time.
its like
private sub form load
call populate grid1
...
call populate grid 6
end sub
-
Feb 17th, 2017, 09:41 AM
#10
Re: how to fetch data to msflexgrid at the same time
You can't really populate them at the same time.
I mean you could loop through and add one record to grid1 then 1 record to grid 2 and so on then move to the next record for each grid which sort of is doing them at the same time but not really.
How are you adding the data to the grids? Are you using binding or are you using a loop to add the data and if using a loop then what method are you using to add the data, one field at a time or one row at a time or?
How many records are we talking about here?
-
Feb 17th, 2017, 10:24 AM
#11
Re: how to fetch data to msflexgrid at the same time
Normally populating the FlexGrid(s) shouldn't be a problem, unless you have 100K records or more.
So either the way you populate the FlexGrid or the actual queries you execute are causing the delays.
-
Feb 17th, 2017, 11:01 AM
#12
Re: how to fetch data to msflexgrid at the same time
Yeah generally it is pretty quick even when using the .TextMatrix(row,col) to populate but the .additem() method is generally faster.
If the op is looping through a recordset and adding each fields data using the .textmatrix property then there could be a noticeable speed increase by using something more like this.
Code:
Dim strData() As String, X As Long
RS.Open "select * from tblsales", CN, adOpenForwardOnly, adLockOptimistic
If Not RS.EOF Then
strData = Split(RS.GetString(adClipString, RS.RecordCount, vbTab, vbCr, "Null"), vbCr)
MSHFlexGrid1.Cols = RS.Fields.Count
For X = 0 To UBound(strData)
MSHFlexGrid1.AddItem strData(X)
Next
End If
RS.Close
-
Feb 17th, 2017, 11:06 AM
#13
Re: how to fetch data to msflexgrid at the same time
Another option that can speed things up a lot when dealing with larger data sets is to set the .redraw property of the grid to false before adding data and back to true when data adding has been completed.
Code:
Private Sub Command1_Click()
Dim strData() As String, X As Long
RS.Open "select * from tblsales", CN, adOpenForwardOnly, adLockOptimistic
MSHFlexGrid1.Redraw = False
If Not RS.EOF Then
strData = Split(RS.GetString(adClipString, RS.RecordCount, vbTab, vbCr, "Null"), vbCr)
MSHFlexGrid1.Cols = RS.Fields.Count
For X = 0 To UBound(strData)
MSHFlexGrid1.AddItem strData(X)
Next
End If
MSHFlexGrid1.Redraw = True
RS.Close
End Sub
-
Feb 17th, 2017, 06:35 PM
#14
Re: how to fetch data to msflexgrid at the same time
And, if this is a program for someone else, show them a splash screen, and while it is visible, load your grids "in the background", then unload the splash screen. Unless you are talking LOTS AND LOTS of records (as mentioned above), OR your queries are taking exceeding long for some reason (again, without the code, it is hard to give advice), then the time for loading six grids should be pretty minimal. Take the advice given by others to 'speed up' your processes, and if that doesn't work, use a splash screen. I know it is not optimal, but at least it takes the user's mind off 'why is this taking so long?'.
Sammi
-
Feb 17th, 2017, 11:15 PM
#15
Thread Starter
Addicted Member
Re: how to fetch data to msflexgrid at the same time
if i cant really populate them at the same time maybe i should check how long the stored procedure executes.
is there a way to get how long a query execute?
-
Feb 17th, 2017, 11:20 PM
#16
Thread Starter
Addicted Member
Re: how to fetch data to msflexgrid at the same time
datamiser, it only involves 500 records
-
Feb 17th, 2017, 11:22 PM
#17
Thread Starter
Addicted Member
Re: how to fetch data to msflexgrid at the same time
sammi, yes i am already using splash screen which takes a long time which i want to eliminate.
-
Feb 18th, 2017, 02:12 AM
#18
Re: how to fetch data to msflexgrid at the same time
Originally Posted by genlight
datamiser, it only involves 500 records
Then you definitely need to show us how you are loading the data. 500 records should load very quickly
-
Feb 26th, 2017, 04:07 AM
#19
Thread Starter
Addicted Member
Re: how to fetch data to msflexgrid at the same time
thanks all. I tested and tested by code and there was no error on my codes. The problem causing some seconds to process before presenting the data was the formatting of the grid which uses dll. I removed the use of dll and directly store the formatting code on the app code.
so I am closing this thread as resolved now. thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|