vbScript array problem

admin

Administrator
Staff member
<html>
<head>
<title>novaPro Open Tag Search</title>
</head>

<body>

<%

strInput = Request.Form("keywords")

%>
<form action='test.asp' method='post'>
<input type='text' name='keywords' value='<%=strInput%>'>
<br>
<br>

<button type='submit'>Search</button>
</form>

<%

if strInput = "" then
strPage = 0
end if

if strInput <> "" then
i = 2
j = 0
strInput = strInput & " "

Dim strArray()

do while i > 1
if Asc(strInput) <> 34 then
i = InStr(strInput, " ")

ReDim strArray(j)
strArray(j) = Left(strInput, i-1)
Response.Write(strArray(j) & "<br>" & chr(13))
j = j + 1

strInput = Right(strInput, Len(strInput)-i)
else
i = InStr(strInput, Chr(34))
strInput = Right(strInput, Len(strInput) - 1)

i = InStr(strInput, Chr(34))

ReDim strArray(j)
strArray(j) = Left(strInput, i-1)
Response.Write(strArray(j) & "<br>" & chr(13))
j = j + 1

strInput = Right(strInput, Len(strInput)-i)
end if
loop

For k = 0 to j-1
Response.Write(strArray(k) & "<br>" & chr(13))
next
end if
%>

Okay - strange problem here...

When I am populating the array strArray I can access the information, but at the end of the script, I can't get the information back out again...

any of you vb-heads got any ideamaybe the code never gets there, are you sure the while loop ends sucessfully? have you tried a simple

Response.Write("TEST")

after the whille loop?the for loop does work, because the <br> and carriage return are inserted into the HTML script... it's just that the array appears to be empty...whats the Asc() funciton do? i get an error on itAsc() returns the ASCII code of the first character in a string - code 34 is a double quote.

Strange that you get an error, because it is fine for me...I found it...

Apparently when you use ReDim to dynamically resize an array, you end up with an empty array again...

I'm slowly getting there, but I have to say that I hate not being able to have properly dynamic arrays like you would in PHP...nice one, i wonder why i get an error?Originally posted by Horus_Kol
I found it...

Apparently when you use ReDim to dynamically resize an array, you end up with an empty array again...

I'm slowly getting there, but I have to say that I hate not being able to have properly dynamic arrays like you would in PHP...


Thats not completely true. You can redim the array completely dynamic in VB but only the right most dimension.

Dim ary 'Notice no ()

ReDim Preserve ary(10)

By the way you can save the information in the array by using "Preserve", it does a memcpy.

Also if you need to test data types use the Is* functions like isArray,IsDate,IsNumeric etc.

<!-- m --><a class="postlink" href="http://msdn.microsoft.com/scripting">http://msdn.microsoft.com/scripting</a><!-- m -->

download Active Scripting Documentation. It is for client documentation, however the only real difference is the object creation, IE CreateObject for a server out of process while Server.CreateObject is in process.Use the VB Constants!!!

Response.Write(strArray(j) & "<br>" & vbNewLine)

Also VB is backwards with its escape character its string terminator is the same as its escape char.

string = """

prints "I think the solution to your problem is just being overlooked.


To create your array just use Split function

Dim strInput
Dim aryInput

strInput = Request.Form("keywords")
aryInput = Split(strInput," ")

if isArray(aryInput) then
for i = 0 to Ubound(aryInput)
Response.Write(aryInput(i))
Next
End if

The Asc function only takes the first character if you have mutliple char string. Otherwise you should use
Asc(Mid(strInput,i,1))thanks for all that AB, but I got my script working fine now...


I tried:

Dim ary

ReDim ary(10)

but got a type mismatch error...


Originally Posted by Afterburn
The Asc function only takes the first character if you have mutliple char string. Otherwise you should use
Asc(Mid(strInput,i,1))
I know:
Originally Posted by Horus_KolAsc() returns the ASCII code of the first character in a string - code 34 is a double quote.
:P


But, like I said, it's all alright now - I'm breaking the input string accordingly...

(Basically, I'm after the same type of input as you get in Google - the search is an OR operation of the inputs, with space characters as the delimiters, but elements within quotes are treated as "exact phrase" - now just got to do the AND function :) )Your going to love that LOL... If your using MS-SQL just use RANK function, then give each part of the query a 1.0 or less for values like "it" and such so that it doesn't dilute the data.heh... MS-SQL Server? no such luck...

I got a dsn-less ODBC connection into a boggy-standard MS-Access database :P

It's just a nice little tool that we're adding into some (bespoke) off-the-shelf (and please don't ask how you can be off-the-shelf and bespoke - too complicated) system we have.
 
Back
Top