varför funkar inte scriptet har provat med att inkludera och utan nu ser koden ut såhär:
får felmess:
Körningsfel i Microsoft VBScript (0x800A0009)
Felaktigt matrisindex: '[number: -1]'
/slumpa/slumpa.asp, line 294
och
Körningsfel i Microsoft VBScript (0x800A0009)
Felaktigt matrisindex: 'intRandomIndex'
/slumpa/slumpa.asp, line 292
<%
'## ---------------------------------------------------------------------------
'## -- COPYRIGHT INFORMATION see the readme.txt file that should
'## be a part of this script. If not! contact me at info@mrwize.nu --
'## ---------------------------------------------------------------------------
Class clsArray
Private g_varArray ' As Variant
Private g_bolArrayType ' As Boolean
Private g_intPositions ' As Integer
Private g_bolCreated ' As Boolean
'## ------------------------------------------------------------------
'## -- PUBLIC PROPERTIES --
'## ------------------------------------------------------------------
'## -- what type of array. 1-dimensional or 2-dimensional --
'---------------------------------------------------------------------
Public Property Let ArrayType(ByVal bType)
g_bolArrayType = bType
End Property
Public Property Get ArrayType
ArrayType = g_bolArrayType
End Property
'## -- how many positions every index in a 2-dimensional array have --
'---------------------------------------------------------------------
Public Property Let Positions(ByVal iPositions)
g_intPositions = iPositions
End Property
Public Property Get Positions
Positions = g_intPositions
End Property
'## ------------------------------------------------------------------
'## -- PRIVATE PROPERTIES --
'## ------------------------------------------------------------------
'## -- to indicate if the array is recently created or not --
'---------------------------------------------------------------------
Private Property Let IsCreated(ByVal bCreated)
g_bolCreated = bCreated
End Property
Private Property Get IsCreated
IsCreated = g_bolCreated
End Property
'## ------------------------------------------------------------------
'## -- PUBLIC METHODS --
'## ------------------------------------------------------------------
Public Sub SetArray(vArray)
If IsArray(vArray) Then
g_varArray = vArray
Else
'## -- set array recently created by this class --
IsCreated = 1
'## -- wich type of array to create --
Select Case ArrayType
Case 2
Dim intPositions
intPositions = Positions
ReDim g_varArray(intPositions,0)
Case Else
ReDim g_varArray(0)
End Select
End If
End Sub
'## ------------------------------------------------------------------
Public Sub AddNew()
Dim intNewIndex ' As Integer
Dim bolIsCreated ' As Boolean
bolIsCreated = IsCreated
intNewIndex = MaxIndex + 1
Select Case ArrayType
Case 2
Dim intPositions ' As Integer
intPositions = Positions
If bolIsCreated <> 1 Then
'## -- the array is not recently created and need a new index --
ReDim Preserve g_varArray(intPositions,intNewIndex)
Else
'## -- array is newly created and need not a new index.
'## -- set array not recent created --
IsCreated = 0
End If
Case Else
'## -- check if the array is newly created --
If bolIsCreated <> 1 Then
'## -- the array is not recently created and need a new index --
ReDim Preserve g_varArray(intNewIndex)
Else
'## -- the array is recent created and need not a new index --
'## -- set array to indicate as not recently created --
IsCreated = 0
End If
End Select
End Sub
'## ------------------------------------------------------------------
Public Sub Update(ByVal vData, ByVal iIndex, ByVal iPos)
'## -- if no index is given as a argument then set index to be
'## updated as last created index --
'-----------------------------------------------------------------
If Len(iIndex) = 0 OR IsNull(iIndex) Then iIndex = MaxIndex()
Select Case ArrayType
Case 2
'## -- if no position for index is given as a argument
'## then update the first position in the index --
'---------------------------------------------------------
If Len(iPos) = 0 OR IsNull(iPos) Then iPos = 0
'## -- save the new value to the array --
'---------------------------------------------------------
g_varArray(iPos, iIndex) = vData
Case Else
'## -- save the new value to the array --
'---------------------------------------------------------
g_varArray(iIndex) = vData
End Select
End Sub
'## ------------------------------------------------------------------
Public Sub Delete(ByVal iIndex)
If iIndex < MinIndex() OR iIndex > MaxIndex() Then Exit Sub '## -- illegal index value --
Dim I, intPos
Dim intEndIndex
intEndIndex = MaxIndex() - 1
Select Case ArrayType
Case 2
Dim intPositions
intPositions = Positions
For I = iIndex To intEndIndex
For intPos = 0 To intPositions
g_varArray(intPos,intEndPosition) = g_varArray(intPos,intEndPosition + 1)
Next
Next
ReDim Preserve g_varArray(intPositions,intEndIndex)
Case Else
For iIndex = iIndex To intEndIndex
g_varArray(iIndex) = g_varArray(iIndex + 1)
Next
ReDim Preserve g_varArray(intEndIndex)
End Select
End Sub
'## ------------------------------------------------------------------
Public Sub Sort(ByVal sSortOrder, ByVal iPos)
Dim intMaxIndex ' As Integer
Dim I, X ' As Integer
Dim varTemp ' As Variant
intMaxIndex = MaxIndex()
Select Case ArrayType
Case 2
'## -- 2-dimensional array in use --
Dim intPositions, intPos
'## -- get total positions in array --
intPositions = Positions
If UCase(sSortOrder) = "ASC" Then
'## -- sort ascending --
For I = 0 To intMaxIndex
For X = (I + 1) To intMaxIndex
If g_varArray(iPos, I) > g_varArray(iPos,X) Then
For intPos = 0 To intPositions
varTemp = g_varArray(intPos, I)
g_varArray(intPos, I) = g_varArray(intPos, X)
g_varArray(intPos, X) = varTemp
Next
End If
Next
Next
ElseIf UCase(sSortOrder) = "DESC" Then
'## -- sort descending --
For I = 0 To intMaxIndex
For X = (I + 1) To intMaxIndex
If g_varArray(iPos, I) < g_varArray(iPos,X) Then
For intPos = 0 To intPositions
varTemp = g_varArray(intPos, I)
g_varArray(intPos, I) = g_varArray(intPos, X)
g_varArray(intPos, X) = varTemp
Next
End If
Next
Next
End If
Case Else
'## -- standard 1-dimensional array in use --
If UCase(sSortOrder) = "ASC" Then
'## -- sort ascending --
For I = 0 To intMaxIndex
For X = (I + 1) To intMaxIndex
If g_varArray(I) > g_varArray(X) Then
varTemp = g_varArray(I)
g_varArray(I) = g_varArray(X)
g_varArray(X) = varTemp
End If
Next
Next
ElseIf UCase(sSortOrder) = "DESC" Then
'## -- sort descending --
For I = 0 To intMaxIndex
For X = (I + 1) To intMaxIndex
If g_varArray(I) < g_varArray(X) Then
varTemp = g_varArray(I)
g_varArray(I) = g_varArray(X)
g_varArray(X) = varTemp
End If
Next
Next
End If
End Select
End Sub
'## ------------------------------------------------------------------
'## -- get iData random values from array --
Public Function Random(ByVal iData)
Randomize
Dim varArray
Dim varArray_tmp
Dim intMaxIndex
Dim intRandomIndex
Dim N
varArray_tmp = g_varArray
intMaxIndex = MaxIndex()
Select Case ArrayType
Case 2
Dim intPos
Dim X
intPos = Positions
ReDim varArray(intPos, iData - 1)
'## -- get iData random values from array --
For N = 0 To iData - 1
'## -- get random index values from "mother" array --
intRandomIndex = CInt(rnd * (intMaxIndex - N))
'## -- save random data --
For X = 0 TO intPos
[b]varArray(X, N) = varArray_tmp(X,intRandomIndex)[/b] <---
[b]varArray_tmp(X, intRandomIndex) = varArray_tmp(X,intMaxIndex - N)[/b] <---
Next
Next
Case Else
ReDim varArray(iData - 1)
'## -- get iData random values from array --
For N = 0 To iData - 1
'## -- get random index value from "mother" array --
intRandomIndex = CInt(rnd * (intMaxIndex - N))
'## -- save random data --
'Response.Write "HERE" rad 306
varArray(N) = varArray_tmp(intRandomIndex)
varArray_tmp(intRandomIndex) = varArray_tmp(intMaxIndex - N)
Next
End Select
'## -- return an array of iData random selected from "mother" array --
Random = varArray
End Function
'## ------------------------------------------------------------------
Public Function GetArray() ' As Variant
GetArray = g_varArray
End Function
'## ------------------------------------------------------------------
'## -- PRIVATE METHODS --
'## ------------------------------------------------------------------
Private Sub Class_Initialize()
'## -- set default values --
'## -- set the array to: not recently created.
IsCreated = 0
End Sub
'## ------------------------------------------------------------------
'## -- get last index (array size) of the array --
'## ------------------------------------------------------------------
Private Function MaxIndex()
Select Case ArrayType
Case 2
MaxIndex = UBound(g_varArray,2)
Case Else
MaxIndex = UBound(g_varArray)
End Select
End Function
'## ------------------------------------------------------------------
'## -- get last index (array size) of the array --
'## ------------------------------------------------------------------
Private Function MinIndex()
Select Case ArrayType
Case 2
MinIndex = LBound(g_varArray,2)
Case Else
MinIndex = LBound(g_varArray)
End Select
End Function
'## ------------------------------------------------------------------
Private Sub Class_Terminate()
'## -- do nothing --
End Sub
End Class
%>
<HTML>
<HEAD>
<TITLE>Random Image</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<BODY bgcolor="#FFFFFF" text="#000000">
<%
strSQLimg = "SELECT [id], username, bild FROM members WHERE NOT bild = 'Bilder\Medlemmar\ingen.gif'"
'strSQLimg = "SELECT * FROM tblGuestbook"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("database/members.mdb")
'objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("../db/wizeBook.mdb")
Set objRSimg = objConn.Execute(strSQLimg)
If Not objRSimg.EOF Then
varArray = objRSimg.GetRows()
End If
Set objRSimg = Nothing
objConn.Close
Set objConn = nothing
Set objArray = New clsArray
With objArray
.ArrayType = 2 '## -- a 2-dimensional array are set to be used --
.Positions = 2 '## -- 3 positions will be created on every index. positions start count at 0 --
.SetArray varArray
'## -- get randomly data as array --
varImages = .Random(6)
End With
Set objArray = Nothing
'## -- show random images --
If IsArray(varImages) Then
For N = 0 TO UBound(varImages,2)
'Response.write varImages(0,N) & "<BR>"
response.write "<a href=""krypin.asp?checkid=" & varImages(0,N) & """><img src=""" & varImages(2,N) & """ alt=""" & varImages(1,N) & """ border = ""0"" width= ""69"" height= ""87""></a>"
Next
End If
%>
</BODY>
</HTML>