[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Excel: VB -> Delphi Conversion

Asked by gwarguitar in Delphi Programming

Tags: delphi

I basically want this function converted from VB to Delphi. The data from the VB version is coming from SQL, the delphi
one will come from a TList. so that part can be ignored or replaced with something like MyList(list[i]).Item1);

Public Sub ExportTQC(intMode As Integer)
On Error GoTo HandleError 'Resume Next
'intMode = 1 All Info
'intMode = 2 AD Info...no cell numbers
'intMode = 2 All Info sort by dept

Dim rst As ADODB.Recordset

Dim sSQL As String
Dim sMsg As String

Dim strFax() As String
Dim strConf() As String
Dim strOther() As String

Dim appExcel As Excel.Application
Dim wbkNew As Excel.Workbook
Dim wksNew As Excel.Worksheet

Dim iCounter As Long
Dim iFldCount As Long
Dim i As Integer, j As Long
Dim lColumnCount As Long

Dim sRootPath As String
Dim sFileName As String
Dim sScriptFileName As String
Dim sExcelFileName As String
Dim sExcelFileAndPath As String
Dim sSQLString As String

Dim strRange As String
Dim strEndColumn As String
Dim lBackcolor As Long
Const vbLightBlue = 16777164
Const xlLightBlue = 37

    Set appExcel = Excel.Application
    Set wbkNew = appExcel.Workbooks.Add
    Set wksNew = appExcel.Worksheets("Sheet1")
   
    wbkNew.Sheets("Sheet1").Name = "TQC Directory"
    Application.DisplayAlerts = False
    wbkNew.Sheets("Sheet2").Delete
    wbkNew.Sheets("Sheet3").Delete
    Application.DisplayAlerts = True
   
    wbkNew.Protect "tqc123", True, False
   
    Select Case intMode
        Case 1
            sExcelFileAndPath = iQSettings.AllStaff & "TQC Directory.xls"
            lColumnCount = 6
            strEndColumn = "G"
            sSQLString = "SP_GetTQCActive"
        Case 2
            sExcelFileAndPath = iQSettings.AllStaff & "TQC DirectoryAD.xls"
            lColumnCount = 5
            strEndColumn = "F"
            sSQLString = "SP_GetTQCActiveAD"
       Case 3
            sExcelFileAndPath = iQSettings.AllStaff & "TQC DirectoryDept.xls"
            lColumnCount = 6
            strEndColumn = "G"
            sSQLString = "usp_GetTQCActiveByDept"
    End Select
   
    Set rst = CreateRecordSet(sSQLString)
   
    iFldCount = rst.Fields.Count

    With wksNew
        .Cells.Font.Name = "Arial"
        .Cells.Font.Size = 8
        .Cells.Font.Strikethrough = False
        .Cells.Font.Superscript = False
        .Cells.Font.Subscript = False
        .Cells.Font.OutlineFont = False
        .Cells.Font.Shadow = False
        .Cells.Font.Underline = xlUnderlineStyleNone
        .Cells.Font.ColorIndex = xlAutomatic
       
        .Rows("2:2").Select
        ActiveWindow.FreezePanes = True
       
        ActiveSheet.PageSetup.PrintTitleRows = "$1:$1"
        ActiveSheet.PageSetup.PrintTitleColumns = ""

        .Rows("1:1").Select
        Selection.Font.Bold = True
       
        'ActiveSheet.PageSetup.PrintArea = ""
        .PageSetup.LeftHeader = "TQC Directory"
        .PageSetup.CenterHeader = ""
        .PageSetup.RightHeader = ""
        .PageSetup.LeftFooter = "&D"
        .PageSetup.CenterFooter = ""
        .PageSetup.RightFooter = "&P of &N"
           
        .PageSetup.LeftMargin = 48
        .PageSetup.RightMargin = 36
        .PageSetup.TopMargin = 36
        .PageSetup.BottomMargin = 54
        .PageSetup.HeaderMargin = 18
        .PageSetup.FooterMargin = 18
           
        .PageSetup.PrintHeadings = False
        .PageSetup.PrintGridlines = False
        .PageSetup.PrintComments = xlPrintNoComments
        .PageSetup.PrintQuality = 600
        .PageSetup.CenterHorizontally = True
        .PageSetup.CenterVertically = False
        .PageSetup.Draft = False
        .PageSetup.FirstPageNumber = xlAutomatic
        .PageSetup.Order = xlDownThenOver
        .PageSetup.BlackAndWhite = False
        .PageSetup.Zoom = 90
        .PageSetup.Orientation = xlLandscape
       
       
        ' Create column headers
        For i = 0 To lColumnCount
'            If intMode = 2 And i = 3 Then
'                .Cells(1, i + 1).Value = ""
'                GoTo SkipToNext
'            End If
            If InStr(1, rst.Fields(i).Name, "zip") > 0 Then
                .Cells.NumberFormat = "@"
                .Cells(1, i + 1).Value = Format(CStr(rst.Fields(i).Name), "00000")
            Else
                .Cells.NumberFormat = "@"
                .Cells(1, i + 1).Value = rst.Fields(i).Name
            End If
