Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: dynamic arrays

  1. #1
    Join Date
    Aug 2003
    Location
    London,UK
    Posts
    54

    Cool Unanswered: dynamic arrays

    i have created a dynamic array.

    the problem that i have is that at run time this arraymay or may not be populated by using redim.

    some code later needs to look at the arrray and extract information out of it but if it hasnt been populated then i get an error...sub script out of range.

    the code is

    For counter = LBound(propertyListArray) To UBound(propertyListArray) - 1
    strSQLArray = strSQLArray & "((propfixedMade.propref="
    strSQLArray = strSQLArray & "'" & propertyListArray(counter) & "'"
    strSQLArray = strSQLArray & ")) OR "
    Next

    strSQLArray = Left(strSQLArray, (Len(strSQLArray) - 4))
    strSQLArray = strSQLArray & ")"
    strSQL = "SELECT propfixedMade.propref, propfixedMade.houseno, propfixedMade.proadd1, propfixedMade.proadd2, " & _
    "propfixedMade.proadd3 , propfixedMade.propstcde " & _
    "FROM propfixedMade " & _
    "WHERE ((propfixedMade.proclass)='R') AND ((propfixedMade.rentgpcode)='G1') " & _
    "AND ("

    strSQL = strSQL & strSQLArray

    lstCPLPropertiesInList.RowSource = strSQL


    what i am doing is creating an sql from the information in the array that can be used to populate the listbox.


    how can i decide if there is inforamtion in the arrray or not and thus avoiding the error.

    thanks in advance

  2. #2
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447

    Re: dynamic arrays

    Originally posted by tinkxtheminx

    For counter = LBound(propertyListArray) To UBound(propertyListArray) - 1 "AND ("

    You have to make a separate function, retrieving your array limits, as


    private function LimitPropListArray(LowerBound as boolean) as long
    dim b as long
    on error resume next
    if LowerBound then
    let b=LBound(propertyListArray)
    if err then
    call err.clear
    let b = 1
    end if
    else
    let b=UBound(propertyListArray)
    if err then
    call err.clear
    let b = 0
    end if
    end if
    let LimitPropListArray=b
    end function


    If your option base is not 1 as assumed in my example, but 0, the values should change into 0 and -1, respectively.
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  3. #3
    Join Date
    Aug 2003
    Location
    London,UK
    Posts
    54
    what parameter is passed to this function

  4. #4
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447
    Originally posted by tinkxtheminx
    what parameter is passed to this function
    Whether you want to Lower or Upper bound from that array
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  5. #5
    Join Date
    Aug 2003
    Location
    London,UK
    Posts
    54
    can you give me an example of how i would call this function

  6. #6
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447
    Originally posted by tinkxtheminx
    can you give me an example of how i would call this function
    Instaed of

    For counter = LBound(propertyListArray) To UBound(propertyListArray)

    you would have to say

    For counter = LimitPropListArray(True) To LimitPropListArray(False)
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  7. #7
    Join Date
    Aug 2003
    Location
    London,UK
    Posts
    54
    this only brings out the first element n the array and not all of them

  8. #8
    Join Date
    Aug 2003
    Location
    London,UK
    Posts
    54
    doctorblue did u send me a private message, cus my email says u did but there is nuttin there?

  9. #9
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447
    Originally posted by tinkxtheminx
    doctorblue did u send me a private message, cus my email says u did but there is nuttin there?
    Yes I did. My message was:

    I don't understand your remark. You wanted a solution for determining the lower and upper bound of a dynamic array, which may not yet instantiated.

    I gave you a solution, incapsulating the possible error by using the standard functions within a separate function, but still determining the bounderies.

    So, is your problem, that you did not take into account that your code should not run when your array isn't filled yet? Otherwise, I can't image why you are talking about not getting an array member.
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  10. #10
    Join Date
    Aug 2003
    Location
    London,UK
    Posts
    54
    yes, the code should not run if the array has not yet been filled yet, that i s why i needed to know if it had been filled up. sorry for the missunderstanding.

  11. #11
    Join Date
    Aug 2003
    Location
    Bosnia & Hercegovina
    Posts
    57
    how about trapping that error with On Error, and checking code in order to decide if it is going to run the rest of code or just skip it......

  12. #12
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447
    Originally posted by tinkxtheminx
    yes, the code should not run if the array has not yet been filled yet, that i s why i needed to know if it had been filled up. sorry for the missunderstanding.
    Let the function return -x (x=1 or 2 or ....) as lower or upper bound if the array isn't instantiated yet, and test this value in the beginning? Seems obvious to me ....
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  13. #13
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447
    Originally posted by Strucnjak
    how about trapping that error with On Error, and checking code in order to decide if it is going to run the rest of code or just skip it......

    This is an quick 'n dirty alternative under two conditions:

    1) if the array isn't instantiated yet, the procedure should be exited
    2) the array bounderies ain't used elsewhere
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  14. #14
    Join Date
    Aug 2003
    Location
    London,UK
    Posts
    54
    Private Sub Form_Load()
    Dim strSQL As String
    Dim strSQLArray As String
    Dim counter As Integer
    Dim counter2 As Integer
    Dim listText As String


    For counter = propertyListArrayLimits(True) To propertyListArrayLimits(False)

    Next

    If counter > 0 Then
    For counter2 = LBound(propertyListArray()) To UBound(propertyListArray())
    strSQLArray = strSQLArray & "((propfixedMade.propref="
    strSQLArray = strSQLArray & "'" & propertyListArray(counter2) & "'"
    strSQLArray = strSQLArray & ")) OR "
    Next
    strSQLArray = Left(strSQLArray, (Len(strSQLArray) - 4))
    strSQLArray = strSQLArray & ")"

    strSQL = "SELECT propfixedMade.propref, propfixedMade.houseno, propfixedMade.proadd1, propfixedMade.proadd2, " & _
    "propfixedMade.proadd3 , propfixedMade.propstcde " & _
    "FROM propfixedMade " & _
    "WHERE ((propfixedMade.proclass)='R') AND ((propfixedMade.rentgpcode)='G1') " & _
    "AND ("

    strSQL = strSQL & strSQLArray

    lstCPLPropertiesInList.RowSource = strSQL
    End If
    End Sub

    thisd is what i have used and it seem to be working ok, is the the ideal whay to run it.

  15. #15
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447
    Originally posted by DoktorBlue
    Let the function return -x (x=1 or 2 or ....) as lower or upper bound if the array isn't instantiated yet, and test this value in the beginning? Seems obvious to me ....

    Or better: check the value of strSQLArray after the loop. If it's = vbNullString you can decide how to continue.
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

Posting Permissions

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