473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Max number of "vars"

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?
Sep 13 '07 #1
7 1414
On 13 Sep, 14:00, "Simon" <simon1...@quicknet.nlwrote:
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?

Sep 13 '07 #2
On Sep 13, 11:00 pm, "Simon" <simon1...@quicknet.nlwrote:
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[i]) 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[i]) 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.
--
Rob

Sep 13 '07 #3
"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?
Sep 13 '07 #4
Rob, thanks! I'll give it a try!

"RobG" <rg***@iinet.net.auschreef in bericht
news:11**********************@g4g2000hsf.googlegro ups.com...
On Sep 13, 11:00 pm, "Simon" <simon1...@quicknet.nlwrote:
>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[i]) 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[i]) 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.
--
Rob

Sep 13 '07 #5
On 13 Sep, 14:43, "Simon" <simon1...@quicknet.nlwrote:
"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.

Sep 13 '07 #6
Simon wrote:
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,

--
Bart

Sep 13 '07 #7
On Thu, 13 Sep 2007 15:00:36 +0200, in comp.lang.javascript "Simon"
<si*******@quicknet.nl>
<46***********************@text.nova.planet.nlwrot e:
>| 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.
-- -------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
-- -------------------------------------------------------------
Sep 13 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dave Smithz | last post by:
Hi there, I have a php script that does some form input validation. As it verifies each field if the field has incorrect data, it appends an error message to an $error array. E.g. if...
3
by: Sean Berry | last post by:
How do I rectify this? ------vars.py------ #!/usr/local/bin/python def setUserid(value): userid = value def getUserid():
9
by: bajopalabra | last post by:
hi session("myVar") = rs.getRows( ) don't work when number of records is greater than 10 does anybody know WHY ??? is it a Session object limitation ??? thanks
4
by: Keith Chadwick | last post by:
I am having some trouble referencing an Application("myVar") variable from within a module.vb file on my ASP.NET site. According to the documentation I should be able to reference...
0
by: Marty Scholes | last post by:
I may have found a bug. I have a table: CREATE TABLE onlpcd_stat ( sel BIGSERIAL PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES onlpcd_user ON DELETE CASCADE, vars TEXT, /*...
3
by: Marco Aschwanden | last post by:
Hi I have a script that looks for modules and tries to load them. After loading I attach the "server"-API function to it. module = __import__(module_name, globals(), locals(), ) module.server...
4
by: lesperancer | last post by:
it looks like this will save many versions of a relationship window, but based on the fact that the same tables are displayed in the relationship window and it will restore versions of what was...
1
by: perlvasu | last post by:
6 jobs are running at the same time and accessing same dbm file for writing and reading. These are daily jobs and failing only some times not regularly. So i thought of this is just because of dead...
16
by: Joe Strout | last post by:
One thing I miss as I move from REALbasic to Python is the ability to have static storage within a method -- i.e. storage that is persistent between calls, but not visible outside the method. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.