473,394 Members | 1,946 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,394 software developers and data experts.

Resource data

I am converting a Pascal app to Javascript.
The app presents spelling tests. Having completed a test, the user will be
presented with a random next one.
Each test is derived from a single line in a txt input file. Each line can
be considered as a string.
How can I incorporate this input file in Javascript?
It would be nice to be able to keep this file (of around 600 lines), since
it makes additions/changes straightforward. If that is not possible, the
lines should be integrated into the script in a 'manageable' way.

TIA
Tom
Feb 20 '08 #1
7 1202
Tom de Neef wrote:
I am converting a Pascal app to Javascript.
The app presents spelling tests. Having completed a test, the user will be
presented with a random next one.
Each test is derived from a single line in a txt input file. Each line can
be considered as a string.
How can I incorporate this input file in Javascript?
It would be nice to be able to keep this file (of around 600 lines), since
it makes additions/changes straightforward. If that is not possible, the
lines should be integrated into the script in a 'manageable' way.
TIA
Tom
You could convert your text file into a JS file. That's what I'd do. So
where your file might look like this now:

line 1 some text
line 2 some text
line 3 some text

With a quick macro in your favourite text editor, you could turn that into:

var q=[];
q[q.length]="line 1 some text";
q[q.length]="line 2 some text";
q[q.length]="line 3 some text";

You still get to leave it as a clear text file, you can still mix up the
line numbers to change the sequence.

Just include it with a javascript script tag and the array q is
available to you. If anything, I would expect it to make your code simpler.
Feb 20 '08 #2
SAM wrote on 20 feb 2008 in comp.lang.javascript:
Tom de Neef a ‚crit :
>I am converting a Pascal app to Javascript.
The app presents spelling tests. Having completed a test, the user
will be presented with a random next one.
Each test is derived from a single line in a txt input file. Each
line can be considered as a string.
How can I incorporate this input file in Javascript?
It would be nice to be able to keep this file (of around 600 lines),
since it makes additions/changes straightforward. If that is not
possible, the lines should be integrated into the script in a
'manageable' way.

perhaps can you insert the text file via php or something like that ?
Or with Ajax-like code?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 20 '08 #3

"Stevo" <pl****@spam-me.comschreef in bericht
news:fp*************@news.t-online.com...
Tom de Neef wrote:
>I am converting a Pascal app to Javascript.
The app presents spelling tests. Having completed a test, the user will
be presented with a random next one.
Each test is derived from a single line in a txt input file. Each line
can be considered as a string.
How can I incorporate this input file in Javascript?
It would be nice to be able to keep this file (of around 600 lines),
since it makes additions/changes straightforward. If that is not
possible, the lines should be integrated into the script in a
'manageable' way.
TIA
Tom

You could convert your text file into a JS file. That's what I'd do. So
where your file might look like this now:

line 1 some text
line 2 some text
line 3 some text

With a quick macro in your favourite text editor, you could turn that
into:

var q=[];
q[q.length]="line 1 some text";
q[q.length]="line 2 some text";
q[q.length]="line 3 some text";

You still get to leave it as a clear text file, you can still mix up the
line numbers to change the sequence.

Just include it with a javascript script tag and the array q is available
to you. If anything, I would expect it to make your code simpler.
Thank you, I have adopted this approach.
Tom
Feb 20 '08 #4
On Feb 20, 6:07 am, Stevo <ple...@spam-me.comwrote:
Tom de Neef wrote:
I am converting a Pascal app to Javascript.
The app presents spelling tests. Having completed a test, the user will be
presented with a random next one.
Each test is derived from a single line in a txt input file. Each line can
be considered as a string.
How can I incorporate this input file in Javascript?
It would be nice to be able to keep this file (of around 600 lines), since
it makes additions/changes straightforward. If that is not possible, the
lines should be integrated into the script in a 'manageable' way.
TIA
Tom

You could convert your text file into a JS file. That's what I'd do. So
where your file might look like this now:

line 1 some text
line 2 some text
line 3 some text

With a quick macro in your favourite text editor, you could turn that into:

var q=[];
q[q.length]="line 1 some text";
q[q.length]="line 2 some text";
q[q.length]="line 3 some text";
For faster downloads it could be turned into

var q=[
"line 1 some text",
"line 2 some text",
"line 3 some text"
];

Note the last text line doesn't have a comma.

Peter
Feb 20 '08 #5
SAM
Tom de Neef a écrit :
"SAM" <st*********************@wanadoo.fr.invalidschre ef in bericht
news:47*********************@news.orange.fr...
>perhaps can you insert the text file via php or something like that ?
(snip)
>
I appreciate your suggestion, but I think I should master Javascript first,
before venturing into php or Ajax.
I don't see JS reading a simple text file (or including it) ...
At least you'll have to transform the text file in a variable or in a JS
array.

