Results 1 to 4 of 4

Thread: Fast Code Generators for VB6

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member nepalbinod's Avatar
    Join Date
    Sep 2007
    Posts
    293

    Fast Code Generators for VB6

    Hi friends,

    During my programming hours, I found so many things that consumed a lot of time but it did not include any skills. So, for fast and rapid development, I have created some functions that I use as code generators. They include codes which are basically used on all of the forms and I thought it might be interesting. If you, too, have such generators, please let us all know.

    vb Code:
    1. 'This function generates code for highlighting all the controls of a form ...
    2.  
    3. Public Sub CodeGen_HighLightAllControlsOnFocus(ByVal theForm As Form)
    4.     On Error Resume Next
    5.     Dim Sttr As String
    6.  
    7.     For Each MyControl In theForm.Controls: DoEvents
    8.      
    9.     If TypeOf MyControl Is TextBox Then
    10.       Sttr = Sttr & vbNewLine & HighLightAssistant(MyControl)
    11.      ElseIf TypeOf MyControl Is ComboBox Then
    12.       Sttr = Sttr & vbNewLine & HighLightAssistant(MyControl)
    13.     ElseIf TypeOf MyControl Is ListBox Then
    14.       Sttr = Sttr & vbNewLine & HighLightAssistant(MyControl)
    15.     ElseIf TypeOf MyControl Is MSFORms.TextBox Then
    16.        Sttr = Sttr & vbNewLine & HighLightAssistant(MyControl)
    17.     ElseIf TypeOf MyControl Is MSFORms.ComboBox Then
    18.      Sttr = Sttr & vbNewLine & HighLightAssistant(MyControl)
    19.     ElseIf TypeOf MyControl Is MSFORms.ListBox Then
    20.       Sttr = Sttr & vbNewLine & HighLightAssistant(MyControl)
    21.     End If
    22.     Next
    23.    
    24. frmcodegen.TextBox1.Text = Sttr
    25. ShowForm frmcodegen
    26. 'Create a new form frmcodegen and put a large textbox with multiline enabled.
    27.  
    28. End Sub
    29.  
    30.  
    31. Function HighLightAssistant(ByVal MyControl As Control) As String
    32. Dim sttr1 As String
    33.        sttr1 = sttr1 & vbNewLine & "Private Sub " & MyControl.Name & "_GotFocus()" & vbNewLine & "    " & "HighLight " & MyControl.Name & vbNewLine & "End Sub" & vbNewLine
    34.        sttr1 = sttr1 & vbNewLine & "Private Sub " & MyControl.Name & "_LostFocus()" & vbNewLine & "    " & "UnHighLight " & MyControl.Name & vbNewLine & "End Sub" & vbNewLine
    35.        HighLightAssistant = sttr1
    36. End Function
    37.  
    38. Public Sub ShowForm(ByVal theForm As Form)
    39. On Error GoTo ErrorHandler
    40.  
    41. If theForm.Visible <> True Then
    42.     theForm.Show vbModal
    43. End If
    44.  
    45. Exit Sub
    46. ErrorHandler:
    47. Msgbox Err.Number & vbNewLine & Err.Description
    48. End Sub
    49.  
    50. 'This function generates code for sending tab keys when the Enter button is pressed on controls
    51.  
    52. Public Sub CodeGen_GetKeyDownLines(ByVal theForm As Form)
    53.   Dim Sttr As String
    54.     For Each MyControl In theForm.Controls: DoEvents
    55.       If TypeOf MyControl Is TextBox Then
    56.           Sttr = Sttr & vbNewLine & GetKeyDownLine(MyControl)
    57.         ElseIf TypeOf MyControl Is ComboBox Then
    58.           Sttr = Sttr & vbNewLine & GetKeyDownLine(MyControl)
    59.         ElseIf TypeOf MyControl Is ListBox Then
    60.           Sttr = Sttr & vbNewLine & GetKeyDownLine(MyControl)
    61.         ElseIf TypeOf MyControl Is MSFORms.TextBox Then
    62.            Sttr = Sttr & vbNewLine & GetKeyDownLine(MyControl)
    63.         ElseIf TypeOf MyControl Is MSFORms.ComboBox Then
    64.          Sttr = Sttr & vbNewLine & GetKeyDownLine(MyControl)
    65.         ElseIf TypeOf MyControl Is MSFORms.ListBox Then
    66.           Sttr = Sttr & vbNewLine & "asfd" & GetKeyDownLine(MyControl)
    67.         End If
    68.     Next
    69.    
    70. frmcodegen.TextBox1.Text = Sttr
    71. ShowForm frmcodegen
    72. End Sub
    73.  
    74. Function GetKeyDownLine(ByVal MyControl As Control) As String
    75.     Dim MyStrrr As String
    76.     MyStrrr = "Private Sub " & MyControl.Name & "_KeyDown(KeyCode As Integer, Shift As Integer)"
    77.     MyStrrr = MyStrrr & vbNewLine & "    If KeyCode = 13 Then SendKeys vbTab" & vbNewLine & "End Sub" & vbNewLine
    78.     GetKeyDownLine = MyStrrr
    79. End Function
    80.  
    81.  
    82. 'This function generates code for sizing a grid's width. Just execute the code, size the grid, call this function.  Depending upon the current size of the grid, code will be generated which can be pasted directly into the form as required.  Here, grid refers to MSHFlexGrid
    83.  
    84. Public Sub CodeGen_GRIDSIZE(ByVal MYGRID As MSHFlexGrid)
    85. Dim mytext As String
    86. Dim myrows As Integer
    87. Dim mycols As Integer
    88. Dim i As Integer
    89. Dim j As Integer
    90. mycols = MYGRID.Cols - 1
    91.  
    92. mytext = MYGRID.Name & ".colwidth(0)=300" & vbNewLine
    93.  
    94. For i = 1 To mycols: DoEvents
    95.    
    96.     mytext = mytext & vbNewLine & MYGRID.Name & ".colwidth(" & i & ")=" & MYGRID.ColWidth(i)
    97. Next i
    98. frmcodegen.TextBox1.Text = mytext
    99. ShowForm frmcodegen
    100. End Sub
    Last edited by Hack; Sep 9th, 2007 at 03:54 AM. Reason: Added Code Tags

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