Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array script problems

Status
Not open for further replies.

krappleby025

Programmer
Sep 6, 2001
347
NL
i have the following script.. which is supposed to check the value of the emailaddress against one that is entered on a form.. It is called by

emailaddress = request.form("emailaddress")

but this script is not generating the response needed, if the email matches then the duplicate field is supposed to read 1.. So that further scripts later can report the error.

Any ideas

dim myarray(8)
set fs = CreateObject("Scripting.FileSystemObject")
set txtfile = fs.OpenTextFile_("F:\Krapp\prize\prize.txt",1,0)
do while txtfile.AtEndOfStream = false
myArray(counter) = split(txtfile.ReadLine,",")
if myArray(2) = emailaddress then
duplicate = "1"
end if
loop
txtfile.close
set txtfile = nothing

The file is set out in the following manner

name, email, town, choice1, choice2, choice3, choice4, choice5

thanks in advance
 
What is "counter"?

myArray(counter) = split(txtfile.ReadLine,",")

and won't the way your using "myArray" and "counter" cause if myArray(2) = emailaddress then to never evaluate to true?

-pete

 
i dont knwo what counter is. i got the script from another person
how would i redo it then to place all results into the correct arrays
 
Yes counter is the incrementer, but I don't see where it is needed. If you always know that email is in the second position then you wouldn't have to increment through the array. You should just be able to populate the array without the counter like:
myArray = split(txtfile.ReadLine,",")

Depending on your system settings, you need to check to see if your arrays are 0 or 1 based.

If 0 based then:
if myArray(1) = emailaddress then...

If 1 based then:
if myArray(2) = emailaddress then...

You also might want to try trimming the whitespace when doing comparisons:
if Trim(myArray(1)) = Trim(emailaddress) then...
 
non of these are working.. i dont understand this

any other ideas
 
See the duplicate post for the answer. fzylgk's first paragraph will actually solve the issue, but I read this post second so I wasn't aware it was already answered. See the other one for explanation.

-Tarwn

[sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
>> i dont understand this
>> any other ideas

Besides understanding how arrays work? I guess someone could do the work for you. Anyone?

That's the only two options i see. Maybe there are more... dunno.
-pete

 
i know how an array works, however either the results are not being placed into the array, or the results that are placed into the array are not the same format as the checking value..
 
Sionce this thread is beginning to get tiring and the answer has already been posted twice, here is the correction that will work:
Code:
do while txtfile.AtEndOfStream = false 
myArray = split(txtfile.ReadLine,",")
if myArray(1) = emailaddress then
duplicate = "1"
end if
loop
txtfile.close
set txtfile = nothing

The reasoning is explained in the duplicate thread, but I believe no one bothered to check that out anyways. If this does not work than there is something wrong with the earlier code that is creating the stream or the format of the text file. Everything else appears to be fine, though I was to lazy to actually write a test script to try this.

-Tarwn

[sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
myArray = split(txtfile.ReadLine,",")

Notice the lack of the use of the variable count which is what i originally posted hours ago.

krappleby025
>> i know how an array works,

All evidence to the contrary.

Tarwn
>> this thread is beginning to get tiring

Agreed.

Tarwn
>> The reasoning is explained in the duplicate thread, but
>> I believe no one bothered to check that out anyways

I didn't need to read the second thread since i had already posted the solution in this thread [hammer]

-pete

 
right i have just used your script

and this is the error i get

Microsoft VBScript runtime error '800a000d'

Type mismatch

/prize/addtotxtfile.asp, line 43

i have tried to do what you said but IT DOES NOT WORK

ok and from the post about it must be something to do with earlier int he script.. THE ONLY part of the script that is used is the command

emailaddress = request.form("emailaddress")

which allocates a form result to the variable emailaddress.

the script works fine without this section, but it needs this section in it

thanks
 
I just noticed something...whats that underscore after OpenTextFile doing? Is that an error in copying or part of your original code?



[sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
in this forum, the actual entry box is not as big as the screen, and the line took two lines, so i added that in the text box, in case it was going to print on two lines

it shows the next line is part of the last...
 
Ok, I decided to check out this code, here is my working test:
Code:
<%
If Request.Form(&quot;emailaddress&quot;) <> &quot;&quot; Then
	emailaddress = request.form(&quot;emailaddress&quot;)

	dim myarray
	set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)
	set txtfile = fs.OpenTextFile(Server.MapPath(&quot;aCsvFile.csv&quot;),1,0)
	do while txtfile.AtEndOfStream = false
		myArray = split(txtfile.ReadLine,&quot;,&quot;)
		if myArray(1) = emailaddress then
			duplicate = &quot;1&quot;
		end if
	loop
	txtfile.close
	set txtfile = nothing
	Response.Write &quot;Dup: &quot; & duplicate
Else
	%>
	<html>
	<body>
	<form method=&quot;POST&quot; action=&quot;<%=Request.ServerVariables(&quot;SCRIPT_NAME&quot;)%>&quot;>
	<input type=&quot;text&quot; name=&quot;emailaddress&quot;>
	<input type=&quot;submit&quot;>
	</form>
	<%
End If
%>

The only real changes I made were in using Server.MapPath to get the text file, which shouldn't matter
I removed the underscore from OpenTextFile
I stop declaring MyArray as an array and assiging myArray(counter) and instead declared MyArray and didn't use an index.

This script works for me.

-Tarwn

[sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top