Alpha Video Training
Results 1 to 10 of 10

Thread: Array Puzzle?

  1. #1
    Member
    Real Name
    RT
    Join Date
    Apr 2000
    Posts
    726

    Default Array Puzzle?

    I am working on the early stages of a report preview button that uses an array to pop up a list of members by State, City, or Zip,the report will be filtered accordingly. The form is based upon a table called "tblMembers". So far, the State portion of the script works as designed. In fact, the city portion also works as designed with the exception of one annoying problem.

    The portion of the script giving me a problem is the following line:

    City(i)= alltrim(tbl.city)+ " " + alltrim(tbl.state)

    For the life of me, I cannot figure out why placing a SPACE between the city and state fields results in the array coming up blank. If I eliminate the space in the line above, both fields are properly displayed in the array.

    Please Note: using a space in the state option works perfectly as follows:

    STATE(i)= alltrim(Ltbl.STATE) + " " + alltrim(Ltbl.Abbreviation)

    I'm sure there is something obvious I did wrong, but I cannot see my own mistake. The only difference that stands out to me so far, is the use of a LookUp Table for the State option while the City option uses table.current()

    Here is the portion of the script for the City option.

    '------------------------------------------
    case alltrim(Selection) = "City"

    'Make City the current index
    'This index sorts tblMembers by alltrim(City) + " " + alltrim(State)
    'Allow the User to Preview/Print a Report Filtered by City

    Dim Choice as C
    Dim Shared ChoiceCity as C
    Dim Nrecs as N
    Dim i as N
    Dim City(3000) as C 'Use a variable instead of 3000 later

    tbl = table.current()
    tbl.index_primary_put("City")
    Nrecs = tbl.records_get()

    i=1

    tbl.fetch_first()
    while .not. tbl.fetch_eof()
    City(i)= alltrim(tbl.city)+ " " + alltrim(tbl.state)
    tbl.fetch_next()
    i=i+1
    end while

    Choice =ui_get_list_array("Select One City",1,"CITY")
    ChoiceCity = Word(Choice,1)

    debug(0)

    Dim query.description as C
    Dim query.filter as c
    Dim query.options as c
    Dim query.order as c

    query.description = "Preview Rpt. by CITY"
    query.order = ""
    query.filter = "city = ChoiceCity"
    query.options = ""
    tbl.query_create()

    :report.preview("rptMembers")

    '--------------------------------------------

  2. #2
    nick marodis
    Guest

    Default RE: Array Puzzle?

    Inplace of this "City(i)= alltrim(tbl.city)+ " " + alltrim(tbl.state)"
    try "City(i)= alltrim(tbl.city)+space(1)+ alltrim(tbl.state)"

    I find space(1) works when "" doesn't


    Have fun
    Nick

  3. #3
    Member
    Real Name
    RT
    Join Date
    Apr 2000
    Posts
    726

    Default RE: Array Puzzle?

    Hi Nick:

    Thanks for the repsponse. I should have stated in my question that I previously tried Space(1). Whether I used quotes or the Space()function, had no impact on the results.

  4. #4
    Former Alpha Employee JerryBrightbill's Avatar
    Real Name
    Jerry Brightbill
    Join Date
    Apr 2000
    Posts
    5,172

    Default RE: Array Puzzle?

    Robert,
    I just created a simple table with the fields and index you are trying to use and created a button on a table form to run the script segment you posted. The array comes up fine. I also put the script segment on the OnPrintInit event for a report and again the array comes up correctly. I can't see anything from what you posted that should be a problem. Have you tried database compact?

    Perhaps if you zip up the complete script or even a copy of the table and all of its related files, someone can find what is happening.

    Jerry

  5. #5
    Former Alpha Employee JerryBrightbill's Avatar
    Real Name
    Jerry Brightbill
    Join Date
    Apr 2000
    Posts
    5,172

    Default RE: Array Puzzle?

    I have found one problem with the script you posted. The query does not work. The filter expression does uses the wrong syntaxt. Change

    query.filter = "city = ChoiceCity"

    to

    query.filter = "alltrim(tblMembers->city) = alltrim(var->ChoiceCity)"

    This will filter the records correctly.

    Another thought. If the index you are using is corrupted, the script may hang and not be able to create the array. You could try deleting the index and then recreating it.

    Jerry

  6. #6
    Member
    Real Name
    RT
    Join Date
    Apr 2000
    Posts
    726

    Default Array Puzzle SOLVED !!!

    Hi Jerry:

    This discussion board is amazing, you solved my frustrating problem!!!!Before I talk about the solution, let me first thank you for the modification of my query filter. I must say the query filter was apparently working properly all along, however, I prefer your methodology, thanks.

    Before I posted my question to this site, I suspected the problem might be related to the index selected. Therefore, I went back, double checked the formatting of the index, and rebuilt each one. However, that did NOT solve the problem, so I assumed the cause of the array formatting problem lied elsewhere. In retrospect, that was a misguided assumption.

    After reading your suggestion, I realized there was an obvious alternative to test the index selected and see if it was the root cause. Unfotunately, I failed to consider this simple option before posting my question.

    Instead of rebuilding the indexes again, I merely changed the index in my script to record number order. And guess what Jerry? That resolved my problem, the array came up perfectly, with the desired space between city and state.

    I still don't understand why it didn't work with the CITY index because the formatting was exactly what I wanted in the Array.

    Thanks again, I love this Alpha discussion group.

    Robert

  7. #7
    Former Alpha Employee JerryBrightbill's Avatar
    Real Name
    Jerry Brightbill
    Join Date
    Apr 2000
    Posts
    5,172

    Default RE: Array Puzzle SOLVED !!!

    Glad it's working. However, I set up an index called City with the same expression you indicated you were using and the array came up fine. If you open the default browse and set the index to City, does eveything show correctly? I am thinking you may still have a corrupt index, corrupt data, or some blank records. Also rebuilding the indexes by clicking on on the build button on the define indexes option may not correct an index problem. Did you try deleting the index completely, rebuilding the remaining indexes, compacting the database, and then recreating the original index?. If the index is indeed corrupted, this should eliminate the problem.

    Jerry

  8. #8
    Member
    Real Name
    RT
    Join Date
    Apr 2000
    Posts
    726

    Default RE: Array Puzzle SOLVED !!!

    Hi Jerry:

    You might be right about the indexes being corrupt because I merely rebuilt them, I did not delete first and then rebuild. I'll give it a try a little later and let you know what happened.

    Thanks again,

    Robert

  9. #9
    Member
    Real Name
    RT
    Join Date
    Apr 2000
    Posts
    726

    Default Indexes: Corrupted?

    Hi Jerry:

    You were also right on this point. The entire cause of the display problem was the index. Once that was corrected, the Array worked properly.

    One last minor question. After I set the index to CITY, the records are ordered just the way I want them. After the Array is displayed in City & State order, and a City Variable is selected, the script subsequently runs a query where the order currently is " ".

    I'm slightly confused on this one, it appears as if I am going back to Record Order as a result of the Query? Or is Alpha somehow smart enough to leave the CITY index active? Do I have to once again set up formatting in the Order portion of the Query?

    Robert

  10. #10
    Former Alpha Employee JerryBrightbill's Avatar
    Real Name
    Jerry Brightbill
    Join Date
    Apr 2000
    Posts
    5,172

    Default RE: Indexes: Corrupted?

    I usually specify the order in a query. Then it doesn't matter what index is in effect when it is run. If you set the query order exactly the same as the expression for an existing index there is not speed penalty since it will use Lightning Query Optimization. There is more info about that in both the users guide and the xbasic manual.

    Jerry

Similar Threads

  1. string puzzle
    By Chris.Tanti in forum Alpha Five Version 6
    Replies: 4
    Last Post: 03-14-2005, 07:43 AM
  2. A New Year puzzle...
    By Paul H in forum Alpha Four Versions 7 and 8
    Replies: 1
    Last Post: 02-17-2005, 12:49 AM
  3. Scripting Puzzle
    By Tim Madison in forum Alpha Five Version 5
    Replies: 4
    Last Post: 05-18-2004, 03:27 PM
  4. Formula Puzzle
    By Bill Feldhaus in forum Alpha Five Version 5
    Replies: 13
    Last Post: 11-13-2003, 07:24 AM
  5. Puzzle 2
    By Tom Cone Jr in forum Alpha Five Version 4
    Replies: 9
    Last Post: 04-16-2001, 07:36 AM

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
  •