Hallo, ich habe folgendes nette Programm in hta mittels vbscript geschrieben (relevanter Auszug):
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.
VB.NET-Quellcode
- Set objOption = Document.createElement("Option")
- objOption.Text = "alle Stationen"
- objOption.Value = "*"
- station.Add(objOption)
- Set con = CreateObject("ADODB.Connection")
- con.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB="&strDatei&";Exclusive=No"
- query= "SELECT daaprotx.station FROM daaprotx daaprotx WHERE (daaprotx.prottyp='1')GROUP BY daaprotx.station"
- Set rs = CreateObject("adodb.recordset")
- rs.Open query, con
- Do Until rs.EOF
- 'Objekt zuweisung für die Listbox
- Set objOption = Document.createElement("Option")
- objOption.Text = rs.Fields(0).value
- objOption.Value = rs.Fields(0).value
- station.Add(objOption)
- rs.MoveNext
- Loop
- Set res = Nothing
- Set con = Nothing
- End Function
- 'Bei Auswahl wird der prozentuale Teil ermittelt
- Function Stationenauswahl
- On Error Resume Next
- Dim MyConn, rs, SQL_query1, cstation
- cstation=Station.options(Station.selectedIndex).value
- Set MyConn = CreateObject("ADODB.Connection")
- MyConn.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB="&strDatei&";Exclusive=No"
- 'Abfrage auf ob alle Stationen oder einzelne Station ausgewertet werden soll
- If cstation = "*" Then
- 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"
- Else
- 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"
- End If
- Set rs=CreateObject("ADODB.recordset")
- rs.Open SQL_query1, MyConn
- If IsNull(rs) Then
- MsgBox "Keine Ausleihen auf dieser Station verbucht!"
- Exit Function
- End If
- Dim arrAllData
- 'GetRow Methode um die Daten in ein Datensatz mittels eines 2 dimensionalen Arrays
- arrAllData = rs.GetRows()
- Dim numCols 'number of fields per row in results
- Dim numColCounter 'used to loop through the columns
- Dim numRows 'number of rows in results
- Dim numRowCounter 'used to loop through the rows
- Dim strthisfield 'current field in loop
- Dim numfield
- numCols = UBound(arrAllData, 1)
- numRows = UBound(arrAllData, 2)
- strHTML="<table class=""table1""cellspacing=""8"" cellpadding=""15""><tr><th>Bei 50%"&"<br>"&"80 Artikel/ Box</th>" & vbCrLf
- 'loop through rows
- For numRowCounter = 0 To numRows
- strHTML=strHTML & "<tr >" & vbCrLf
- 'for each column
- For numColCounter = 1 to numCols
- strthisfield = arrAllData(numColCounter, numRowCounter)
- If IsNull(strthisfield) Then
- strthisfield = "-null-"
- End If
- If Trim(strthisfield) = "" Then
- strthisfield = " "
- End If
- If numColCounter = 1 Then
- strthisfield = Round(strthisfield )
- strthisfield = (strthisfield / 80)*0.5
- strthisfield = Round(strthisfield)
- End If
- strHTML=strHTML & "<td>" & strthisfield & "</td>" & vbCrLf
- Next
- strHTML=strHTML & "</tr>" & vbCrLf
- Next
- strHTML=strHTML & "</table>"
- table1.InnerHTML = strHTML
- Dim MyConn3
- Dim rs3
- Dim SQL_query13
- Set MyConn3 = CreateObject("ADODB.Connection")
- MyConn3.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB="&strDatei&";Exclusive=No"
- If cstation = "*" Then
- 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"
- Else
- 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"
- End If
- Set rs3=CreateObject("ADODB.recordset")
- rs3.Open SQL_query13, MyConn3
- If IsNull(rs3) Then
- MsgBox "Keine Ausleihen auf dieser Station verbucht!"
- Exit Function
- End If
- Dim arrAllData3
- arrAllData3 = rs3.GetRows()
- Dim numCols3 'number of fields per row in results
- Dim numColCounter3 'used to loop through the columns
- Dim numRows3 'number of rows in results
- Dim numRowCounter3 'used to loop through the rows
- Dim strthisfield3 'current field in loop
- numCols3 = UBound(arrAllData3, 1)
- numRows3 = UBound(arrAllData3, 2)
- strHTML3="<table class=""table2""cellspacing=""8"" cellpadding=""15""><tr><th>Bei 80%"&"<br>"&"80 Artikel/ Box </th>" & vbCrLf
- 'loop through rows
- For numRowCounter3 = 0 To numRows3
- strHTML3=strHTML3 & "<tr >" & vbCrLf
- 'for each column
- For numColCounter3 = 1 to numCols3
- strthisfield3 = arrAllData3(numColCounter3, numRowCounter3)
- If IsNull(strthisfield3) Then
- strthisfield3 = "-null-"
- End If
- If Trim(strthisfield3) = "" Then
- strthisfield3 = " "
- End If
- If numColCounter3 = 0 Then
- End If
- If numColCounter3 = 1 Then
- strthisfield3= Round(strthisfield3)
- strthisfield3 = (strthisfield3 / 80)*0.8
- strthisfield3 = Round(strthisfield3)
- End If
- strHTML3=strHTML3 & "<td>" & strthisfield3 & "</td>" & vbCrLf
- Next
- strHTML3=strHTML3 & "</tr>" & vbCrLf
- Next
- strHTML3=strHTML3 & "</table>"
- 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.