Schleife auf Datenbank zum ändern und anzeigen im HTA

  • VBScript

    Schleife auf Datenbank zum ändern und anzeigen im HTA

    Hallo, ich habe folgendes nette Programm in hta mittels vbscript geschrieben (relevanter Auszug):

    VB.NET-Quellcode

    1. Set objOption = Document.createElement("Option")
    2. objOption.Text = "alle Stationen"
    3. objOption.Value = "*"
    4. station.Add(objOption)
    5. Set con = CreateObject("ADODB.Connection")
    6. con.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB="&strDatei&";Exclusive=No"
    7. query= "SELECT daaprotx.station FROM daaprotx daaprotx WHERE (daaprotx.prottyp='1')GROUP BY daaprotx.station"
    8. Set rs = CreateObject("adodb.recordset")
    9. rs.Open query, con
    10. Do Until rs.EOF
    11. 'Objekt zuweisung für die Listbox
    12. Set objOption = Document.createElement("Option")
    13. objOption.Text = rs.Fields(0).value
    14. objOption.Value = rs.Fields(0).value
    15. station.Add(objOption)
    16. rs.MoveNext
    17. Loop
    18. Set res = Nothing
    19. Set con = Nothing
    20. End Function
    21. 'Bei Auswahl wird der prozentuale Teil ermittelt
    22. Function Stationenauswahl
    23. On Error Resume Next
    24. Dim MyConn, rs, SQL_query1, cstation
    25. cstation=Station.options(Station.selectedIndex).value
    26. Set MyConn = CreateObject("ADODB.Connection")
    27. MyConn.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB="&strDatei&";Exclusive=No"
    28. 'Abfrage auf ob alle Stationen oder einzelne Station ausgewertet werden soll
    29. If cstation = "*" Then
    30. SQL_query1 = "SELECT DOW(daaprotx.datum)as Wochentag,Count(daaprotx.datum)/COUNT(DISTINCT daaprotx.datum)As Rückgaben FROM daaprotx WHERE BETWEEN (daaprotx.datum, gomonth(date(), -12), daaprotx.datum) AND(daaprotx.prottyp='1') Group by 1"
    31. Else
    32. SQL_query1 = "SELECT DOW(daaprotx.datum)as Wochentag,Count(daaprotx.datum)/COUNT(DISTINCT daaprotx.datum)As Rückgaben FROM daaprotx WHERE BETWEEN (daaprotx.datum, gomonth(date(), -12), daaprotx.datum) AND(daaprotx.prottyp='1')AND(daaprotx.station='"&Station.options(Station.selectedIndex).value&"')Group by 1"
    33. End If
    34. Set rs=CreateObject("ADODB.recordset")
    35. rs.Open SQL_query1, MyConn
    36. If IsNull(rs) Then
    37. MsgBox "Keine Ausleihen auf dieser Station verbucht!"
    38. Exit Function
    39. End If
    40. Dim arrAllData
    41. 'GetRow Methode um die Daten in ein Datensatz mittels eines 2 dimensionalen Arrays
    42. arrAllData = rs.GetRows()
    43. Dim numCols 'number of fields per row in results
    44. Dim numColCounter 'used to loop through the columns
    45. Dim numRows 'number of rows in results
    46. Dim numRowCounter 'used to loop through the rows
    47. Dim strthisfield 'current field in loop
    48. Dim numfield
    49. numCols = UBound(arrAllData, 1)
    50. numRows = UBound(arrAllData, 2)
    51. strHTML="<table class=""table1""cellspacing=""8"" cellpadding=""15""><tr><th>Bei 50%"&"<br>"&"80 Artikel/ Box</th>" & vbCrLf
    52. 'loop through rows
    53. For numRowCounter = 0 To numRows
    54. strHTML=strHTML & "<tr >" & vbCrLf
    55. 'for each column
    56. For numColCounter = 1 to numCols
    57. strthisfield = arrAllData(numColCounter, numRowCounter)
    58. If IsNull(strthisfield) Then
    59. strthisfield = "-null-"
    60. End If
    61. If Trim(strthisfield) = "" Then
    62. strthisfield = " "
    63. End If
    64. If numColCounter = 1 Then
    65. strthisfield = Round(strthisfield )
    66. strthisfield = (strthisfield / 80)*0.5
    67. strthisfield = Round(strthisfield)
    68. End If
    69. strHTML=strHTML & "<td>" & strthisfield & "</td>" & vbCrLf
    70. Next
    71. strHTML=strHTML & "</tr>" & vbCrLf
    72. Next
    73. strHTML=strHTML & "</table>"
    74. table1.InnerHTML = strHTML
    75. Dim MyConn3
    76. Dim rs3
    77. Dim SQL_query13
    78. Set MyConn3 = CreateObject("ADODB.Connection")
    79. MyConn3.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB="&strDatei&";Exclusive=No"
    80. If cstation = "*" Then
    81. SQL_query13 = "SELECT DOW(daaprotx.datum)as Wochentag,Count(daaprotx.datum)/COUNT(DISTINCT daaprotx.datum)As Rückgaben FROM daaprotx WHERE BETWEEN (daaprotx.datum, gomonth(date(), -12), daaprotx.datum) AND(daaprotx.prottyp='1') Group by 1"
    82. Else
    83. SQL_query13 = "SELECT DOW(daaprotx.datum)as Wochentag,Count(daaprotx.datum)/COUNT(DISTINCT daaprotx.datum)As Rückgaben FROM daaprotx WHERE BETWEEN (daaprotx.datum, gomonth(date(), -12), daaprotx.datum) AND(daaprotx.prottyp='1')AND(daaprotx.station='"&Station.options(Station.selectedIndex).value&"')Group by 1"
    84. End If
    85. Set rs3=CreateObject("ADODB.recordset")
    86. rs3.Open SQL_query13, MyConn3
    87. If IsNull(rs3) Then
    88. MsgBox "Keine Ausleihen auf dieser Station verbucht!"
    89. Exit Function
    90. End If
    91. Dim arrAllData3
    92. arrAllData3 = rs3.GetRows()
    93. Dim numCols3 'number of fields per row in results
    94. Dim numColCounter3 'used to loop through the columns
    95. Dim numRows3 'number of rows in results
    96. Dim numRowCounter3 'used to loop through the rows
    97. Dim strthisfield3 'current field in loop
    98. numCols3 = UBound(arrAllData3, 1)
    99. numRows3 = UBound(arrAllData3, 2)
    100. strHTML3="<table class=""table2""cellspacing=""8"" cellpadding=""15""><tr><th>Bei 80%"&"<br>"&"80 Artikel/ Box&nbsp;</th>" & vbCrLf
    101. 'loop through rows
    102. For numRowCounter3 = 0 To numRows3
    103. strHTML3=strHTML3 & "<tr >" & vbCrLf
    104. 'for each column
    105. For numColCounter3 = 1 to numCols3
    106. strthisfield3 = arrAllData3(numColCounter3, numRowCounter3)
    107. If IsNull(strthisfield3) Then
    108. strthisfield3 = "-null-"
    109. End If
    110. If Trim(strthisfield3) = "" Then
    111. strthisfield3 = " "
    112. End If
    113. If numColCounter3 = 0 Then
    114. End If
    115. If numColCounter3 = 1 Then
    116. strthisfield3= Round(strthisfield3)
    117. strthisfield3 = (strthisfield3 / 80)*0.8
    118. strthisfield3 = Round(strthisfield3)
    119. End If
    120. strHTML3=strHTML3 & "<td>" & strthisfield3 & "</td>" & vbCrLf
    121. Next
    122. strHTML3=strHTML3 & "</tr>" & vbCrLf
    123. Next
    124. strHTML3=strHTML3 & "</table>"
    125. table2.InnerHTML = strHTML3


    wie man schnell sieht, es ist unübersichtlich und für das gleiche: also benennen der Tabelle und eine kleine Rechnung, durchlaufe alles immer wieder und wieder, also dachte ich mir das müsste doch mit einer Schleife zu lösen sein. Jedoch bekomm ich das einfach nicht hin, da ich ja auch immer die Tabelle brauche für mein css. Das programm funktioniert so zwar aber ich möchte den Code aufpolieren. Bin für jeden Ansatz offen.