<html> <body> <% 'Her skal dit array ind, som test er det bare en flok forskille ord: ordArr = Split("a1,b1,c1,a2,a8,a4,b4,b3,c6,c4,a3,a5,a7,b7,c7,b6,c6,c5,b5",",")
ordArr = Sorter(ordArr) %> <table width="100%"> <% ordPrRow = 0 maxPrRow = 4 firstChar="" for i = lbound(ordArr) to ubound(ordArr) if firstChar <> ucase(left(ordArr(i),1)) then if ordPrRow > 0 then Response.Write "</tr>" ordPrRow = 0 end if firstChar = ucase(left(ordArr(i),1)) Response.Write "<tr><td colspan=""" & maxPrRow & """>" & firstChar & "</td></tr>" end if if ordPrRow = 0 then Response.Write "<tr>"
Response.Write "<td>" & ordArr(i) & "</td>"
ordPrRow = ordPrRow + 1 if ordPrRow = maxPrRow then Response.Write "</tr>" ordPrRow = 0 end if Next if ordPrRow > 0 then Response.Write "</tr>" %> </table>
</body> </html>
<% Function Sorter(ByVal tabel) Dim blnContinue, i, varFirst, varSecond blnContinue = True Do Until blnContinue = False blnContinue = False For i = 0 to UBound(tabel) If i = UBound(tabel) Then Exit For Arr = Split(tabel(i),".") tmp1 = arr(0) if isnumeric(tmp1) then tmp1 = Int(tmp1) Arr = Split(tabel(i+1),".") tmp2 = arr(0) if isnumeric(tmp2) then tmp2 = Int(tmp2) If tmp1 > tmp2 Then varFirst = tabel(i) varSecond = tabel(i+1) tabel(i) = varSecond tabel(i+1) = varFirst blnContinue = True End If Next Loop Sorter = tabel End Function %>
Mangler er mellemrum fra hvor A slutter til hvor B begynder så prøv at rette:
if firstChar <> ucase(left(ordArr(i),1)) then if ordPrRow > 0 then Response.Write "</tr>" ordPrRow = 0 end if firstChar = ucase(left(ordArr(i),1)) Response.Write "<tr><td colspan=""" & maxPrRow & """>" & firstChar & "</td></tr>" end if
Til dette:
if firstChar <> ucase(left(ordArr(i),1)) then if ordPrRow > 0 then Response.Write "</tr>" ordPrRow = 0 end if if firstChar <> "" then Response.Write "<tr><td colspan=""" & maxPrRow & """> </td></tr>" firstChar = ucase(left(ordArr(i),1)) Response.Write "<tr><td colspan=""" & maxPrRow & """>" & firstChar & "</td></tr>" end if
Det kan gøres sådan her. Hvis antallet af ord for et bogstav er imellem 3 og 9 bliver det vise i enten 3 eller 4 kolonner, da man er nød til at finde max antal pr. kolonne. Hvis antallet er 1 eller 2 er det naturvis i 1 eller 2 kolonner.
firstChar="" antalRows=0 for i = lbound(ordArr) to ubound(ordArr) if firstChar <> ucase(left(ordArr(i),1)) then if antalRows > 0 then Response.Write "</tr></table>" Response.Write "</tr>" antalRows = 0 end if if firstChar <> "" then Response.Write "<tr><td colspan=""" & maxPrRow & """> </td></tr>" firstChar = ucase(left(ordArr(i),1)) Response.Write "<tr><td colspan=""" & maxPrRow & """>" & firstChar & "</td></tr>" Response.Write "<tr>" antalKarakter = countChar(ordArr,firstChar) antalPrKol=abs(int(-antalKarakter/maxPrRow)) end if
if antalRows=0 then Response.Write "<td valign=""top""><table>" end if
antalRows=antalRows+1 if antalRows=antalPrKol then Response.Write "</table></td>" antalRows=0 end if
Next if ordPrCol > 0 then Response.Write "</tr>" %> </table>
</body> </html>
<% Function Sorter(ByVal tabel) Dim blnContinue, i, varFirst, varSecond blnContinue = True Do Until blnContinue = False blnContinue = False For i = 0 to UBound(tabel) If i = UBound(tabel) Then Exit For Arr = Split(tabel(i),".") tmp1 = arr(0) if isnumeric(tmp1) then tmp1 = Int(tmp1) Arr = Split(tabel(i+1),".") tmp2 = arr(0) if isnumeric(tmp2) then tmp2 = Int(tmp2) If tmp1 > tmp2 Then varFirst = tabel(i) varSecond = tabel(i+1) tabel(i) = varSecond tabel(i+1) = varFirst blnContinue = True End If Next Loop Sorter = tabel End Function
Function countChar(tabel,char) dim x antal=0 for x=lbound(tabel) to ubound(tabel) if ucase(char)=ucase(left(tabel(x),1)) then antal=antal+1 end if next countChar=antal End function
Skal det være sådan der er 4 også når antallet er imellem 5 og 9 så kan det laves sådan her:
<html> <body>
<% ordArr = Split("a1,b1,a2,a8,a4,b4,b3,a3,a5,a7,b7,b6,c1,c2,c3,c4,c5,c6,d1,d2,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10",",") ordArr = Sorter(ordArr) %> <table width="100%"> <% ordPrCol = 0 maxPrRow = 4 nrCol = 0 firstChar="" antalRows=0 for i = lbound(ordArr) to ubound(ordArr)
if firstChar <> ucase(left(ordArr(i),1)) then if antalRows > 0 then Response.Write "</tr></table>" Response.Write "</tr>" antalRows = 0 end if nrCol=0 firsteHasMax=false if firstChar <> "" then Response.Write "<tr><td colspan=""" & maxPrRow & """> </td></tr>" firstChar = ucase(left(ordArr(i),1)) Response.Write "<tr><td colspan=""" & maxPrRow & """>" & firstChar & "</td></tr>" Response.Write "<tr>" antalKarakter = countChar(ordArr,firstChar) antalPrKol=abs(int(-antalKarakter/maxPrRow)) if (antalPrKol*maxPrRow - antalKarakter >= antalPrKol) and (antalPrKol>1) then firsteHasMax=true end if end if
if antalRows=0 then Response.Write "<td valign=""top""><table>" end if
antalRows=antalRows+1 if antalRows=antalPrKol then Response.Write "</table></td>" antalRows=0 nrCol=nrCol+1 if firsteHasMax=true then if (antalPrKol*nrCol+(antalPrKol-1)*(maxPrRow-nrCol)) >= antalKarakter then firsteHasMax=false antalPrKol=antalPrKol-1 end if end if end if
Next if ordPrCol > 0 then Response.Write "</tr>" %> </table>
</body> </html>
<% Function Sorter(ByVal tabel) Dim blnContinue, i, varFirst, varSecond blnContinue = True Do Until blnContinue = False blnContinue = False For i = 0 to UBound(tabel) If i = UBound(tabel) Then Exit For Arr = Split(tabel(i),".") tmp1 = arr(0) if isnumeric(tmp1) then tmp1 = Int(tmp1) Arr = Split(tabel(i+1),".") tmp2 = arr(0) if isnumeric(tmp2) then tmp2 = Int(tmp2) If tmp1 > tmp2 Then varFirst = tabel(i) varSecond = tabel(i+1) tabel(i) = varSecond tabel(i+1) = varFirst blnContinue = True End If Next Loop Sorter = tabel End Function
Function countChar(tabel,char) dim x antal=0 for x=lbound(tabel) to ubound(tabel) if ucase(char)=ucase(left(tabel(x),1)) then antal=antal+1 end if next countChar=antal End function
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.