Solved

combining variable strings in ASP VBScript

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…

758 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

27 Experts available now in Live!

Get 1:1 Help Now