Solved

combining variable strings in ASP VBScript

Posted on 2010-08-18
5
556 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

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
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

751 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