Results 1 to 40 of 98

Thread: good old arrays

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Location
    North London
    Posts
    121

    Re: good old arrays

    do i still need need the module?

    do i still need the "students" array?

    can you provide me with an example of how it should look if i dont need use the module?

    thank you

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: good old arrays

    Do you still need the module, no but if you want to keep the Students array you'll need to make it Private in the form.

    I just showed you how to use the new arrays. Give it a try and I'll help if you need it.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Location
    North London
    Posts
    121

    Re: good old arrays

    i removed the module as its not required.... here goes

    Code:
    Option Explicit
    Dim Element As Integer
    Private NameArray() As String
    Private MarkArray() As Integer
    
    Private Sub cmdAddRecord_Click()
        '~~~ Checking. This should be done first !
        If Val(txtStudentMark.Text) <= 0 Then
            MsgBox "student mark cannot be less than zero. Please re-enter it"
            Exit Sub
        ElseIf Val(txtStudentMark.Text) > 100 Then
            MsgBox "student mark cannot be greater than 100. Please re-enter it"
            Exit Sub
        End If
        
     
        NameArray().StudentName = txtStudentName.Text
        MarkArray().StudentMark = txtStudentMark.Text
    
           
        lstNames.AddItem txtStudentName.Text
        lstMarks.AddItem txtStudentMark.Text
    
    
    End Sub
    that doesnt work, i receive an "invalid qualifer" error message...

    im confused with how to get assign the array to "txtstudent and txtmark.text" any ideas?? is that my error??
    Last edited by xirokx; Apr 6th, 2010 at 09:12 PM.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: good old arrays

    Notice this code that used to be in cmdAddRecord_Click

    Code:
        Element = Element + 1
        ReDim Preserve Students(1 To Element) '~~~> We are dynamically allocating size for the array
    
        Students(Element).StudentName = txtStudentName.Text
        Students(Element).StudentMark = txtStudentMark.Text
    Do you see the difference from what you are doing?

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