• 0

[VB/VS2008] How do I declare a set of commands once


Question

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 by SirEvan
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

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

  • 0
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

  • 0

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

  • 0
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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.