Is there a way to dynamically assign a subscript to a variant ?
November 21, 2018 09:44AM
Hi,

I'm trying to read a query and use subscript to add multiple members to an array. I know I can use file to array but I'm curious if there is a way to dynamically add the subscript?

Here is my code why doesn't seem to work. What I'd like is to have the subscript variable "nTripCounter" update for each record I read.


vListTrips is Variant

nTripCounter is int
HExecuteQuery(Query_Trip_WebBooking,hQueryDefault)
HReadFirst(Query_Trip_WebBooking)
WHILE not HOut(Query_Trip_WebBooking)

nTripCounter=nTripCounter+1

vListTrips.trip[nTripCounter].tripCode=Query_Trip_WebBooking.Trip_Code
vListTrips.trip[nTripCounter].tripID=Query_Trip_WebBooking.TripID
vListTrips.trip[nTripCounter].tripName=Query_Trip_WebBooking.tripName



HReadNext(Query_Trip_WebBooking)

END


sResultJson is string=VariantToJSON(sResultJson)

RESULT sResultJson


Thanks!
Re: Is there a way to dynamically assign a subscript to a variant ?
November 21, 2018 12:51PM
Hi,

Are you looking for a query count reference or are you looking for the actual record reference as it sits in the database. By doing a query you are potentially filtering records.

Try hExecuteQuery(Query_Trip_WebBooking)

nTripCounter is int = 0
this will make sure you reset .

Hope this Helps

Mike
Re: Is there a way to dynamically assign a subscript to a variant ?
November 23, 2018 10:01AM
Looks like all correct. But I would use more simple way:

vListTrips is Variant
nTripCounter is int
IF HExecuteQuery(Query_Trip_WebBooking,hQueryDefault)
  FOR EACH Query_Trip_WebBooking
    nTripCounter+=1
    vListTrips.trip[nTripCounter].tripCode=Query_Trip_WebBooking.Trip_Code
    vListTrips.trip[nTripCounter].tripID=Query_Trip_WebBooking.TripID
    vListTrips.trip[nTripCounter].tripName=Query_Trip_WebBooking.tripName
  END
END
sResultJson is string=VariantToJSON(sResultJson)
RESULT sResultJson
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: