+ Reply to Thread
Results 1 to 2 of 2

What is wrong with my code???

Hybrid View

  1. #1
    sand
    Guest

    What is wrong with my code???


    Hi,

    I have written the follwoing code.

    Dim clientName As String
    Dim clientNameArray()
    Dim count1 As Integer
    Dim NumberOfClients As Integer
    NumberOfClients = 0
    ReDim clientNameArray(NumberOfClients)
    clientNameArray(0) = "test"
    count1 = 1
    Dim count2 As Integer
    Do
    If....

    clientName = RecordArray(cnt1, 0)
    'clientNameArray(count1) = clientName
    MsgBox "Test1" + clientName
    'IDAccFSEB = IDAccFSEB + 1
    'count1 = 1
    'count2 = 0
    For count2 = 0 To count1
    MsgBox "Test" + clientNameArray(count2)
    MsgBox "Test2" + clientName
    If Not LCase(clientNameArray(count2)) <>
    LCase(clientName) Then
    IDAccFSEB = IDAccFSEB + 1
    clientNameArray(count2) = clientName
    MsgBox "Test" + clientNameArray(count1)
    count1 = count1 + 1
    End If
    Next
    End If
    Loop

    What happens is i retrieve the clientName from an array.
    I have instantiated the array with one record so as it not being empty.
    If the client'sName is not the same as in the array, then i should the
    client's name shpuld be inserted into the array and increment a
    counter. This counter keeps track of the number of clients. However, i
    keep getting zero for the following variable "IDAccFSEB". y? I hope
    someone can help. Its urgent. Thanx


    --
    sandPosted from http://www.pcreview.co.uk/ newsgroup access


  2. #2
    Dave Peterson
    Guest

    Re: What is wrong with my code???

    I'm confused over what you're doing, but maybe this'll help.

    If I want to load unique values from a range A1:A10 into an array, I could do it
    this way:

    Option Explicit
    Sub testme01()

    Dim ClientNameArray() As String
    Dim ClientName As String

    Dim iCtr As Long
    Dim NewNameCtr As Long
    Dim FoundAMatch As Boolean

    Dim myCell As Range

    NewNameCtr = 0
    ReDim ClientNameArray(1 To 1)

    For Each myCell In ActiveSheet.Range("a1:A10").Cells
    ClientName = myCell.Value

    If NewNameCtr = 0 Then
    'load the initial value
    ClientNameArray(1) = ClientName
    NewNameCtr = NewNameCtr + 1
    Else
    'look for a match
    FoundAMatch = False
    For iCtr = LBound(ClientNameArray) To UBound(ClientNameArray)
    If LCase(ClientNameArray(iCtr)) = LCase(ClientName) Then
    'get out, it's already there
    FoundAMatch = True
    Exit For
    End If
    Next iCtr

    If FoundAMatch = True Then
    'do nothing
    Else
    NewNameCtr = NewNameCtr + 1
    ReDim Preserve ClientNameArray(1 To NewNameCtr)
    ClientNameArray(NewNameCtr) = ClientName
    End If
    End If
    Next myCell

    If NewNameCtr > 0 Then
    For iCtr = LBound(ClientNameArray) To UBound(ClientNameArray)
    MsgBox ClientNameArray(iCtr)
    Next iCtr
    End If

    End Sub

    ===============
    But even better John Walkenbach has an easier way of loading a collection
    (similar to an array) with unique values at:
    http://j-walk.com/ss/excel/tips/tip47.htm

    I'd try to use that.



    sand wrote:
    >
    > Hi,
    >
    > I have written the follwoing code.
    >
    > Dim clientName As String
    > Dim clientNameArray()
    > Dim count1 As Integer
    > Dim NumberOfClients As Integer
    > NumberOfClients = 0
    > ReDim clientNameArray(NumberOfClients)
    > clientNameArray(0) = "test"
    > count1 = 1
    > Dim count2 As Integer
    > Do
    > If....
    >
    > clientName = RecordArray(cnt1, 0)
    > 'clientNameArray(count1) = clientName
    > MsgBox "Test1" + clientName
    > 'IDAccFSEB = IDAccFSEB + 1
    > 'count1 = 1
    > 'count2 = 0
    > For count2 = 0 To count1
    > MsgBox "Test" + clientNameArray(count2)
    > MsgBox "Test2" + clientName
    > If Not LCase(clientNameArray(count2)) <>
    > LCase(clientName) Then
    > IDAccFSEB = IDAccFSEB + 1
    > clientNameArray(count2) = clientName
    > MsgBox "Test" + clientNameArray(count1)
    > count1 = count1 + 1
    > End If
    > Next
    > End If
    > Loop
    >
    > What happens is i retrieve the clientName from an array.
    > I have instantiated the array with one record so as it not being empty.
    > If the client'sName is not the same as in the array, then i should the
    > client's name shpuld be inserted into the array and increment a
    > counter. This counter keeps track of the number of clients. However, i
    > keep getting zero for the following variable "IDAccFSEB". y? I hope
    > someone can help. Its urgent. Thanx
    >
    > --
    > sandPosted from http://www.pcreview.co.uk/ newsgroup access


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1