Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split creates variant not array

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
0
0
CA
Hi Guys,

I have a simple process whereby I split a comma separated string. The issue is that it comes back as a variant data type not an array and this blocks the rest of my process from working

The code is:

Code:
' sADMIN_ALLOWED_HTML_TAGS = "P,BR,UL,OL,LI"

if sADMIN_ALLOWED_HTML_TAGS <> "" then
  arrAllowedHTMLList = split(sADMIN_ALLOWED_HTML_TAGS, ",")
  ubound_arrAllowedHTMLList = ubound(arrAllowedHTMLList)
end if

I am curious as to how to solve this. I can hard code the list, but would prefer it come from a db call to allow for more flexibility in the future. I am also starting to see this issue crop up in other applications where we use the SPLIT command.

Any ideas?

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Works for me: get 4

BTW, how is dimmed arrAllowedHTMLList ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Treat the variant as an array (which it is).

This works for me:
Code:
sADMIN_ALLOWED_HTML_TAGS = "P,BR,UL,OL,LI"

if sADMIN_ALLOWED_HTML_TAGS <> "" then
  arrAllowedHTMLList = split(sADMIN_ALLOWED_HTML_TAGS, ",")
  ubound_arrAllowedHTMLList = ubound(arrAllowedHTMLList)
end if

'wscript.echo(ubound_arrAllowedHTMLList)
for i = 0 to ubound_arrAllowedHTMLList
wscript.echo(arrAllowedHTMLList(i))
next

What exactly are you having trouble with?
 
The array comes back as a type VARIANT and the ubound returns -1

Then I can't access the array.



Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
>The issue is that it comes back as a variant

All VBScript variables are variants ...


>this blocks the rest of my process from working

In what way is it blocking it?
 
The code you originally posted won't work because the 'allowed tags' line is commented out. Either you are getting that variable from somewhere else, or there is an error in other code that you have not shown.
 
@strongm

Yes, I know they are all variants, but when the typename comes back as Variant the calls to ubound and IsArray fail
Ubound comes back with -1 and the isarray returns false


@jges

Yes its commented out, it was to show you the values, the real variable data is from a db call.


Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
the real variable data is from a db call
Did you debug the real value of the real variable ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You should be able to see easily enough that the code you posted (after uncommenting the first line) works. So, the problem must be with your "db call".

My guess would be that you are getting a blank or a null from the database. Easy to test, just echo the contents of sADMIN_ALLOWED_HTML_TAGS after it gets its value, and see if it's what you expected
 
Given the now explained "issues" (variant, returns -1 from the ubound call, isarray returns false) I'd have to concur with guitarzan. You are getting a dud value from the db call.
 
I wish it was that simple. The db call returned exactly what the code snippet showed as the value for sADMIN_ALLOWED_HTML_TAGS. I response.write it out and copied the text.

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
I'd response.write it just after the Split.

BTW, no On Error Resume Next instruction ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
> I response.write it out and copied the text
OK, so this is VBScript with classic ASP?

I recommend the following code as a test:

Code:
response.write "sADMIN_ALLOWED_HTML_TAGS: " & sADMIN_ALLOWED_HTML_TAGS
if sADMIN_ALLOWED_HTML_TAGS <> "" then
  arrAllowedHTMLList = split(sADMIN_ALLOWED_HTML_TAGS, ",")
  ubound_arrAllowedHTMLList = ubound(arrAllowedHTMLList)
  response.write "UBound is " & ubound_arrAllowedHTMLList
else
  response.write "sADMIN_ALLOWED_HTML_TAGS is empty"
end if

Otherwise you will have to show your database code call for further help. And if you are using Classic ASP, you might want to post in forum333

And PHV has a good point about On Error Resume Next. Another thing is to use Option Explicit at the top... maybe you are misspelling the variable name sADMIN_ALLOWED_HTML_TAGS when it is assigned its value??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top