'SkipToNext:
        Next

        strRange = "A1:" & strEndColumn & "1"
       
        .Range(strRange).Borders(xlEdgeBottom).LineStyle = xlContinuous
        .Range(strRange).Borders(xlEdgeBottom).Weight = xlThin
        .Range(strRange).Borders(xlEdgeBottom).ColorIndex = xlAutomatic

        ' Data starts on 3rd row
        j = 2
   
        ' Loop through recordset adding rows to Excel
        Do Until rst.EOF
       
            strRange = "A" & CStr(j) & ":" & strEndColumn & CStr(j)
           
            lBackcolor = xlLightBlue
            If rst.Fields("FlagRecord") = 0 Then lBackcolor = xlNone
            .Range(strRange).Interior.ColorIndex = lBackcolor
           
            If (j - 1) Mod 5 = 0 Then
                .Range(strRange).Borders(xlEdgeBottom).LineStyle = xlContinuous
                .Range(strRange).Borders(xlEdgeBottom).Weight = xlThin
                .Range(strRange).Borders(xlEdgeBottom).ColorIndex = xlAutomatic
            Else
                .Range(strRange).Borders(xlEdgeBottom).LineStyle = xlNone
            End If
           
            For i = 0 To lColumnCount
'                If intMode = 2 And i = 3 Then
'                    .Cells(j, i + 1).Value = ""
'                Else
                    .Cells(j, i + 1).Value = rst.Fields(i).Value
'                End If
            Next
                   
            j = j + 1
            rst.MoveNext
        Loop
       
        .Cells.Select
        .Cells.EntireColumn.AutoFit
        .Range("A1").Select
       
'======================
'set up special numbers
'======================
Dim intX As Integer
Dim intRootJ As Integer
       
        j = j + 1
        .Cells(j, 1) = "FAX NUMBERS"
        .Cells(j, 4) = "CONFERENCE ROOMS"
        .Cells(j, 6) = "OTHER NUMBERS"
       
        strRange = "A" & j & ":F" & j
        .Range(strRange).Borders(xlEdgeBottom).LineStyle = xlContinuous
        .Range(strRange).Borders(xlEdgeBottom).Weight = xlThin
        .Range(strRange).Borders(xlEdgeBottom).ColorIndex = xlAutomatic
        .Range(strRange).Font.Bold = True
       
        intRootJ = j
        Set rst = New ADODB.Recordset
        Set rst = CreateRecordSet("SP_GetTQCSpecialNumbers 1") 'fax numbers
        ReDim strFax(rst.RecordCount)
        intX = 0
        Do While rst.EOF = False
            intX = intX + 1
            strFax(intX) = rst.Fields("string_label") & " " & rst.Fields("string")
            .Cells(j + intX, 1) = strFax(intX)
            rst.MoveNext
        Loop
               
        Set rst = New ADODB.Recordset
        Set rst = CreateRecordSet("SP_GetTQCSpecialNumbers 2") 'conf numbers
        ReDim strConf(rst.RecordCount)
        intX = 0
        Do While rst.EOF = False
            intX = intX + 1
            strConf(intX) = rst.Fields("string_label") & " " & rst.Fields("string")
            .Cells(j + intX, 4) = strConf(intX)
            rst.MoveNext
        Loop
               
        Set rst = New ADODB.Recordset
        Set rst = CreateRecordSet("SP_GetTQCSpecialNumbers 3") 'other numbers
        ReDim strOther(rst.RecordCount)
        intX = 0
        Do While rst.EOF = False
            intX = intX + 1
            strOther(intX) = rst.Fields("string_label") & " " & rst.Fields("string")
            .Cells(j + intX, 6) = strOther(intX)
            rst.MoveNext
        Loop
               
        .Protect Password:="tqc123", DrawingObjects:=False, Contents:=True, Scenarios:=False

    End With
   
    appExcel.Visible = True
   
On Error GoTo HandleError
   
    KillFile (sExcelFileAndPath)
    wbkNew.Protect "tqc123", True, False
    wbkNew.SaveAs FileName:=sExcelFileAndPath
ShowTQC:
    appExcel.DisplayFullScreen = True
    appExcel.DisplayFullScreen = False
    If Not wksNew Is Nothing Then
        wksNew.Select
    End If
KillObjects:
    Set rst = Nothing

    ' Cleanup Excel objects
    Set wksNew = Nothing
    Set wbkNew = Nothing
    Set appExcel = Nothing
Exit Sub

HandleError:
If Err.Number = 1004 Then
    MsgBox "The file cannot be copied to the network location. A user on the network has the file opened." & vbCr & "The TQC File needs to be saved manually by you.", vbOKOnly
    GoTo ShowTQC
Else
    MsgBox "The following error occured:" & vbCr & Err.Description & vbCr & Err.Number
End If
GoTo KillObjects

End Sub


[+][-]08/30/04 03:19 PM, ID: 11936610Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/30/04 03:22 PM, ID: 11936628Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/30/04 05:07 PM, ID: 11937521Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/31/04 07:17 AM, ID: 11942371Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/31/04 09:09 AM, ID: 11943649Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Delphi Programming
Tags: delphi
Sign Up Now!
Solution Provided By: PierreC
Participating Experts: 1
Solution Grade: A
 
[+][-]08/31/04 11:27 AM, ID: 11945151Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/31/04 11:59 AM, ID: 11945438Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81