SirEvan Posted August 8, 2009 Share Posted August 8, 2009 (edited) I got my database finally working with the app, but now I have a question about optimizations in the code. I currently have the following lines of code set up to update the record in the database each time any control is changed : Me.Validate() Me.USMC_DataBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.USMCDataSet) IT works, but I'd like to try and shorten the ammount of c ode in the program to save space, make things easier to read, etc. How do I declare these 3 lines as a function or something, and then just call it with something like this: UpdateRecord() ? Thanks Edit: Is this correct? Private Sub UpdateRecord() Me.Validate() Me.USMC_DataBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.USMCDataSet) End Sub and then just use "Call UpdateRecord()"? Nevermind, answered my own question. Edited August 8, 2009 by SirEvan Link to comment Share on other sites More sharing options...
0 Mordkanin Posted August 8, 2009 Share Posted August 8, 2009 Just what you said: Put them in a function. Something like Sub UpdateRecord() Me.Validate() Me.USMC_DataBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.USMCDataSet) End Sub Link to comment Share on other sites More sharing options...
0 mitchartz Posted August 8, 2009 Share Posted August 8, 2009 Just what you said: Put them in a function. Something like Sub UpdateRecord() Me.Validate() Me.USMC_DataBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.USMCDataSet) End Sub Yuppers Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted August 9, 2009 Veteran Share Posted August 9, 2009 The keyword "Call" is entirely optional. You can invoke a function by simply typing its name followed by parentheses. Furthermore, you can't use "Call" if the function returns a value and you wish to retrieve it. Link to comment Share on other sites More sharing options...
0 ajua Posted August 9, 2009 Share Posted August 9, 2009 The keyword "Call" is entirely optional. You can invoke a function by simply typing its name followed by parentheses. Furthermore, you can't use "Call" if the function returns a value and you wish to retrieve it. Indeed. Using "Call" is not recommended at all. Just call the function as FunctionName() Link to comment Share on other sites More sharing options...
Question
SirEvan
I got my database finally working with the app, but now I have a question about optimizations in the code. I currently have the following lines of code set up to update the record in the database each time any control is changed :
IT works, but I'd like to try and shorten the ammount of c ode in the program to save space, make things easier to read, etc.
How do I declare these 3 lines as a function or something, and then just call it with something like this:
?
Thanks
Edit: Is this correct?
and then just use "Call UpdateRecord()"?
Nevermind, answered my own question.
Edited by SirEvanLink to comment
Share on other sites
4 answers to this question
Recommended Posts