|
-
Mar 20th, 2002, 07:57 PM
#1
Thread Starter
Member
Storing A Username and IP address in an array
I am working on a chat program, and have the UDP server set up, but I need a way (unlike mine) that can store, retrieve, and delete usernames and IP addresses from an array. The array is named
IPList
and has the dimensions
(1 to 2, 1 to 100000)
1 is the Username, 2 is the IP address.
My current way can store one username, but has a problem with the second one. It seems to erase both of them. If you could give me a new algorithm, I would really appreciate it.
And then, with BSChat working, I shall take over the world...er...not.
-brian728s
[email protected]
-
Mar 20th, 2002, 09:51 PM
#2
Can you post the code ur using to write to the Array.
-
Mar 21st, 2002, 04:46 PM
#3
Thread Starter
Member
Public IPList(1 To 2, 1 To 100000) As String
Public Function FindIndex(Search As String) As Double
Dim i As Double
FindIndex = -1
For i = 1 To 100000
If IPList(1, i) = Search Then
FindIndex = i
Exit Function
End If
Next i
End Function
Public Function NewUser(Name As String, IP As String) As Boolean
Dim a As Double
Dim Name2 As String
Name2 = Replace(Name, Chr(1), "")
a = FindBlankIndex()
If FindIndex(Name2) = -1 Then
a = FindBlankIndex
IPList(1, a) = Name
IPList(2, a) = IP
NewUser = True
Else
NewUser = False
End If
End Function
Public Sub LogOut(Name As String)
Dim a As Double
a = FindIndex(Name)
If a <> -1 Then
IPList(1, a) = ""
IPList(2, a) = ""
End If
End Sub
Public Function FindBlankIndex() As Double
FindBlankIndex = -1
Dim i As Double
For i = 1 To 100000
If IPList(1, i) = "" Then
FindBlankIndex = i
Exit Function
End If
Next i
End Function
FindBlankIndex Works and returns the index of the first blank record in IP list. Findindex works as far as I know. NewUser and logout are the ones that are driving me insane. They apparantly can store and retrieve the first one, but don't work with any ones over that.
-
Mar 21st, 2002, 04:54 PM
#4
Need-a-life Member
Next time, paste your code between vbcode tags. It's easier to read. I'll paste his code again:
VB Code:
Public Function FindIndex(Search As String) As Double
Dim i As Double
FindIndex = -1
For i = 1 To 100000
If IPList(1, i) = Search Then
FindIndex = i
Exit Function
End If
Next i
End Function
Public Function NewUser(Name As String, IP As String) As Boolean
Dim a As Double
Dim Name2 As String
Name2 = Replace(Name, Chr(1), "")
a = FindBlankIndex()
If FindIndex(Name2) = -1 Then
a = FindBlankIndex
IPList(1, a) = Name
IPList(2, a) = IP
NewUser = True
Else
NewUser = False
End If
End Function
Public Sub LogOut(Name As String)
Dim a As Double
a = FindIndex(Name)
If a <> -1 Then
IPList(1, a) = ""
IPList(2, a) = ""
End If
End Sub
Public Function FindBlankIndex() As Double
FindBlankIndex = -1
Dim i As Double
For i = 1 To 100000
If IPList(1, i) = "" Then
FindBlankIndex = i
Exit Function
End If
Next i
End Function
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Mar 21st, 2002, 05:12 PM
#5
Need-a-life Member
I would redim the array un run-time as needed, if you like to improve it.
Try this code, I remove the FindBlankIndex function... and didn't test it so I don't know if it works.
VB Code:
Public Function FindIndex(Search As String) As Double
Dim i As Double
FindIndex = -1
For i = 1 To 100000
If IPList(1, i) = Search Or IPList(1, i) = "" Then
FindIndex = i
Exit Function
End If
Next i
End Function
Public Function NewUser(Name As String, IP As String) As Boolean
Dim a As Double
Dim Name2 As String
Name2 = Replace(Name, Chr(1), "")
a = FindIndex(Name2)
If IPList(1, a) = "" Then
IPList(1, a) = Name
IPList(2, a) = IP
NewUser = True
Else
NewUser = False
End If
End Function
Public Sub LogOut(Name As String)
Dim a As Double
a = FindIndex(Name)
If IPList(1, a) <> "" Then
IPList(1, a) = ""
IPList(2, a) = ""
End If
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Mar 21st, 2002, 05:24 PM
#6
Member
FYI, if these are username/ip pairs, then IMHO this would be MUCH easier than a matrix:
VB Code:
Public Type UsernameIPPair
Username As String
IP As String
End Type
Dim Users(0 To SomeBigNumber) As UsernameIPPair
Msgbox Users(0).Username
Msgbox Users(x).IP
.
.
.
-
Mar 21st, 2002, 05:26 PM
#7
-
Mar 21st, 2002, 05:27 PM
#8
Member
True, I'm just saying for future reference...one of my programs uses a matrix and it makes it really hard to code
-
Mar 21st, 2002, 08:40 PM
#9
Thread Starter
Member
Thank you! I used type once before, but couldn't remember it for this one. I will post a link to my website with a free download once I get it working.
-
Mar 21st, 2002, 08:50 PM
#10
Need-a-life Member
Beware!!
This is a correction to the code
VB Code:
Public Function NewUser(Name As String, IP As String) As Boolean
Dim a As Double
Dim Name2 As String
Name2 = Replace(Name, Chr(1), "")
a = FindIndex(Name2)
[b]If a > 0 Then[/b]
If IPList(1, a) = "" Then
IPList(1, a) = Name
IPList(2, a) = IP
NewUser = True
Else
NewUser = False
End If
[b]Else
MsgBox "Sorry, the list is full"
End If[/b]
End Function
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|