Results 1 to 15 of 15

Thread: I need help in visual basic 6 with synchronizing commands one after the other

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    8

    I need help in visual basic 6 with synchronizing commands one after the other

    We are working on visual basic 6. We have a normal simple form in which we have a grid and a save button. Note that we are using the fpspread;

    There are many commands to be executed on the key change of the grid... In case system is still functioning and user clicks on the save button, it is starting the save procedure even though the main process of the grid change hasn't finished yet.

    We tried to make disable to the save button at the beginning of the grid change and then enabling it again at its end but when you have many lines in the grid we are still able to press the button in a way or another;

    We tried as well the wait command at the beginning of the save; apparently it s working but not practical solution cause user will have to wait for a while before the save procedure starts... and this time is hard coded where as it will differ from a user to another based on the different validations to be done in the grid.
    Is there a way to make the executions under save button wait and not fire in case still other commands are running?

    Your fast reply is highly appreciated;
    Thank you
    Dolly

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    One method is using a form-level variable. That variable can be used different ways, but basically it is a flag. If the flag is zero, then no actions are in process otherwise the 'Save' button's click event simply exits early, i.e.,
    Code:
    If m_Actions <> 0 Then Exit Sub
    
    m_Actions = [someValue] ' initialize the flag
    ' start the save process
    
    ' at some point, when all actions are finished, m_Actions must be reset to zero
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    8

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    Thank you for your fast reply...
    We tried as well what you proposed... I will explain where it failed..
    In the beginning of the grid change we set a variable "finished" to 0; and at the end of the grid change we set it to 1; on save button we mentioned if finished = 0 exit sub else continue the save process...

    It failed when we were posting many lines in the grid and grid was validating many lines and meanwhile we were pressing save button... at a certain point the variable is being 1 but will be set again to 0 when the validation of the next line starts and if at this moment we press save... hope you got my point...

  4. #4
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    461

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    Then don't set it to be just 1 but increase it by 1, and when that process is finished decrease it by 1. After that you can put a check: If m_Actions > 0 Then Exit Sub
    Last edited by MikiSoft; Feb 5th, 2016 at 01:41 PM.

  5. #5
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    Quote Originally Posted by dollyaouad View Post
    Thank you for your fast reply...
    We tried as well what you proposed... I will explain where it failed..
    In the beginning of the grid change we set a variable "finished" to 0; and at the end of the grid change we set it to 1; on save button we mentioned if finished = 0 exit sub else continue the save process...

    It failed when we were posting many lines in the grid and grid was validating many lines and meanwhile we were pressing save button... at a certain point the variable is being 1 but will be set again to 0 when the validation of the next line starts and if at this moment we press save... hope you got my point...
    It seems clear that you've described exactly where you're defeating your own save protection.

    basically while you're loading the grid with a bunch of changes, every time you load a line - you're disabling your save protection.
    so why are you even using the same variable? use one for the button, and one for the grid change, and check both before allowing the save.

  6. #6
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    >We tried to make disable to the save button at the beginning of the grid change
    Presumably with something like;
    CbSave.Enabled = False
    I expect you have tried a DoEvents or a CbSave.Refresh immediately after that, if not give it a go.

    Another idea would be to make the button invisible/ visible as required.
    Last edited by Magic Ink; Feb 5th, 2016 at 05:30 PM. Reason: Another idea ...

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    8

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    Dear all, I tried all the proposed solutions... still messing in the case below...
    1 - in the beginning of the grid change:
    //Set the variable to false and disable the save button in the toolbar
    blnSave = False
    frmMDMMain.TbrMainMenu.Buttons("btnsave").Enabled = False
    frmMDMMain.MnuSave.Enabled = False

    2 - in the end of the grid change:
    //Set the variable to true and enable the save button in the toolbar
    blnSave = True
    frmMDMMain.TbrMainMenu.Buttons("btnsave").Enabled = True
    frmMDMMain.MnuSave.Enabled = True

    3 - before saving, to do a test on the blnsave variable,
    it should be true to save ( it means that the grid change event is finished)

    SCENARIO:
    we have 3 lines in the grid, we are changing value by copy and past.
    when changing value in line 1 and directly change in line 2 (in a fast way)
    while clicking on the save button many times, it is entering in the grd change event of the
    first line then in the save event before entering the change event of the second line

    PROBLEM:
    The system is saving before finishing the grid change event of the second line

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

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    Just by per chance, is this problem in a simple application that you can share with us by zipping it up and uploading it (Under Go Advanced button, Manage Uploads, follow instructions)? I am wondering why you are using the copy-paste method to put things into your grid. Am also wondering what you are really trying to accomplish with the 'Save' button. Where is the data being saved? Why not save the information when the paste is completed instead of using a button click? So, as my questions may be confusing....to ME, what you are doing is confusing. Would LOVE to see your project uploaded here so I could look at it (along with your instructions on WHAT is being copy-pasted (and from where) into the grid). If you can do this, make sure there is no personal data nor any dll's or .exe files in your zipped program.


    EDIT:--> What is 'fpspread'?

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    8

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    Hi
    It is an ERP solution... a sales invoice... fpsread means far point spread... a grid control... when you open the screen we load for the user the latest invoice data... you click on a button to make your changes and once done you click on another save button to save the data back to the database...
    user may make copy from one line of the grid or even from excel into new lines.... grid includes the details of the invoice like what item, quantity, specifications...
    Hope you got it as I can not upload the entire code...
    Regards

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

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    1-what code is under the button that you click on to make your changes?
    2-what code is under the button that you click to save the data back to the database?

    Edit---I hit the wrong button...let me continue...

    3-When you copy-paste from one 'line' (assuming you mean 'row'), what is selected? One column, multiple column?
    4-Also, if you copy-paste from EXCEL, is just one cell copied at a time, or are multiple cells (in the same row, I am assuming) copied and then pasted to your grid?

    5-As this is a user function (the copy-paste, clicking, etc), I would think that after the user pastes something in, a SAVE button is then clicked (manually). I don't see how/why you would be using change-events of the Grid to do all of this.

    As you cannot upload, it may take a few more questions to determine HOW you are doing this, WHY you are using some methods, and WHAT is the major issue.

    Just trying to understand...
    Last edited by SamOscarBrown; Feb 10th, 2016 at 09:38 AM.

  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    8

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    Hi
    1- code we write under the edit button is to unlock the controls on the screen so the user can enter data and modify them
    2- save button reads from the record set and the screens controls and write them in the tables of the database (sql)
    3- yes you are right.. line means row.. you may copy multiple cells and paste them bulk and even you may copy many columns many rows and make 1 paste...
    4- in the grid change we validate the data entered in the cells to make sure of some business rules like for example in the cell of the item, we make sure the item exists and quantity in stock.... the grid change code was not written specifically for the paste function... it is needed for normal entries as well like when entering manually the data in the fields and we need to validate them... and it fires as well when you make paste in the grid...

    The real issue is that when i try to work very fast as user... and i try to make paste for a cell for example on many lines very fast and i click on the save button many times.... although we have disabled the save button at a certain fraction of second user was able to click it and validation got skipped... hope i made myself clearer this time...

    Thank you

  12. #12
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    You must ensure that the Save button IS disabled or invisible BEFORE the grid change routine gets started, did you try what I suggested in #6.
    Alternatively do all the validation when you click the Save button.
    Last edited by Magic Ink; Feb 11th, 2016 at 04:32 AM.

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

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    Hmmmm....must be a VERY fast user....let me try to understand a bit more....okay, someone pastes in a bunch of cells (multiple rows and columns) on a single paste. You do some cell validation at one point, and then you save the new information in the grid to a DB.

    If your button is disabled (or made invisible) while the validations are taking place, and then enabled (or made visible) at the completion of the code that accomplishes the validations, there should be no problem. I like, however, MI's suggestion...do your validations on the click event (or call a validation sub from there) of the Save button.

  14. #14
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    It kind of sounds like (from post #3), that the enabling and disabling of the button is not done in conjunction with an update to the grid as a whole, i.e I'm going to update the grid so disable the button, update the whole grid, then enable the button.
    It sounds like the update is based on rows, so each updated row is a separate transaction with the button being disabled and reenabled between each row update.

    As the process works through the rows, if the user presses on the button, the button might be disabled, but the event isn't delivered because the row update process is in progress. The pocess of updating that row is done, the button reenabled, and the click event is delivered to the button, and save is done, but the grid update continues with the next row update, disabling the button, updating, reenabling, etc.

    I don't do this type of activity so can't speak with any authority, but it seems that there needs to be a way to make the grid update as a whole a single transaction as far as the button is concerned, rather than disabling/enabling the button each time an individual row is modified.

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

    Re: I need help in visual basic 6 with synchronizing commands one after the other

    Agree with your last statement, passel. In a loop through the Grid's rows, OP should be able to update each 'record' (row), which I would presume would work best in the click_event of the Save button....done one time.

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