Results 1 to 6 of 6

Thread: User Defined arrays

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258

    Talking

    Heres what I need to do , Keep track of a name and an index number in a server application . I tried at first to do it in a text file , but I found it to hard to to parse the text and just plain complicated . "but heh is'nt it all?"
    Ok so I then thought I could store it in an array , but I dont know much about them . So I read a bit . It sounds like it'll work but Im not sure How to implement it . So I tried to make my own (Type) I did this in a .bas module . Is it right?
    In general Declare
    -----------------------
    Public Type usrArray
    sTemp As String
    iCount As Integer
    End Type
    Dim allusers(1 To 10) As usrArray
    ---------------------
    Public Sub addUser(socknum As Integer, nick As String)
    usrCounter = usrCounter + 1

    allusers(usrCounter).sTemp = "nick"
    allusers(usrCounter).iCount = socknum
    msgbox allusers(usrCount)
    End Sub
    ---------------------

    I was hoping that
    ----------------------
    Public Type usrArray
    sTemp As String
    iCount As Integer
    End Type
    Dim allusers(1 To 10) As usrArray
    ----------------------
    would give me an array of 10 items each containing a string and an integer . Back in the main form at the event I put
    Call addUser(index, nick) and I Get an Error saying Only user defined types defined in public modules can be coherced to or from a a variant but its supposed to be an array ? So Im confused .
    Is someone willing to attempt to explain to me what I need to understand and fix this Problem ?

    Once again Im trying to sore a string and a number in an array that I can increase in size to match the number of people on the server .
    Thanks ,
    []PRIVATE




    [Edited by PRIVATE1 on 08-15-2000 at 11:09 AM]

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    Put the Type declaration in the Module not in the General Declarations of the form.
    It should help

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Its in a module =)
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  4. #4
    Guest
    here this might help a little....
    ok ok. I went a little overboard


    Code:
    Private Type usrArray
    sTemp As String
    iCount As Integer
    End Type
    
    Dim usr() As usrArray
    Dim TheCount As Integer
    Dim i As Long
    Private Sub AddUser(SockNum As Integer, Nick As String)
    
      ReDim Preserve usr(TheCount)
      
      usr(TheCount).iCount = SockNum
      usr(TheCount).sTemp = Nick
      
      TheCount = TheCount + 1
      
    End Sub
    
    Private Sub Command1_Click()
    
      Call AddUser(1, "Dennis")
    
      For i = 0 To UBound(usr) - 1
        MsgBox usr(i).iCount
        MsgBox usr(i).sTemp
      Next
      
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Thank you ,
    []Private
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258

    Question

    How can I check to see if the new
    usr(TheCount).sTemp = Nick
    is in the array already ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width