Making x amount of lists from a source list in formula

I’m doing a DBLookup that returns a list. Each list item is a fieldname in square brackets followed by a hat thing and an option value meant for the named field.

Using formula I’d like to make some variables from this list. I’d like to make several variables that will contain a list of options for that fieldname. The variables should be named according to the fieldname e.g. vCompanyName.

REM “My HTML that I want to change the select options of.” ;

MyHTML := “” ;

REM “What the DBLookup Returns” ;

NewOptions:=[CompanyName]^One:[CompanyName]^Two:[CompanyName]^Three:[Sector]^Alpha:[Sector]^Beta" ;

REM “Names of fields on my form enclosed in square brackets.” ;

HolderList:=

"[Name]" :

"[CompanyName]" :

"[Sector]" :

"[Country]" ;

REM “Creating a variable name based on the name in the square brackets of an option and populating it with each option that is meant for that field.” ;

zMakeLists:= @Transform( NewOptions ; “ListName” ; @Set( “v” + @Right( @Left( ListName ; “]^” ) ;“[” ) ; “v” + @Right( @Left( ListName ; “]^” ) ;“[” ) + ListName ) ) ;

REM “Generating the HTML options for each field” ;

MakeHTML := @Set( “z” + HolderList ; @Implode( @Transform( “v” + HolderList ; “ListItem” ; “” + @Right( ListItem ; “^” ) ) ) ) ;

REM {Replacing a keyword e.g. “[CompanyName]Options*” with the HTML options} ;

@ReplaceSubstring( MyHTML ; HolderList + “Options*” ; “z” + HolderList )

It seems to be creating the variable names, but populating them with the field name and the entire contents of NewOptions rather than just the ones for that field.

I’m thinking maybe @Transform isn’t the way to go and that I should somehow count the amount of options for each field and then use @Subset to pull them out, but not sure how I would pull out options in the middle of a list with @Subset.

Any ideas anybody?

Thanks

Ross