27. juli 2004 - 11:06Der er
37 kommentarer og 1 løsning
Function Virker ikke
Min funktion giver "Subscript out of range" og markerer linien ' If arrSplit(1) = Index Then ' Hvad gør jeg galt? Jeg kalder funktionen sådan her:
TheArray = GetConnectionArray(1)
Og her er min kode:
Dim arrUsers(400) As String Dim arrSplit() As String Dim x As Integer
Public Function GetConnectionArray(Index As Integer) As Integer Dim strData As String For x = 0 To 400 strData = arrUsers(x) arrSplit() = Split(strData, "|") If arrSplit(1) = Index Then CheckNull = x End If Next End Function
Det er stadig det samme problem... :( Den skal finde brugernavnet på den som lukker forbindelsen.. Data'en ligger således i arrUsers "Username|WinsockConnection|Blabla..."
Public Function GetConnectionUser(Index As Integer) As String Dim strData As String For x = 1 To 400 strData = arrUsers(x) arrSplit() = Split(strData, "|") If arrSplit(1) = Index Then CheckNull = arrSplit(0) Exit For End If Next End Function
Private Sub winsock_Close(Index As Integer) Dim UserName As String UserName = GetConnectionUser(Index) End sub
Public Function GetConnectionUser(Index As Integer) As String Dim strData As String For x = 1 To 400 strData = arrUsers(x) arrSplit() = Split(strData, "|") '<- Du jo ikke opdele strData Hvis den er tom. If arrSplit(1) = Index Then '<- Klart du for fejl da arrSplit(1) ikke findes CheckNull = arrSplit(0) Exit For End If Next End Function
Public Function GetConnectionUser(Index As Integer) As String Dim strData As String For x = 1 To 400 strData = arrUsers(x) arrSplit() = Split(strData, "|") If UBound(arrSplit) > 0 Then 'Tjekker om arrSplit() er sat.. If arrSplit(1) = Index Then CheckNull = arrSplit(0) Exit For End If End If 'End UBound(.. Next End Function
Public Function GetConnectionUser(Index As Integer) As String Dim strData As String For x = 1 To 400 strData = arrUsers(x) If strData <> "" Then arrSplit() = Split(strData, "|") If arrSplit(1) = Index Then GetConnectionUser = arrSplit(0) Exit For End If End If Next End Function
Hmm... Jeg har lavet en ny funktion, og selvfølgelig den medfølgende fejl... Fejl: Expected Array, og så markerer den '' arrSplit() = ''
Min Kode:
Public Function Chat(Index As String, Text As String, Kind As String) Dim strData As String Dim arrSplit As String AddToLog "Funktion started" For x = 0 To IntMax strData = arrUsers(x) If strData <> "" Then arrSplit() = Split(strData, "|") Select Case Kind Case "Chat" If arrSplit(0) <> "Unknown" Then Winsock(x).SendData EncryptText("Chat|" & User & ": " & Text & "|Chat") AddToLog "Sent the message to a user" End Select End If Next 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.