Solved

combining variable strings in ASP VBScript

Posted on 2010-08-18
5
551 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

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.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

831 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