patternMinor
Modified TextBox for forms generating SQL statements
Viewed 0 times
sqlstatementsmodifiedgeneratingtextboxforforms
Problem
An overview of what I've done:
I've inherited
I use to create a large function that would check for changes in the
I've added four properties:
I have not fully implemented the new textbox in my code, but I am working on it.
It may only be slightly modified, but it should cut down my code from 500+ lines of code down to less than +-30 if ran in a for-loop.
SQLTextBox.vb
I've pu
I've inherited
System.Windows.Forms.TextBox and added a few properties to help me out in creating forms that generate SQL statements. I use to create a large function that would check for changes in the
TextBox compared to a string. Then it would take text and concatenate it to a SQL statement. Now it's simple and easier to use. I've added four properties:
- A String property to hold the default string that the textbox is initially set to and will reset back if the text is left empty.
- A String property to hold the text's associated SQL statement.
- A Boolean to check if the text has changed from the default.
- Finally, an Integer to hold an ID if there is a reason to need one, such as saving and loading text from a file by the ID.
I have not fully implemented the new textbox in my code, but I am working on it.
It may only be slightly modified, but it should cut down my code from 500+ lines of code down to less than +-30 if ran in a for-loop.
SQLTextBox.vb
Public Class ModifiedTextBox
Inherits System.Windows.Forms.TextBox
Private _strDefaultText As String
Private _strSqlText As String
Private _nID As Integer
Private _bModified As Boolean = False
Property ID()
Set(nID)
_nID = nID
End Set
Get
Return _nID
End Get
End Property
Property TextModified()
Set(bModified)
_bModified = bModified
End Set
Get
Return _bModified
End Get
End Property
Property SqlText()
Set(strSqlText)
_strSqlText = strSqlText
End Set
Get
Return _strSqlText
End Get
End Property
Property DefaultText()
Set(strDefaultText)
_strDefaultText = strDefaultText
Me.Text = _strDefaultText
End Set
Get
Return _strDefaultText
End Get
End Property
End ClassI've pu
Solution
There's not much to review here really. I'd be more interested in reviewing the code that's actually doing the work, but here goes.
-
Lose the Systems Hungarian notation. The IDE/Code tells me what the data type is. That is if you...
-
Declare the data types of the properties
-
Use auto properties. There's way too much code here for how simple this is.
-
Lose the Systems Hungarian notation. The IDE/Code tells me what the data type is. That is if you...
-
Declare the data types of the properties
-
Use auto properties. There's way too much code here for how simple this is.
Public Class ModifiedTextBox
Inherits System.Windows.Forms.TextBox
Property ID() As Integer
Property TextModified() As Boolean
Property SqlText() As String
Property DefaultText() As String
Set(strDefaultText)
_strDefaultText = strDefaultText
Me.Text = _strDefaultText
End Set
Get
Return _strDefaultText
End Get
End Property
End ClassCode Snippets
Public Class ModifiedTextBox
Inherits System.Windows.Forms.TextBox
Property ID() As Integer
Property TextModified() As Boolean
Property SqlText() As String
Property DefaultText() As String
Set(strDefaultText)
_strDefaultText = strDefaultText
Me.Text = _strDefaultText
End Set
Get
Return _strDefaultText
End Get
End Property
End ClassContext
StackExchange Code Review Q#100733, answer score: 6
Revisions (0)
No revisions yet.