Using Variant Arrays

Posted on 1997-10-29
Medium Priority
Last Modified: 2010-04-04
My question is this. I am using the type variant in a program I am writing. Now I created an array using
varArrayCreate and I will put some sample sode below. Now it is easy to read data into the variant array except when you get to the last record to read in and I keep getting list index out of bounds. Now I have tried a few different things to try and stop giving me this error. For example, if I made
the following array
tempArray := varArrayCreate([1,10],varVariant) I tried to
read in only up to tempArray[9] and still get list index is out of bounds. Now this is imossible since I am not at the end of the array. Very strange and if anyone can shed some light on this let me know. I must to doing some damn simple
the wrong way. I had a full head of hair before this problem came up. Cheers.

If (Table2.Findkey([TempJobNo]) = false) then
  TotalFields := Table1.FieldCount ;
  TempArray := varArrayCreate([0,TotalFields-1],varVariant);
    For i := 0 to TotalFields-1 do
      TempArray[i] := Table1.Fields[i].AsVariant ;
      Table1.Next ;
      TempJobNo := Table1.Fieldbyname('JOB_NO').AsString ;
      Table1.Next ;
      TempJobNo := Table1.Fieldbyname('JOB_NO').AsString ;

Question by:westy100697
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

Pegasus100397 earned 160 total points
ID: 1349171

Your right, sometimes it does help to have another programmer look over your code (works for me!). Anyway your problem is in the Table1.FieldCount loop, it SHOULD be:

TotalFields := Table1.FieldCount-1 ;
TempArray := varArrayCreate([0,TotalFields],varVariant);
For i := 0 to TotalFields do
TempArray[i] := Table1.Fields[i].AsVariant ;

The Array is going out of bounds because of the Fields[i] reference.

Good luck with your project!

Author Comment

ID: 1349172
Hey thanks for the help but solved the problem by going away and having a cuppa and it came to me all of a sudden. Happens a lot when you relax for while and come back to it. Will give you the points though cause it is exactly the prob. Thanks muchly !

Expert Comment

ID: 1349173
Glad to be of help Westy!

You'll have to reject or accept the answer before the Expert Exchange system will clear it from the list of QX's awaiting answers.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question