Solved

combining variable strings in ASP VBScript

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Message Logon Windows 2012 R2 Server 16 24
Website Interactive tool that will do calculations 3 52
Select only the top record in a left join 13 34
Scroll 5 news at a time. 4 25
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
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…

815 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

10 Experts available now in Live!

Get 1:1 Help Now