home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Format SQL188454262001.psc / frmStringFormat.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-04-26  |  28.9 KB  |  888 lines

  1. VERSION 5.00
  2. Begin VB.Form frmStringFormat 
  3.    Caption         =   "Format SQL v2.0"
  4.    ClientHeight    =   7860
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   8520
  8.    Icon            =   "frmStringFormat.frx":0000
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   7860
  11.    ScaleWidth      =   8520
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.CommandButton CmdClearAll 
  14.       Caption         =   "Clear All"
  15.       Height          =   390
  16.       Left            =   2550
  17.       TabIndex        =   19
  18.       Top             =   7350
  19.       Width           =   990
  20.    End
  21.    Begin VB.CommandButton cmdCancel 
  22.       Caption         =   "Cancel"
  23.       Height          =   390
  24.       Left            =   7425
  25.       TabIndex        =   14
  26.       Top             =   7350
  27.       Width           =   990
  28.    End
  29.    Begin VB.CommandButton cmdOK 
  30.       Caption         =   "OK"
  31.       Height          =   390
  32.       Left            =   6375
  33.       TabIndex        =   13
  34.       Top             =   7350
  35.       Width           =   990
  36.    End
  37.    Begin VB.Frame fOutput 
  38.       Caption         =   "Output"
  39.       Height          =   615
  40.       Left            =   150
  41.       TabIndex        =   10
  42.       Top             =   7200
  43.       Width           =   2265
  44.       Begin VB.OptionButton optFile 
  45.          Caption         =   "Notepad"
  46.          Height          =   315
  47.          Left            =   1200
  48.          TabIndex        =   12
  49.          Top             =   225
  50.          Width           =   915
  51.       End
  52.       Begin VB.OptionButton optClipBoard 
  53.          Caption         =   "Clipboard"
  54.          Height          =   315
  55.          Left            =   150
  56.          TabIndex        =   11
  57.          Top             =   225
  58.          Value           =   -1  'True
  59.          Width           =   1065
  60.       End
  61.    End
  62.    Begin VB.CommandButton cmdFormat 
  63.       Caption         =   "Format String"
  64.       BeginProperty Font 
  65.          Name            =   "Arial"
  66.          Size            =   9
  67.          Charset         =   0
  68.          Weight          =   700
  69.          Underline       =   0   'False
  70.          Italic          =   0   'False
  71.          Strikethrough   =   0   'False
  72.       EndProperty
  73.       Height          =   375
  74.       Left            =   2400
  75.       TabIndex        =   9
  76.       Top             =   4035
  77.       Width           =   3735
  78.    End
  79.    Begin VB.Frame fOptions 
  80.       Caption         =   "Options"
  81.       BeginProperty Font 
  82.          Name            =   "Arial"
  83.          Size            =   9
  84.          Charset         =   0
  85.          Weight          =   400
  86.          Underline       =   0   'False
  87.          Italic          =   0   'False
  88.          Strikethrough   =   0   'False
  89.       EndProperty
  90.       Height          =   885
  91.       Left            =   2040
  92.       TabIndex        =   6
  93.       Top             =   150
  94.       Width           =   6375
  95.       Begin VB.CheckBox ckContinue 
  96.          Caption         =   "Line Continuation"
  97.          Height          =   240
  98.          Left            =   360
  99.          TabIndex        =   18
  100.          Top             =   525
  101.          Value           =   1  'Checked
  102.          Width           =   1665
  103.       End
  104.       Begin VB.TextBox txtLineLen 
  105.          Alignment       =   2  'Center
  106.          Height          =   315
  107.          Left            =   4350
  108.          TabIndex        =   17
  109.          Text            =   "30"
  110.          Top             =   450
  111.          Width           =   390
  112.       End
  113.       Begin VB.CheckBox ckQuotes 
  114.          Caption         =   "Double Quotes to Single Quotes"
  115.          Height          =   255
  116.          Left            =   3300
  117.          TabIndex        =   8
  118.          Top             =   225
  119.          Value           =   1  'Checked
  120.          Width           =   2895
  121.       End
  122.       Begin VB.CheckBox ckVarible 
  123.          Caption         =   "Make Variable"
  124.          Height          =   255
  125.          Left            =   360
  126.          TabIndex        =   7
  127.          Top             =   240
  128.          Value           =   1  'Checked
  129.          Width           =   1575
  130.       End
  131.       Begin VB.Label lblLineLen 
  132.          Caption         =   "Line Length:"
  133.          Height          =   240
  134.          Left            =   3300
  135.          TabIndex        =   16
  136.          Top             =   525
  137.          Width           =   990
  138.       End
  139.    End
  140.    Begin VB.TextBox txtNewString 
  141.       BeginProperty Font 
  142.          Name            =   "Arial"
  143.          Size            =   9
  144.          Charset         =   0
  145.          Weight          =   400
  146.          Underline       =   0   'False
  147.          Italic          =   0   'False
  148.          Strikethrough   =   0   'False
  149.       EndProperty
  150.       Height          =   2655
  151.       Left            =   120
  152.       MultiLine       =   -1  'True
  153.       ScrollBars      =   3  'Both
  154.       TabIndex        =   2
  155.       Top             =   4440
  156.       Width           =   8295
  157.    End
  158.    Begin VB.TextBox txtOldString 
  159.       BeginProperty Font 
  160.          Name            =   "Arial"
  161.          Size            =   9
  162.          Charset         =   0
  163.          Weight          =   400
  164.          Underline       =   0   'False
  165.          Italic          =   0   'False
  166.          Strikethrough   =   0   'False
  167.       EndProperty
  168.       Height          =   2655
  169.       Left            =   120
  170.       MultiLine       =   -1  'True
  171.       ScrollBars      =   3  'Both
  172.       TabIndex        =   1
  173.       Top             =   1320
  174.       Width           =   8295
  175.    End
  176.    Begin VB.TextBox txtVar 
  177.       BeginProperty Font 
  178.          Name            =   "Arial"
  179.          Size            =   9
  180.          Charset         =   0
  181.          Weight          =   400
  182.          Underline       =   0   'False
  183.          Italic          =   0   'False
  184.          Strikethrough   =   0   'False
  185.       EndProperty
  186.       Height          =   285
  187.       Left            =   120
  188.       TabIndex        =   0
  189.       Text            =   "strSQL"
  190.       Top             =   480
  191.       Width           =   1815
  192.    End
  193.    Begin VB.Label Label3 
  194.       Caption         =   "http://www.cshellvb.com"
  195.       Height          =   240
  196.       Left            =   3600
  197.       TabIndex        =   21
  198.       Top             =   7500
  199.       Width           =   2715
  200.    End
  201.    Begin VB.Label Label2 
  202.       Caption         =   "Written By: Chris Shell"
  203.       Height          =   240
  204.       Left            =   3600
  205.       TabIndex        =   20
  206.       Top             =   7200
  207.       Width           =   2715
  208.    End
  209.    Begin VB.Label Label1 
  210.       Caption         =   "Label1"
  211.       Height          =   315
  212.       Left            =   3300
  213.       TabIndex        =   15
  214.       Top             =   375
  215.       Width           =   1665
  216.    End
  217.    Begin VB.Label lblNewString 
  218.       Caption         =   "New String:"
  219.       BeginProperty Font 
  220.          Name            =   "Arial"
  221.          Size            =   9
  222.          Charset         =   0
  223.          Weight          =   400
  224.          Underline       =   0   'False
  225.          Italic          =   0   'False
  226.          Strikethrough   =   0   'False
  227.       EndProperty
  228.       Height          =   255
  229.       Left            =   120
  230.       TabIndex        =   5
  231.       Top             =   4080
  232.       Width           =   1335
  233.    End
  234.    Begin VB.Label lOldText 
  235.       Caption         =   "String to be Formatted:"
  236.       BeginProperty Font 
  237.          Name            =   "Arial"
  238.          Size            =   9
  239.          Charset         =   0
  240.          Weight          =   400
  241.          Underline       =   0   'False
  242.          Italic          =   0   'False
  243.          Strikethrough   =   0   'False
  244.       EndProperty
  245.       Height          =   255
  246.       Left            =   120
  247.       TabIndex        =   4
  248.       Top             =   960
  249.       Width           =   1950
  250.    End
  251.    Begin VB.Label lVar 
  252.       Caption         =   "Varible Name:"
  253.       BeginProperty Font 
  254.          Name            =   "Arial"
  255.          Size            =   9
  256.          Charset         =   0
  257.          Weight          =   400
  258.          Underline       =   0   'False
  259.          Italic          =   0   'False
  260.          Strikethrough   =   0   'False
  261.       EndProperty
  262.       Height          =   255
  263.       Left            =   120
  264.       TabIndex        =   3
  265.       Top             =   120
  266.       Width           =   1215
  267.    End
  268. Attribute VB_Name = "frmStringFormat"
  269. Attribute VB_GlobalNameSpace = False
  270. Attribute VB_Creatable = False
  271. Attribute VB_PredeclaredId = True
  272. Attribute VB_Exposed = False
  273. Option Explicit
  274. ' *************************************************************
  275. '  Format String
  276. '  Chris Shell
  277. '  http://www.cshellvb.com
  278. ' *************************************************************
  279. '  Author grants royalty-free rights to use this code within
  280. '  compiled applications. Selling or otherwise distributing
  281. '  this source code is not allowed without author's express
  282. '  permission.
  283. ' *************************************************************
  284. Const DIM_STR1 As String = "Dim "
  285. Const DIM_STR2 As String = " as String"
  286. Const CONT_STR As String = " & _"
  287. Const CONNECT_STR As String = " & "
  288. Const SELECT_STR As String = "SELECT "
  289. Const FROM_STR As String = " FROM "
  290. Const WHERE_STR As String = " WHERE "
  291. Const GROUPBY_STR As String = " GROUP BY "
  292. Const UPDATE_STR As String = "UPDATE "
  293. Const INSERT_STR As String = "INSERT INTO "
  294. Const DELETE_STR As String = "DELETE "
  295. Dim aSQLVar() As Integer
  296. '**************************************
  297. 'Windows API/Global Declarations for :
  298. 'Create links from labels!
  299. '**************************************
  300. Public Enum OpType
  301.     Startup = 1
  302.     Click = 2
  303.     FormMove = 3
  304.     LinkMove = 4
  305. End Enum
  306. Dim Clicked As Boolean
  307. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  308. Public Function FormatString(sOld As String, bSQLSmart As Boolean, bContinue As Boolean, _
  309.     iLineCnt As Integer, sVariable As String, bFixQuotes As Boolean) As String
  310. Dim lStrLen As Integer
  311. Dim lcv As Integer, lCnt As Integer
  312. Dim StartPos As Integer, EndPos As Integer
  313. Dim sVar As String
  314. Dim sPart As String
  315. Dim iSQLCnt As Integer, iSQLLen As Integer
  316. Dim iSELECT As Integer, iFROM As Integer, iWHERE As Integer, iGROUPBY As Integer
  317. Dim iUPDATE As Integer, iINSERT As Integer, iDELETE As Integer
  318. '********************************************
  319. 'This class was written by:
  320. '   Karl E. Peterson
  321. '   http://www.mvps.org/vb/
  322. 'See the class for more detail. Thank you to
  323. 'him for this code, I got it via VBPJ Article
  324. 'on string building in ASP.
  325. '********************************************
  326. Dim cSBld As New CStringBuilder
  327. 'Chr(34) = "
  328. 'Chr(39) = '
  329. On Error GoTo ehHandle
  330.         
  331.     '********************************************
  332.     'Clean up String before we begin...
  333.     '********************************************
  334.         'Remove Tab Characters
  335.         sOld = RemoveChar(sOld, CStr(vbTab))
  336.         'Remove Vertical Tab Characters
  337.         'sOld = RemoveChar(sOld, vbVerticalTab)
  338.         'Remove Carriage Returns
  339.         sOld = Replace(sOld, CStr(vbCr), " ")
  340.         'Remove Line Feeds
  341.         sOld = RemoveChar(sOld, CStr(vbLf))
  342.         'Remove extra Spaces
  343.         sOld = Trim(sOld)
  344.         
  345.         
  346.     '********************************************
  347.     'Ready to Rock...
  348.     '********************************************
  349.        
  350.     'Replace any quotes with single quotes if desired
  351.     If bFixQuotes = True Then
  352.         sOld = CleanString(sOld)
  353.     End If
  354.     'Store original length
  355.     lStrLen = Len(sOld)
  356.     'If a variable is given te use it...
  357.     If Len(sVariable) > 0 Then
  358.         sVar = sVariable
  359.         cSBld.Append DIM_STR1 & sVar & DIM_STR2 & vbCrLf & vbCrLf
  360.     Else
  361.         sVar = "strSQL"
  362.     End If
  363.     'Place some space between the declare and the code
  364.     cSBld.Append vbCrLf & vbTab
  365.     'Set initial values prior to loop
  366.     StartPos = 1
  367.     lCnt = 0
  368.     iSQLCnt = 0
  369.         
  370.     'Essentially, we go through each character iin the string (VB does this nicely).
  371.     'If we reach are character count (iLineCnt) then we make a new line.
  372.     'We do this until we reach the end...
  373.     For lcv = 0 To lStrLen
  374.             lCnt = lCnt + 1
  375.             
  376.             If lcv = 0 Then
  377.                     cSBld.Append sVar & " = "
  378.             End If
  379.             
  380.             If bSQLSmart Then
  381.                If (lCnt = aSQLVar(iSQLCnt)) Then
  382.                     If iSQLCnt = 0 Then
  383.                                        
  384.                     End If
  385.                     iSQLCnt = iSQLCnt + 1
  386.                     
  387.                End If
  388.                
  389.             End If
  390.                         
  391.             If (lCnt = iLineCnt) Or (lcv >= lStrLen) Then
  392.                 lCnt = 0
  393.                 
  394.                 If bContinue Then
  395.                     'Are we at the End
  396.                     If (lcv >= lStrLen) Then
  397.                         cSBld.Append Chr(34) & Mid(sOld, StartPos, (lStrLen - lcv)) & Chr(34)
  398.                     Else
  399.                         cSBld.Append Chr(34) & Mid(sOld, StartPos, iLineCnt) & Chr(34) & CONT_STR
  400.                     End If
  401.                 Else
  402.                     'Are we at the End
  403.                     If (lcv >= lStrLen) Then
  404.                         cSBld.Append sVar & " = " & sVar & CONNECT_STR & _
  405.                             Chr(34) & Mid(sOld, StartPos, (lStrLen - lcv)) & Chr(34)
  406.                     Else
  407.                         cSBld.Append sVar & " = " & sVar & CONNECT_STR & _
  408.                             Chr(34) & Mid(sOld, StartPos, iLineCnt) & Chr(34)
  409.                     End If
  410.                 
  411.                 
  412.                 End If
  413.                 
  414.                 iLineCnt = iLineCnt + 1
  415.                 
  416.                 If StartPos = 1 Then
  417.                     StartPos = lcv + 2
  418.                 Else
  419.                     StartPos = lcv + 1
  420.                 End If
  421.                 
  422.                 cSBld.Append vbCrLf
  423.                                 
  424.             End If
  425.             
  426.     Next lcv
  427.     'Pass the String Back...
  428.     FormatString = cSBld.ToString
  429.     Set cSBld = Nothing
  430. ExitFunc:
  431.     Exit Function
  432. ehHandle:
  433.     MsgBox "ERROR: " & Err.Number & " - " & Err.Description
  434.     Resume Next
  435. End Function
  436. Function CleanString(szOriginal)
  437.     If szOriginal = "" Then
  438.         CleanString = "NULL"
  439.     Else
  440.         CleanString = Substitute(szOriginal, "'", "''")
  441.         CleanString = Substitute(CleanString, "
  442.     End If
  443. End Function
  444. Private Sub cmdCancel_Click()
  445.     Unload Me
  446. End Sub
  447. Private Sub CmdClearAll_Click()
  448.     If MsgBox("Clear all text boxes?", vbYesNo + vbQuestion, "Clear") = vbYes Then
  449.         txtNewString.Text = ""
  450.         txtOldString.Text = ""
  451.         
  452.     End If
  453.     Me.Refresh
  454. End Sub
  455. Private Sub cmdFormat_Click()
  456. Dim bContinue As Boolean, sVar As String
  457. Dim bQuote As Boolean, iCnt As Integer, bSQLSmart As Boolean
  458.     bContinue = False
  459.     sVar = ""
  460.     bQuote = False
  461.     bSQLSmart = False
  462.     If Len(txtOldString.Text) = 0 Then
  463.         MsgBox "No String entered!", vbExclamation
  464.         Exit Sub
  465.     End If
  466. '    If ckSQLSmart.Value = vbChecked Then
  467. '       bSQLSmart = True
  468. '    End If
  469.     If ckContinue.Value = vbChecked Then
  470.        bContinue = True
  471.     End If
  472.     If ckQuotes.Value = vbChecked Then
  473.         bQuote = True
  474.     End If
  475.     If ckVarible.Value = vbChecked Then
  476.         sVar = txtVar.Text
  477.     End If
  478.     If IsNumeric(txtLineLen.Text) Then
  479.         iCnt = CInt(txtLineLen.Text)
  480.     Else
  481.         iCnt = 50
  482.     End If
  483.         
  484.     'txtNewString.Text = FormatString(txtOldString.Text, False, bContinue, iCnt, sVar, bQuote)
  485.     txtNewString.Text = FormatSQL(txtOldString.Text, True, bContinue, iCnt, sVar, bQuote)
  486. End Sub
  487. Function Substitute(szBuff, szOldString, szNewString)
  488.     Dim iStart
  489.     Dim iEnd
  490.     ''' Find first substring
  491.     iStart = InStr(1, szBuff, szOldString)
  492.     ''' Loop through finding substrings
  493.     Do While iStart <> 0
  494.         ''' Find end of string
  495.         iEnd = iStart + Len(szOldString)
  496.         ''' Concatenate new string
  497.         szBuff = Left(szBuff, iStart - 1) & szNewString & Right(szBuff, Len(szBuff) - iEnd + 1)
  498.         ''' Advance past new string
  499.         iStart = iStart + Len(szNewString)
  500.         ''' Find next occurrence
  501.         iStart = InStr(iStart, szBuff, szOldString)
  502.     Loop
  503.     Substitute = szBuff
  504. End Function
  505. Function RemoveChar(sText As String, sChar As String) As String
  506.     Dim iPos As Integer, iStart As Integer
  507.     Dim sTemp As String
  508.     iStart = 1
  509.     Do
  510.         iPos = InStr(iStart, sText, sChar)
  511.         If iPos <> 0 Then
  512.             sTemp = sTemp & Mid(sText, iStart, (iPos - iStart))
  513.             iStart = iPos + 1
  514.         End If
  515.     Loop Until iPos = 0
  516.     sTemp = sTemp & Mid(sText, iStart)
  517.     RemoveChar = sTemp
  518. End Function
  519. Sub SQLVarPos(ByVal sSQL As String)
  520. Dim lcv As Integer
  521. Dim iPos As Integer
  522. Dim iLen As Integer
  523. On Error GoTo ehHandle
  524.     ReDim aSQLVar(3, 1)
  525.     Debug.Print sSQL
  526.     iLen = 0
  527.     '1 SELECT, INSERT, UPDATE, or DELETE
  528.     iPos = InStr(1, UCase(sSQL), SELECT_STR)
  529.         
  530.     If iPos = 0 Then
  531.         iPos = InStr(1, UCase(sSQL), INSERT_STR)
  532.         
  533.         If iPos = 0 Then
  534.             iPos = InStr(1, UCase(sSQL), UPDATE_STR)
  535.             
  536.             If iPos = 0 Then
  537.                 iPos = InStr(1, UCase(sSQL), DELETE_STR)
  538.             Else
  539.                 iLen = Len(UPDATE_STR)
  540.             End If
  541.             
  542.             If iPos <> 0 Then
  543.                 iLen = Len(DELETE_STR)
  544.             End If
  545.         Else
  546.             iLen = Len(INSERT_STR)
  547.         End If
  548.     Else
  549.         iLen = Len(SELECT_STR)
  550.     End If
  551.     If iPos > 0 Then
  552.         aSQLVar(0, 0) = iPos
  553.         aSQLVar(0, 1) = iLen
  554.         
  555.     Else
  556.         aSQLVar(0, 0) = -1
  557.         aSQLVar(0, 1) = 0
  558.     End If
  559.             
  560.     '2 FROM Clause
  561.     iPos = InStr(1, UCase(sSQL), FROM_STR)
  562.     iLen = Len(FROM_STR)
  563.     If iPos > 0 Then
  564.         aSQLVar(1, 0) = iPos
  565.         aSQLVar(1, 1) = iLen
  566.         
  567.     Else
  568.         aSQLVar(1, 0) = -1
  569.         aSQLVar(1, 1) = 0
  570.     End If
  571.     '3 WHERE Clause
  572.     iPos = InStr(1, UCase(sSQL), WHERE_STR)
  573.     iLen = Len(WHERE_STR)
  574.     If iPos > 0 Then
  575.         aSQLVar(2, 0) = iPos
  576.         aSQLVar(2, 1) = iLen
  577.         
  578.     Else
  579.         aSQLVar(2, 0) = -1
  580.         aSQLVar(2, 1) = 0
  581.     End If
  582.             
  583.     '4 GROUP BY Clause
  584.     iPos = InStr(1, UCase(sSQL), GROUPBY_STR)
  585.     iLen = Len(GROUPBY_STR)
  586.     If iPos > 0 Then
  587.         aSQLVar(3, 0) = iPos
  588.         aSQLVar(3, 1) = iLen
  589.         
  590.     Else
  591.         aSQLVar(3, 0) = -1
  592.         aSQLVar(3, 1) = 0
  593.     End If
  594. SUB_EXIT:
  595.     Exit Sub
  596. ehHandle:
  597.     MsgBox "SQLVarPos: " & Err.Number & " - " & Err.Description
  598.     Resume Next
  599. End Sub
  600. Private Sub cmdOK_Click()
  601. Dim hFile As Integer
  602. Dim sFilename As String
  603. Dim iFileName As Integer
  604.     If optClipBoard.Value = True Then
  605.         ClipboardCopy txtNewString.Text
  606.         MsgBox "Your code on the Clipboard, Enjoy!", vbExclamation
  607.         
  608.     Else
  609.         
  610.         iFileName = Int((10000 - 100 + 1) * Rnd + 100)
  611.         'obtain the next free file handle from the system
  612.         hFile = FreeFile
  613.         sFilename = App.Path & "\tmp" & iFileName & ".txt"
  614.          
  615.         'open and save the textbox to a file
  616.         Open sFilename For Output As #hFile
  617.             Print #hFile, (txtNewString.Text)
  618.         Close #hFile
  619.         If Err.Number <> 0 Then
  620.             MsgBox "Problem creating temporary file! The disk may be full or read only.", vbExclamation
  621.             Err.Clear
  622.             Exit Sub
  623.         End If
  624.         
  625.         Call Shell("Notepad " & sFilename, vbNormalFocus)
  626.                 
  627.         Kill sFilename
  628.         
  629.         MsgBox "Your code is in Notepad, Enjoy!", vbExclamation
  630.         
  631.     End If
  632.     Unload Me
  633. End Sub
  634. Public Sub ClipboardCopy(Text As String)
  635. 'Copies text to the clipboard
  636. On Error GoTo error
  637.     Clipboard.Clear
  638.     Clipboard.SetText Text$
  639. Exit Sub
  640. error:  MsgBox Err.Description, vbExclamation, "Error"
  641. End Sub
  642. Private Sub Form_Load()
  643.     MakeLink Label3, Startup
  644. End Sub
  645. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  646.     MakeLink Label3, FormMove
  647. End Sub
  648. Private Sub Form_Resize()
  649.     ResizeForm Me
  650. End Sub
  651. Private Sub Label3_Click()
  652.     MakeLink Label3, Click, Me
  653. End Sub
  654. Private Sub Label3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  655.     MakeLink Label3, LinkMove
  656. End Sub
  657. Public Sub MakeLink(LabelName As Label, Operation As OpType, Optional FormName As Form)
  658.     Dim Openpage As Integer
  659.     Select Case Operation
  660.         Case LinkMove
  661.         LabelName.ForeColor = 255
  662.         LabelName.FontUnderline = True
  663.         Case Click
  664.         Openpage = ShellExecute(Me.hwnd, "Open", LabelName.Caption, "", App.Path, 1)
  665.         LabelName.ForeColor = 8388736
  666.         Clicked = True
  667.         Case FormMove
  668.         LabelName.FontUnderline = False
  669.         If Not Clicked Then
  670.             LabelName.ForeColor = 16711680
  671.         Else
  672.             LabelName.ForeColor = 8388736
  673.         End If
  674.         Case Startup
  675.         LabelName.ForeColor = 16711680
  676.     End Select
  677. End Sub
  678.         
  679. Public Function FormatSQL(sOld As String, bSQLSmart As Boolean, bContinue As Boolean, _
  680.     iCharCnt As Integer, sVariable As String, bFixQuotes As Boolean) As String
  681. Dim lStrLen As Integer
  682. Dim lcv As Integer, lCnt As Integer
  683. Dim StartPos As Integer, EndPos As Integer
  684. Dim sVar As String
  685. Dim sPart As String
  686. Dim iLineLen As Integer, iLineCnt As Integer
  687. Dim bSQLPart As Boolean
  688. '********************************************
  689. 'This class was written by:
  690. '   Karl E. Peterson
  691. '   http://www.mvps.org/vb/
  692. 'See the class for more detail. Thank you to
  693. 'him for this code, I got it via VBPJ Article
  694. 'on string building in ASP.
  695. '********************************************
  696. Dim cSBld As New CStringBuilder
  697. 'Chr(34) = "
  698. 'Chr(39) = '
  699. On Error GoTo ehHandle
  700.         
  701.     '********************************************
  702.     'Clean up String before we begin...
  703.     '********************************************
  704.         
  705.         'Remove Tab Characters
  706.         sOld = RemoveChar(sOld, CStr(vbTab))
  707.         
  708.         'Remove Carriage Returns
  709.         sOld = Replace(sOld, CStr(vbCr), CStr(Chr(32)))
  710.         
  711.         'Remove Line Feeds
  712.         sOld = RemoveChar(sOld, CStr(vbLf))
  713.         
  714.         'Remove extra Spaces
  715.         sOld = Trim(sOld)
  716.         
  717.         
  718.     '********************************************
  719.     'Ready to Rock...
  720.     '********************************************
  721.        
  722.     'Replace any quotes with single quotes if desired
  723.     If bFixQuotes = True Then
  724.         sOld = CleanString(sOld)
  725.     End If
  726.     'Store original length
  727.     lStrLen = Len(sOld)
  728.     'If a variable is given te use it...
  729.     If Len(sVariable) > 0 Then
  730.         sVar = sVariable
  731.         cSBld.Append DIM_STR1 & sVar & DIM_STR2 & vbCrLf & vbCrLf
  732.     Else
  733.         sVar = "strSQL"
  734.     End If
  735.     'Set Key SQL Positions in Array
  736.     Call SQLVarPos(sOld)
  737.         
  738.     'Place some space between the declare and the code
  739.     cSBld.Append vbCrLf & vbTab
  740.     'Set initial values prior to loop
  741.     StartPos = 1
  742.     lCnt = 0
  743.     'iSQLCnt = 0
  744.         
  745.     'Essentially, we go through each character iin the string (VB does this nicely).
  746.     'If we reach are character count (iCharCnt) then we make a new line.
  747.     'We do this until we reach the end...
  748.     If lStrLen <= iCharCnt Then
  749.         cSBld.Append sVar & " = "
  750.         cSBld.Append ContinueString(sOld, True)
  751.     Else
  752.         For lcv = 0 To lStrLen
  753.                 lCnt = lCnt + 1
  754.                 
  755.                 If lcv = 0 Then
  756.                         cSBld.Append sVar & " = "
  757.                 End If
  758.                 
  759.                 iLineLen = 0
  760.                 bSQLPart = False
  761.                 
  762.                 'Check if we should to cut here?
  763.                 Select Case True
  764.                 
  765.                 Case aSQLVar(0, 0) = lcv
  766.                     iLineLen = aSQLVar(0, 1)
  767.                     bSQLPart = True
  768.                 Case aSQLVar(1, 0) = lcv
  769.                     If lCnt > 1 Then
  770.                         iLineLen = -1
  771.                         
  772.                     Else
  773.                         iLineLen = aSQLVar(1, 1)
  774.                         bSQLPart = True
  775.                     End If
  776.                     
  777.                 Case aSQLVar(2, 0) = lcv
  778.                     If lCnt > 1 Then
  779.                         iLineLen = -1
  780.                         
  781.                     Else
  782.                         iLineLen = aSQLVar(2, 1)
  783.                         bSQLPart = True
  784.                     End If
  785.                     
  786.                 Case aSQLVar(3, 0) = lcv
  787.                     If lCnt > 1 Then
  788.                         iLineLen = -1
  789.                         
  790.                     Else
  791.                         iLineLen = aSQLVar(3, 1)
  792.                         bSQLPart = True
  793.                     End If
  794.                 Case (lCnt = iCharCnt) Or (lcv = lStrLen)
  795.                     
  796.                     If (iCharCnt < (lStrLen - lcv)) Then
  797.                         For iLineLen = 0 To 50
  798.                             Debug.Print Asc(Mid(sOld, (lcv - iLineLen), 1))
  799.                             
  800.                             If Asc(Mid(sOld, (lcv - iLineLen), 1)) = 32 Or _
  801.                                 Asc(Mid(sOld, (lcv - iLineLen), 1)) = 44 Then
  802.                                 
  803.                                 lcv = lcv - iLineLen
  804.                                 iLineLen = iCharCnt - iLineLen
  805.                                 Exit For
  806.                                 
  807.                             End If
  808.                         Next
  809.                         
  810.                     Else
  811.                         'We Should be Done!
  812.                         iLineLen = (lStrLen - (StartPos - 1))
  813.                         
  814.                     End If
  815.                     
  816.                 End Select
  817.                 
  818.                 'This means get whatever is remaining right now
  819.                 If iLineLen = -1 Then
  820.                     'lcv = lcv - 1
  821.                     iLineLen = lCnt
  822.                 End If
  823.                 
  824.                 If iLineLen > 0 Then
  825.                     lCnt = 0
  826.                     
  827.                     If bContinue Then
  828.                         cSBld.Append ContinueString(Mid(sOld, StartPos, iLineLen), CBool(((iLineLen + lcv) >= lStrLen)))
  829.                     Else
  830.                         
  831.                         cSBld.Append AppendString(sVar, Mid(sOld, StartPos, iLineLen), CBool(((iLineLen + lcv) >= lStrLen)))
  832.                     End If
  833.                     
  834.                     If CBool(((iLineLen + lcv) >= lStrLen)) = True Then
  835.                         
  836.                         Exit For
  837.                     End If
  838.                     
  839.                     If bSQLPart Then
  840.                         lcv = lcv + iLineLen
  841.                     End If
  842.                     
  843.                     StartPos = lcv
  844.                                         
  845.                     'If StartPos = 1 Then
  846.                     '    StartPos = lcv + 2
  847.                     'Else
  848.                     '    StartPos = lcv + 1
  849.                     'End If
  850.                     
  851.                     cSBld.Append vbCrLf
  852.                              
  853.                     'If CBool(((iLineLen + lcv) >= lStrLen)) = False Then
  854.                     '    lcv = lcv + iLineLen
  855.                     'Else
  856.                     '    Exit For
  857.                     'End If
  858.                              
  859.                 End If
  860.                 
  861.         Next lcv
  862.     End If
  863.     'Pass the String Back...
  864.     FormatSQL = cSBld.ToString
  865.     Set cSBld = Nothing
  866. ExitFunc:
  867.     Exit Function
  868. ehHandle:
  869.     MsgBox "ERROR: " & Err.Number & " - " & Err.Description
  870.     Resume Next
  871. End Function
  872. Private Function ContinueString(sLine As String, bEnd As Boolean) As String
  873.     If bEnd Then
  874.         ContinueString = Chr(34) & sLine & Chr(34)
  875.     Else
  876.         ContinueString = Chr(34) & sLine & Chr(34) & CONT_STR
  877.     End If
  878. End Function
  879. Private Function AppendString(sVar As String, sLine As String, bEnd As Boolean) As String
  880.     If bEnd Then
  881.          AppendString = sVar & " = " & sVar & CONNECT_STR & _
  882.                                 Chr(34) & sLine & Chr(34)
  883.     Else
  884.          AppendString = sVar & " = " & sVar & CONNECT_STR & _
  885.                                 Chr(34) & sLine & Chr(34)
  886.     End If
  887. End Function
  888.