Max number of "vars"

S

Simon

Hi everybody..

I'm having a big problem and I think it has something to do with a maximum
of variables that can be used..
I need to set 16495 variables..
With a smaller amount the script works, but with this number the script
doesnt work anymore..

It goes like this:
var tmp1 = '002RtdOosterhof.jpg';
if (fileName == tmp1) {var stop = 'JA';
}
var tmp2 = '003RtdNoordmolen.jpg';
if (fileName == tmp2) {var stop = 'JA';
}
var tmp3 = '004RotterdamZuidplein.TIF';
if (fileName == tmp3) {var stop = 'JA';
}
var tmp4 = '004RotterdamZuidplein.jpg';
if (fileName == tmp4) {var stop = 'JA';
.......etc............ all the way to var tmp16495

(The reason why there are so many is beacuse it runs through a table that
has all the uploads registered, and i need to compare them with the selected
file before uploading it, so that an existing file will not be overwritten.)

Any ideas?
 
C

Captain Paralytic

Hi everybody..

I'm having a big problem and I think it has something to do with a maximum
of variables that can be used..
I need to set 16495 variables..
With a smaller amount the script works, but with this number the script
doesnt work anymore..

It goes like this:
var tmp1 = '002RtdOosterhof.jpg';
if (fileName == tmp1) {var stop = 'JA';}

var tmp2 = '003RtdNoordmolen.jpg';
if (fileName == tmp2) {var stop = 'JA';}

var tmp3 = '004RotterdamZuidplein.TIF';
if (fileName == tmp3) {var stop = 'JA';}

var tmp4 = '004RotterdamZuidplein.jpg';
if (fileName == tmp4) {var stop = 'JA';
......etc............ all the way to var tmp16495

(The reason why there are so many is beacuse it runs through a table that
has all the uploads registered, and i need to compare them with the selected
file before uploading it, so that an existing file will not be overwritten.)

Any ideas?

Why don't you use an array?
Why don't you check the file serverside?
 
R

RobG

Hi everybody..

I'm having a big problem and I think it has something to do with a maximum
of variables that can be used..
I need to set 16495 variables..
With a smaller amount the script works, but with this number the script
doesnt work anymore..

It goes like this:
var tmp1 = '002RtdOosterhof.jpg';
if (fileName == tmp1) {var stop = 'JA';}

var tmp2 = '003RtdNoordmolen.jpg';
if (fileName == tmp2) {var stop = 'JA';}

var tmp3 = '004RotterdamZuidplein.TIF';
if (fileName == tmp3) {var stop = 'JA';}

var tmp4 = '004RotterdamZuidplein.jpg';
if (fileName == tmp4) {var stop = 'JA';
......etc............ all the way to var tmp16495

(The reason why there are so many is beacuse it runs through a table that
has all the uploads registered, and i need to compare them with the selected
file before uploading it, so that an existing file will not be overwritten.)

Put your filenames in an array, then iterate over it to test against
the selected filename. Here's one version:

var fileNames = [
'002RtdOosterhof.jpg',
'003RtdNoordmolen.jpg',
'004RotterdamZuidplein.TIF',
'004RotterdamZuidplein.jpg',
...
];

function checkFilename( fName ){
var i = fileNames.length;
while (i--) {
if (fName == fileNames) return true;
}
return false;
}

If you are unsure about capitalisation, make all the values in
fileNames lower case and test with:

if (fName.toLowerCase() == fileNames) return true;


You could also set the filenames as properties of an object and use:

var fNameObj = {
'002RtdOosterhof.jpg' : '',
'003RtdNoordmolen.jpg' : '',
'004RotterdamZuidplein.TIF' : '',
'004RotterdamZuidplein.jpg' : '',
...
};

function checkFilename( fName ){
return (fName in fNameObj);
}

As above, you may want to make the test all lower case.
 
S

Simon

Rob, thanks! I'll give it a try!

RobG said:
Hi everybody..

I'm having a big problem and I think it has something to do with a
maximum
of variables that can be used..
I need to set 16495 variables..
With a smaller amount the script works, but with this number the script
doesnt work anymore..

It goes like this:
var tmp1 = '002RtdOosterhof.jpg';
if (fileName == tmp1) {var stop = 'JA';}

var tmp2 = '003RtdNoordmolen.jpg';
if (fileName == tmp2) {var stop = 'JA';}

var tmp3 = '004RotterdamZuidplein.TIF';
if (fileName == tmp3) {var stop = 'JA';}

var tmp4 = '004RotterdamZuidplein.jpg';
if (fileName == tmp4) {var stop = 'JA';
......etc............ all the way to var tmp16495

(The reason why there are so many is beacuse it runs through a table that
has all the uploads registered, and i need to compare them with the
selected
file before uploading it, so that an existing file will not be
overwritten.)

Put your filenames in an array, then iterate over it to test against
the selected filename. Here's one version:

var fileNames = [
'002RtdOosterhof.jpg',
'003RtdNoordmolen.jpg',
'004RotterdamZuidplein.TIF',
'004RotterdamZuidplein.jpg',
...
];

function checkFilename( fName ){
var i = fileNames.length;
while (i--) {
if (fName == fileNames) return true;
}
return false;
}

If you are unsure about capitalisation, make all the values in
fileNames lower case and test with:

if (fName.toLowerCase() == fileNames) return true;


You could also set the filenames as properties of an object and use:

var fNameObj = {
'002RtdOosterhof.jpg' : '',
'003RtdNoordmolen.jpg' : '',
'004RotterdamZuidplein.TIF' : '',
'004RotterdamZuidplein.jpg' : '',
...
};

function checkFilename( fName ){
return (fName in fNameObj);
}

As above, you may want to make the test all lower case.
 
C

Captain Paralytic

"> Why don't you use an array?> Why don't you check the file serverside?

"
If you have a tip, you mean like an asp-solution?
Can you help me any further?

Well, like an asp or php or other server solution. What are you using
on the server to handle the uploads?

This is an ideal application for an simple AJAX request.
 
B

Bart Van der Donck

Simon said:
I'm having a big problem and I think it has something to do with a
maximum of variables that can be used..
I need to set 16495 variables..
With a smaller amount the script works, but with this number the
script doesnt work anymore..

It goes like this:
var tmp1 = '002RtdOosterhof.jpg';
if (fileName == tmp1) {var stop = 'JA';}

var tmp2 = '003RtdNoordmolen.jpg';
if (fileName == tmp2) {var stop = 'JA';}

var tmp3 = '004RotterdamZuidplein.TIF';
if (fileName == tmp3) {var stop = 'JA';}

var tmp4 = '004RotterdamZuidplein.jpg';
if (fileName == tmp4) {var stop = 'JA';
......etc............ all the way to var tmp16495

(The reason why there are so many is beacuse it runs through a table
that has all the uploads registered, and i need to compare them with
the selected file before uploading it, so that an existing file will
not be overwritten.)

Any ideas?

Using that amount of one-dimensional strings is almost always a flaw
in the code design; because you don't have a clear view, you consume
too much CPU and your code gets illegibly long.

I think you should use multi-dimensional strings in scenarios like
yours, e.g. arrays like RobG suggested, objects ("associative arrays",
"hashes", "dictionnaries"), or combinations of those.

The code might become technically more complex to understand; but it's
the only way to deal with heavy data structures.

It is often worth to make a clear architecture beforehand for your
total data, and/or study the parts where you would be unfamiliar with.

Hope this helps,
 
J

Jeff North

| Hi everybody..
|
| I'm having a big problem and I think it has something to do with a maximum
| of variables that can be used..
| I need to set 16495 variables..
| With a smaller amount the script works, but with this number the script
| doesnt work anymore..
|
| It goes like this:
| var tmp1 = '002RtdOosterhof.jpg';
| if (fileName == tmp1) {var stop = 'JA';
| }
| var tmp2 = '003RtdNoordmolen.jpg';
| if (fileName == tmp2) {var stop = 'JA';
| }
| var tmp3 = '004RotterdamZuidplein.TIF';
| if (fileName == tmp3) {var stop = 'JA';
| }
| var tmp4 = '004RotterdamZuidplein.jpg';
| if (fileName == tmp4) {var stop = 'JA';
| ......etc............ all the way to var tmp16495
|
| (The reason why there are so many is beacuse it runs through a table that
| has all the uploads registered, and i need to compare them with the selected
| file before uploading it, so that an existing file will not be overwritten.)
|
| Any ideas?

You don't really need to place all of that data within Javascript.
You can use AJAX to query the database and return true/false depending
upon whether or not the filename has already been used.
Alternatively, use the server-side code to give each file upload a
unique name for example pic1.jpg, pic[1].jpg, pic1[2].jpg.
-- -------------------------------------------------------------
(e-mail address removed) : Remove your pants to reply
-- -------------------------------------------------------------
 
S

Simon

You don't really need to place all of that data within Javascript.
You can use AJAX to query the database and return true/false depending
upon whether or not the filename has already been used.
Alternatively, use the server-side code to give each file upload a
unique name for example pic1.jpg, pic[1].jpg, pic1[2].jpg.

Jeff, thanks, that is the kind of information i'm looking for! (and also the
contribution of RobG, thanks, it works!!)

Could you help me on my way..

What do i need to do in order to have ajax running at my server. Where do I
get it, How do i approach it, must I change something within ISS, that kind
of stuff)
(Remember, you're talking to a real "dummie")
 
J

Jeff North

| You don't really need to place all of that data within Javascript.
| > You can use AJAX to query the database and return true/false depending
| > upon whether or not the filename has already been used.
| > Alternatively, use the server-side code to give each file upload a
| > unique name for example pic1.jpg, pic[1].jpg, pic1[2].jpg.
|
| Jeff, thanks, that is the kind of information i'm looking for! (and also the
| contribution of RobG, thanks, it works!!)
|
| Could you help me on my way..
|
| What do i need to do in order to have ajax running at my server. Where do I
| get it, How do i approach it, must I change something within ISS, that kind
| of stuff)
| (Remember, you're talking to a real "dummie")

AJAX is basically javascript calls to other pages. I suggest grabbing
a copy of AjaxRequest Library from http://www.ajaxtoolbox.com/ Matt
also posted to this newsgroup, but this library is well documented and
plenty of examples.

But...like all things javascript you've got to take the worse case
scenario. I would use the alternative that I suggested an let the
server-side script handle duplicate files.
-- -------------------------------------------------------------
(e-mail address removed) : Remove your pants to reply
-- -------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,156
Latest member
KetoBurnSupplement
Top