Results 1 to 19 of 19

Thread: [RESOLVED] how to fetch data to msflexgrid at the same time

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    193

    Resolved [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,

  2. #2
    gibra
    Guest

    Re: how to fetch data to msflexgrid at the same time

    We know nothing about your project, so need more info...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    193

    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.

  4. #4
    gibra
    Guest

    Re: how to fetch data to msflexgrid at the same time

    Quote Originally Posted by genlight View Post
    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?

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: how to fetch data to msflexgrid at the same time

    agree with gibra....how about showing your six functions?

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,871

    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.

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    193

    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

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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?

  11. #11
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,871

    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.

  12. #12
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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

  14. #14
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    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

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    193

    Re: how to fetch data to msflexgrid at the same time

    datamiser, it only involves 500 records

  16. #16
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: how to fetch data to msflexgrid at the same time

    Quote Originally Posted by genlight View Post
    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

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    193

    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

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    193

    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.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    193

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width