file 'testsText.js' :

var lines = '1st line;2nd line;3rd line';

or :

var lines = ['1st line','2nd line','3rd line'];

or :

var lines = [
'1st line',
'2nd line',
'3rd line'
];

(that was supposed the php to do)
(using your original file without to modify it by yourself)
(no ' will be allowed in any line)(php translated that)
(after all, perhaps your C script can create this file ?)
And in the head of your main html page

<script type="text/javascript" src="testsText.js"></script>
<script type="text/javascript">
if(typeof(lines) == 'string') lines = lines.split(';');
function newTest() {
return lines[Math.floor(Math.random()*lines.length)];
}
</script>
In the body of my idea the call to correction was made server-side and
the result displayed in a popup to do not use Ajax.

If you have a file with corrected lines you can load it in same way as
above and compare the answer with correspondent corrected line
then display result somewhere in same page without using Ajax.
But take care you'll force to load 2 files of 600 lines each (which
weight that will be ?)
--
sm
Feb 21 '08 #6
"Tom de Neef" <td*****@qolor.nlschreef
>I am converting a Pascal app to Javascript.
The app presents spelling tests. Having completed a test, the user will be
presented with a random next one.
Each test is derived from a single line in a txt input file. Each line can
be considered as a string.
How can I incorporate this input file in Javascript?
It would be nice to be able to keep this file (of around 600 lines), since
it makes additions/changes straightforward. If that is not possible, the
lines should be integrated into the script in a 'manageable' way.

TIA
Tom
The answer was given in a later thread: use XMLHttpRequest. The code I now
use is as follows:

function loadFile(url) {
var req = false;
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest && !(window.ActiveXObject)) {
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
// branch for IE/Windows ActiveX version
} else if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
if(req) {
req.open("GET", url, false);
req.send("");
return req.responseText
}
}
var tests = []
tests =
loadFile('ww.opg').split(String.fromCharCode(13)+S tring.fromCharCode(10))

Tom
Feb 26 '08 #7
Thomas 'PointedEars' Lahn wrote on 26 feb 2008 in comp.lang.javascript:
tests = tests.split(/\r?\n|\r/);
tests = tests.split(/[\r\n]/)

This will skip empty lines,
which can be either bad or usefull.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 26 '08 #8

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

Similar topics

2
by: lawrence | last post by:
I had some code that worked fine for several weeks, and then yesterday it stopped working. I'm not sure what I did. Nor can I make out why it isn't working. I'm running a query that should return 3...
5
by: lawrence | last post by:
I posted before, but have now narrowed my problem down to this method. At the start of the method, I test to make sure that I have a resource, a pointer to data returned from a database. This test...
2
by: Arjen | last post by:
Hello, I have 2 resource files. The resource files have both inside the name field values. I want to select from the first resource file the records where the name field haves a value between 1...
8
by: Bonj | last post by:
when creating a resource-only dll, the only way I can get it to compile and work correctly, is to make it a non-resource-only dll. surely this can't be the way...? basically, there is a load of...
1
by: Namratha Shah \(Nasha\) | last post by:
Hi All, This is a resource file generation tool which converts an xml based resource formats to .net resource file i.e. (.resources) and vice-versa. Today we will see how we will generate ...
7
by: Rich | last post by:
I am resurrecting this question (since it got bumped down by more recent posts). This is probably very simple - I need to add a version resource to a DLL project in MSVC++ 2005 Express in order...
8
by: CodeLeon | last post by:
Hi, All. I am creating a setup program. The way it works is that the user creates their setup info, my program generates the C# code for a setup executable, embeds the xml file containing the info...
5
by: Mukesh | last post by:
Hi i want to use AJAX.net in my Existing Application I have already installed the ajax .net ..net 3.0 and using VS 2005 in the old application i have added a new web form then script manager...
0
by: =?Utf-8?B?cHJhc2hhbnQga3VtYXIgc3JpdmFzdGF2YQ==?= | last post by:
Hi all, I m using asp.net 2.0 version and want to retrieve the particular string from resource file dynamically... Following is the my code ... but in this every time I get exception that...
0
by: =?Utf-8?B?cHJhc2hhbnQga3VtYXIgc3JpdmFzdGF2YQ==?= | last post by:
Hi all, I m using asp.net 2.0 version and want to retrieve the particular string from resource file dynamically... Following is the my code ... but in this every time I get exception that...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.