Type mismatch: array or user-defined type expected.

Type mismatch: array or user-defined type expected.

Page 1 of 1

2 Replies - 3589 Views - Last Post: 21 August 2010 - 07:47 AM Rate Topic: -----

#1 jerry4prince  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-December 09

Type mismatch: array or user-defined type expected.

Posted 21 August 2010 - 01:29 AM

I am having an error in the cmdSearch that says Type mismatch: array or user-defined type expected. Please can someone see me through

Private Sub cmdSearch_Click()
    Dim lngMatch As Long
    ReDim DataArray(0)
    
    If txtRegNO.Text = "" Then
        MsgBox "Please make enter a Reg Number!    ", vbExclamation, "Invalid Input"
        txtNO.SetFocus   'set the cursor at the search box.
        Exit Sub
    End If
    '
    ' Search the Database for a record
    '
    DataArray(0) = txtNO.Text
    lngMatch = BinarySearch(DataArray())
    '
    ' If found, display the record
    '
    If lngMatch Then
        Call FillFields
    End If

End Sub

'This Fills the controls (text boxes and combo) with the current record from the recordset
Public Sub FillFields()
    If Not (rs.BOF = True Or rs.EOF = True) Then        'check if we are at the last or first record. This is use alot.
        txtRegNO.Text = rs.Fields("Fields2")            'RegNO = fields and display that data
        txtContactAddress.Text = rs.Fields("Fields3")   'as above
        txtStudentName.Text = rs.Fields("Fields4")      'as above
        txtPhoneNO.Text = rs.Fields("Fields5")          'as above
        txtDOB.Text = rs.Fields("Fields6")              'as above
        cboSex.Text = rs.Fields("Fields1")              'as above
    Else
        'Reset the textboxes and combox if the are no more records.
        txtRegNO.Text = ""
        txtContactAddress.Text = ""
        txtStudentName.Text = ""
        txtPhoneNO.Text = ""
        txtDOB.Text = ""
        cboSex.Text = ""
    End If
    
End Sub

Private Function BinarySearch(DataArray() As String) As Long
    Dim lngIndex As Long
    Dim lngFirst As Long
    Dim lngLast As Long
    Dim lngMiddle As Long
    Dim strSearch As String
    Dim blnDone As Boolean
    ReDim DataArray(0)

        
        lngFirst = LBound(DataArray)
        lngLast = UBound(DataArray)
            
        blnDone = (DataArray(lngFirst) > DataArray(lngLast))
    
        BinarySearch = lngFirst - 1
        
        Do Until blnDone
    '
    ' Set the pointer to the middle record
    '
            lngMiddle = (lngFirst + lngLast) \ 2
            If DataArray(lngMiddle) = strSearch Then
                BinarySearch = lngMiddle
                blnDone = True
                Exit Do
            ElseIf ((DataArray(lngMiddle) < strSearch) Xor blnDone) Then
                lngFirst = lngMiddle + 1
            Else
                lngLast = lngMiddle - 1
            End If
        Loop Until lngFirst > lngLast

End Function

This post has been edited by JackOfAllTrades: 21 August 2010 - 04:13 AM
Reason for edit:: Added code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: Type mismatch: array or user-defined type expected.

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5957
  • View blog
  • Posts: 23,226
  • Joined: 23-August 08

Re: Type mismatch: array or user-defined type expected.

Posted 21 August 2010 - 04:14 AM

When posting code, please post it in code tags...

:code:

You need to tell us what line this is occurring on.
Was This Post Helpful? 0
  • +
  • -

#3 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: Type mismatch: array or user-defined type expected.

Posted 21 August 2010 - 07:47 AM

is this code is in ado or dao why don't you try
find first or find methods

ok to remove the error
declare the function binary search with the variant parameter

This post has been edited by thava: 21 August 2010 - 07:48 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1