Solved

combining variable strings in ASP VBScript

Posted on 2010-08-18
5
546 Views
Last Modified: 2012-05-10
Hi,

I have a long string which looks like this:
SearchResponseString.ResponseBatch.Responses.get(0).SearchResult.SearchResults.get(0).PostTitle

It is used to pull a value from a JSON string.

I will be pulling multiple values from this but the only part that changes will be the end, "(0).PostTitle"

So I want to put the first part in a variable and then just change the last part as needed, like this:

Dim SearchBase
SearchBase = SearchResponseString.ResponseBatch.Responses.get(0).SearchResult.SearchResults.get

Response.Write(SearchBase+(1).PostTitle)

But this gives me error:
Microsoft VBScript runtime  error '800a01a8'
Object required: '[number: 1]'

and if I try this:
Response.Write(SearchBase&(1).PostTitle)

I get error:
Microsoft VBScript runtime  error '800a01a8'
Object required: '[number: 1]'

and if I try this:
Response.Write(SearchBase(1).PostTitle)

I get error:
Microsoft VBScript runtime  error '800a000d'
Type mismatch

So how do I get the first part of the string and last part to work together?

These are the ones that don't work:
Response.Write(SearchBase(1).PostTitle)
Response.Write(SearchBase+(1).PostTitle)
Response.Write(SearchBase&(1).PostTitle)

Thanks for any ideas.
0
Comment
Question by:elliottbenzle
5 Comments
 
LVL 2

Accepted Solution

by:
aianrnoens earned 250 total points
ID: 33464390
You cannot do it that way.   however here is something similar that should work for you.



var1 = ""
var2 = ""
var3 = ""
var4 = ""
var5 = ""
With SearchResponseString.ResponseBatch.Responses.get(0).SearchResult.SearchResults
var1 = get(0).PostTitle
var2 = get(1).PostTitle
var3 = get(2).PostTitle
var4 = get(3).PostTitle
var5 = get(4).PostTitle
end with
response.write(var1)
response.write(var2)
response.write(var3)
response.write(var4)
response.write(var5)

Open in new window

0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 250 total points
ID: 33464402
ASP is not like JavaScript where you can use eval() to run a fragment of code from a string.
That is essentially what you are trying to do - to make ASP recognize a string as a variable.
The closest you can get is this:

Dim v, w, x, y
v = SearchResponseString.ResponseBatch.Responses.get(0).SearchResult.SearchResults
w = v.get(0).PostTitle
x = v.get(1).OtherField
0
 
LVL 2

Expert Comment

by:aianrnoens
ID: 33464418
in the with block use this code instead
var1 = .get(0).PostTitle
var2 = .get(1).PostTitle
var3 = .get(2).PostTitle
var4 = .get(3).PostTitle
var5 = .get(4).PostTitle
0
 
LVL 28

Expert Comment

by:sybe
ID: 33464968
> ASP is not like JavaScript where you can use eval() to run a fragment of code from a string.

In VBScript you can use Execute() or ExecuteGlobal() to do that.
0
 
LVL 4

Author Closing Comment

by:elliottbenzle
ID: 33465342
Thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now