Avatar billede EIHP Juniormester
04. marts 2006 - 12:01 Der er 12 kommentarer og
1 løsning

Arrey virker ik rigtigt??

Min arrey ser sådan her ud: 5,1,2,3,4,6,7
Men den siger UBound(arrFriendViewByProfile) = 6 og ik 7
Avatar billede eagleeye Praktikant
04. marts 2006 - 12:03 #1
Det er fordi første index i et array har index 0 og ikke 1. Så det sidste element har index antal-1 og ikke antal i arrayet.
Avatar billede EIHP Juniormester
04. marts 2006 - 12:14 #2
Det jeg godt klar over..
5 = 0
7 = 6
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strDatabase

strSQL = "Select * from Friends where notlist = 0 order by Id"
Set rs = Conn.Execute(strSQL)
strMakeFriendViewByProfile = "5"

Do
strMakeFriendViewByProfile = strMakeFriendViewByProfile & "," & rs("Id")
rs.MoveNext
Loop While Not rs.EOF

arrFriendViewByProfile = Split(strMakeFriendViewByProfile,",")

Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing

Function FindProfileNr(id)
For FP = 0 to 255
If FP = id then
strFP = FP
Stop
End If
Next
FindProfileNr = strFP
End Function

if FindProfileNr(rs("id")) = 1 then
    strForrige = UBound(arrFriendViewByProfile)
    else
    strForrige = arrFriendViewByProfile( int( FindProfileNr(rs("id")) - 1 ) )
    End If
   
    if FindProfileNr(rs("id")) = UBound(arrFriendViewByProfile) then
    strNext = 1
    else
    strNext = arrFriendViewByProfile( int( FindProfileNr(rs("id")) + 1 ) )
    End If

Microsoft VBScript runtime  error '800a0009'

Subscript out of range: 'Int(...)'

/ap/friends.asp, line 113
Avatar billede eagleeye Praktikant
04. marts 2006 - 12:51 #3
Denne if sætning som tjekker om rs("id") er sidste element i array:

    if FindProfileNr(rs("id")) = UBound(arrFriendViewByProfile) then

Skal havde +1 på:

    if FindProfileNr(rs("id")) = UBound(arrFriendViewByProfile)+1 then
Avatar billede eagleeye Praktikant
04. marts 2006 - 13:11 #4
nu har jeg kigget lidt på din funktion: FindProfileNr(id)

Så vidt jeg kan giver den bare samme tal tilbage som man overføre til den.
Avatar billede EIHP Juniormester
04. marts 2006 - 13:12 #5
løsning?
Avatar billede EIHP Juniormester
04. marts 2006 - 13:16 #6
Function FindProfileNr(id)
For FP = 0 to 255
If arrFriendViewByProfile(FP) = id then
strFP = FP
Stop
End If
Next
FindProfileNr = strFP
End Function

Ville det være løsningen?
Avatar billede eagleeye Praktikant
04. marts 2006 - 13:18 #7
Ja det ville det, men i stedet for 255 bør man bruge ubound(arrayet)


Function FindProfileNr(id)
For FP = 0 to ubound(arrFriendViewByProfile)
If arrFriendViewByProfile(FP) = id then
strFP = FP
Stop
End If
Next
FindProfileNr = strFP
End Function
Avatar billede eagleeye Praktikant
04. marts 2006 - 13:23 #8
og så skal der også int omkring if sætningen inde i funktionen som tjekker mod id, så det bliver:

Function FindProfileNr(id)
For FP = 0 to ubound(arrFriendViewByProfile)
If int(arrFriendViewByProfile(FP)) = id then
strFP = FP
Stop
End If
Next
FindProfileNr = strFP
End Function
Avatar billede EIHP Juniormester
04. marts 2006 - 13:46 #9
Microsoft VBScript runtime  error '800a0009'

Subscript out of range: 'FP'

/ap/inc/top.asp, line 96
Avatar billede eagleeye Praktikant
04. marts 2006 - 13:49 #10
Hvordan ser koden ud som giver den fejl?
Avatar billede EIHP Juniormester
04. marts 2006 - 13:50 #11
Function FindProfileNr(id)
For FP = 0 to ubound(arrFriendViewByProfile)
If int(arrFriendViewByProfile(FP)) = id then
strFP = FP
Stop
End If
Next
FindProfileNr = strFP
End Function
Avatar billede EIHP Juniormester
04. marts 2006 - 13:53 #12
Vent.. det var denne her:
if FindProfileNr(rs("id")) = 1 then
    strForrige = int(UBound(arrFriendViewByProfile)) +1
    else
    strForrige = arrFriendViewByProfile( int( FindProfileNr(rs("id")) - 1 ) )
    End If

Men da jeg sætte denne her ind:
if FindProfileNr(rs("id")) = 1 then
    strForrige = int(UBound(arrFriendViewByProfile)) +1
    elseif FindProfileNr(rs("id")) = 0 then
    strForrige = int(UBound(arrFriendViewByProfile)) +1
    else
    strForrige = arrFriendViewByProfile( int( FindProfileNr(rs("id")) - 1 ) )
    End If

OG så virket det..
Avatar billede eagleeye Praktikant
05. marts 2006 - 10:13 #13
jeg fik ikke lavet et svar, det gør jeg lige :)
Avatar billede Ny bruger Nybegynder

Din løsning...

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.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester