Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32263 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2017-01-23 03:29 -0800 |
| Last post | 2017-01-24 17:21 +0000 |
| Articles | 20 on this page of 32 — 5 participants |
Back to article view | Back to comp.lang.javascript
Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 03:29 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 03:59 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 06:26 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 07:41 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 08:08 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 08:43 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 09:41 -0800
Re: Read in file to array. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-01-23 10:29 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 11:24 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 11:38 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 11:56 -0800
Re: Read in file to array. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-23 20:36 +0000
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 19:54 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 20:10 -0800
Re: Read in file to array. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-24 14:27 +0000
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-24 08:24 -0800
Re: Read in file to array. Jake Jarvis <pig_in_shoes@yahoo.com> - 2017-01-24 17:42 +0100
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-24 08:54 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-24 09:04 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-24 11:07 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-24 13:17 -0800
Re: Read in file to array. Tim Streater <timstreater@greenbee.net> - 2017-01-24 21:35 +0000
Re: Read in file to array. Jake Jarvis <pig_in_shoes@yahoo.com> - 2017-01-24 22:42 +0100
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-24 15:32 -0800
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-24 15:55 -0800
Re: Read in file to array. Tim Streater <timstreater@greenbee.net> - 2017-01-25 08:59 +0000
Re: Read in file to array. Jake Jarvis <pig_in_shoes@yahoo.com> - 2017-01-25 01:58 +0100
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-24 18:51 -0800
Re: Read in file to array. Jake Jarvis <pig_in_shoes@yahoo.com> - 2017-01-25 10:29 +0100
Re: Read in file to array. Tim Streater <timstreater@greenbee.net> - 2017-01-25 08:58 +0000
Re: Read in file to array. jonas.thornvall@gmail.com - 2017-01-23 12:28 -0800
Re: Read in file to array. Tim Streater <timstreater@greenbee.net> - 2017-01-24 17:21 +0000
Page 1 of 2 [1] 2 Next page →
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 03:29 -0800 |
| Subject | Read in file to array. |
| Message-ID | <2b6a77ee-b20d-4f11-bd56-c73f66523ec7@googlegroups.com> |
Well i come so far i can save the graph data to a textfile i did go for "\r\n" as node/record separator and i use star "*" to separate data-items in each node/record.
So i end up with something like this in my textfile
0*1,3,7*false*847*122*10*10*#F6A3D3*#F6A3D3
1*0,5,6*false*950*370*10*10*#D3D85E*#D3D85E
2*4,6,7*false*352*617*10*10*#7C9F6D*#7C9F6D
3*0,5,7*false*600*20*10*10*#A5DD6F*#A5DD6F
4*2,5,6*false*250*369*10*10*#994CF6*#994CF6
5*1,3,4*false*352*122*10*10*#76A9EE*#76A9EE
6*1,2,4*false*599*720*10*10*#B4E9C8*#B4E9C8
7*0,2,3*false*832*549*10*10*#994CF6*#994CF6
Now i want to read back a graph to array in script.
arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
I was thinking sub=arr.split("\r\n")
And then for each record dataitem=sub.split("\r\n")
And last for links=dataitem[1].split(",")
Does it seem sound?
[toc] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 03:59 -0800 |
| Message-ID | <015aa987-b329-446c-9fb9-b7c1317a7a39@googlegroups.com> |
| In reply to | #32263 |
Den måndag 23 januari 2017 kl. 12:29:37 UTC+1 skrev jonas.t...@gmail.com:
> Well i come so far i can save the graph data to a textfile i did go for "\r\n" as node/record separator and i use star "*" to separate data-items in each node/record.
>
> So i end up with something like this in my textfile
> 0*1,3,7*false*847*122*10*10*#F6A3D3*#F6A3D3
> 1*0,5,6*false*950*370*10*10*#D3D85E*#D3D85E
> 2*4,6,7*false*352*617*10*10*#7C9F6D*#7C9F6D
> 3*0,5,7*false*600*20*10*10*#A5DD6F*#A5DD6F
> 4*2,5,6*false*250*369*10*10*#994CF6*#994CF6
> 5*1,3,4*false*352*122*10*10*#76A9EE*#76A9EE
> 6*1,2,4*false*599*720*10*10*#B4E9C8*#B4E9C8
> 7*0,2,3*false*832*549*10*10*#994CF6*#994CF6
>
> Now i want to read back a graph to array in script.
> arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
>
> I was thinking sub=arr.split("\r\n")
> And then for each record dataitem=sub.split("\r\n")
>
> And last for links=dataitem[1].split(",")
>
> Does it seem sound?
function loadGraph()
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
document.debug.data.value += textFromFileLoaded;
};
fileReader.readAsText(fileToLoad, "UTF-8");
arr=[];
sub=textFromFileLoaded.split("\r\n");
for (var x=0;x<sub.length;sub++){
dataitem=sub[x].split("*");
for(var a=0;a<dataitem.length;a++){
arr[a].hold=dataitem[3];
arr[a].rposX=dataitem[4];
arr[a].rposY=dataitem[5];
arr[a].rwidth=dataitem[6];
arr[a].rcolor=dataitem[7];
arr[a].bcolor=dataitem[8];
dataitem[2].split(",")
for (var b=0;b<dataitem;b++) {
arr[a].nodelinks[b]=dataitem[b]
}
}
}
}
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 06:26 -0800 |
| Message-ID | <30277451-ca92-4bc3-b070-3ed4fd8d2dfc@googlegroups.com> |
| In reply to | #32264 |
Den måndag 23 januari 2017 kl. 12:59:19 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 23 januari 2017 kl. 12:29:37 UTC+1 skrev jonas.t...@gmail.com:
> > Well i come so far i can save the graph data to a textfile i did go for "\r\n" as node/record separator and i use star "*" to separate data-items in each node/record.
> >
> > So i end up with something like this in my textfile
> > 0*1,3,7*false*847*122*10*10*#F6A3D3*#F6A3D3
> > 1*0,5,6*false*950*370*10*10*#D3D85E*#D3D85E
> > 2*4,6,7*false*352*617*10*10*#7C9F6D*#7C9F6D
> > 3*0,5,7*false*600*20*10*10*#A5DD6F*#A5DD6F
> > 4*2,5,6*false*250*369*10*10*#994CF6*#994CF6
> > 5*1,3,4*false*352*122*10*10*#76A9EE*#76A9EE
> > 6*1,2,4*false*599*720*10*10*#B4E9C8*#B4E9C8
> > 7*0,2,3*false*832*549*10*10*#994CF6*#994CF6
> >
> > Now i want to read back a graph to array in script.
> > arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
> >
> > I was thinking sub=arr.split("\r\n")
> > And then for each record dataitem=sub.split("\r\n")
> >
> > And last for links=dataitem[1].split(",")
> >
> > Does it seem sound?
>
> function loadGraph()
> {
>
> var fileToLoad = document.getElementById("fileToLoad").files[0];
> var fileReader = new FileReader();
> fileReader.onload = function(fileLoadedEvent)
> {
> var textFromFileLoaded = fileLoadedEvent.target.result;
> document.debug.data.value += textFromFileLoaded;
> };
> fileReader.readAsText(fileToLoad, "UTF-8");
>
> arr=[];
> sub=textFromFileLoaded.split("\r\n");
> for (var x=0;x<sub.length;sub++){
> dataitem=sub[x].split("*");
> for(var a=0;a<dataitem.length;a++){
> arr[a].hold=dataitem[3];
> arr[a].rposX=dataitem[4];
> arr[a].rposY=dataitem[5];
> arr[a].rwidth=dataitem[6];
> arr[a].rcolor=dataitem[7];
> arr[a].bcolor=dataitem[8];
> dataitem[2].split(",")
> for (var b=0;b<dataitem;b++) {
> arr[a].nodelinks[b]=dataitem[b]
> }
> }
> }
> }
Well now the gist seem to work but there must be some problem with javascript
I manage to get an alert on the data if i "load twice", isn't that strange.
alert(textFromFileLoaded);
sub=textFromFileLoaded.split("!");
"X3LOADSAVE.js:46 Uncaught ReferenceError: textFromFileLoaded is not defined
at loadGraph (X3LOADSAVE.js:46)
at HTMLButtonElement.onclick (0GRAPH.HTML?filename=N8L3circle.txt:31)"
But second time file loaded it is read into array without errors reported, it seem like a timing issue?
There is no problem to just write to the textarea first time but for some reason i can not use textFromFileload at all i must copy the value to my own variable and even then it will not be read in the first time i load, but the second time i press button to load it work.
function loadGraph()
{
textFromFileLoaded="";
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
textFromFileLoaded = fileLoadedEvent.target.result;
document.debug.data.value = textFromFileLoaded;
mytext=textFromFileLoaded;
};
fileReader.readAsText(fileToLoad, "UTF-8");
//arr=[];
alert(mytext);
sub=mytext.split("!");
for (var x=0;x<sub.length;sub++){
dataitem=sub[x].split("*");
alert(dataitem[1]);
for(var a=0;a<dataitem.length;a++){
arr[a].hold=false;
arr[a].rposX=parseInt(dataitem[4]);
arr[a].rposY=parseInt(dataitem[5]);
arr[a].rwidth=parseInt(dataitem[6]);
arr[a].rheigth=parseInt(dataitem[7]);
arr[a].rcolor=dataitem[8];
arr[a].bcolor=dataitem[9];
links=dataitem[1].split(",");
for (var b=0;b<dataitem;b++) {
arr[a].nodelinks[b]=parseInt(links[b]);
}
}
}
}
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 07:41 -0800 |
| Message-ID | <191ace72-7818-44ca-9dae-d0499239f132@googlegroups.com> |
| In reply to | #32266 |
Den måndag 23 januari 2017 kl. 15:27:03 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 23 januari 2017 kl. 12:59:19 UTC+1 skrev jonas.t...@gmail.com:
> > Den måndag 23 januari 2017 kl. 12:29:37 UTC+1 skrev jonas.t...@gmail.com:
> > > Well i come so far i can save the graph data to a textfile i did go for "\r\n" as node/record separator and i use star "*" to separate data-items in each node/record.
> > >
> > > So i end up with something like this in my textfile
> > > 0*1,3,7*false*847*122*10*10*#F6A3D3*#F6A3D3
> > > 1*0,5,6*false*950*370*10*10*#D3D85E*#D3D85E
> > > 2*4,6,7*false*352*617*10*10*#7C9F6D*#7C9F6D
> > > 3*0,5,7*false*600*20*10*10*#A5DD6F*#A5DD6F
> > > 4*2,5,6*false*250*369*10*10*#994CF6*#994CF6
> > > 5*1,3,4*false*352*122*10*10*#76A9EE*#76A9EE
> > > 6*1,2,4*false*599*720*10*10*#B4E9C8*#B4E9C8
> > > 7*0,2,3*false*832*549*10*10*#994CF6*#994CF6
> > >
> > > Now i want to read back a graph to array in script.
> > > arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
> > >
> > > I was thinking sub=arr.split("\r\n")
> > > And then for each record dataitem=sub.split("\r\n")
> > >
> > > And last for links=dataitem[1].split(",")
> > >
> > > Does it seem sound?
> >
> > function loadGraph()
> > {
> >
> > var fileToLoad = document.getElementById("fileToLoad").files[0];
> > var fileReader = new FileReader();
> > fileReader.onload = function(fileLoadedEvent)
> > {
> > var textFromFileLoaded = fileLoadedEvent.target.result;
> > document.debug.data.value += textFromFileLoaded;
> > };
> > fileReader.readAsText(fileToLoad, "UTF-8");
> >
> > arr=[];
> > sub=textFromFileLoaded.split("\r\n");
> > for (var x=0;x<sub.length;sub++){
> > dataitem=sub[x].split("*");
> > for(var a=0;a<dataitem.length;a++){
> > arr[a].hold=dataitem[3];
> > arr[a].rposX=dataitem[4];
> > arr[a].rposY=dataitem[5];
> > arr[a].rwidth=dataitem[6];
> > arr[a].rcolor=dataitem[7];
> > arr[a].bcolor=dataitem[8];
> > dataitem[2].split(",")
> > for (var b=0;b<dataitem;b++) {
> > arr[a].nodelinks[b]=dataitem[b]
> > }
> > }
> > }
> > }
>
> Well now the gist seem to work but there must be some problem with javascript
> I manage to get an alert on the data if i "load twice", isn't that strange.
>
> alert(textFromFileLoaded);
> sub=textFromFileLoaded.split("!");
>
> "X3LOADSAVE.js:46 Uncaught ReferenceError: textFromFileLoaded is not defined
> at loadGraph (X3LOADSAVE.js:46)
> at HTMLButtonElement.onclick (0GRAPH.HTML?filename=N8L3circle.txt:31)"
>
> But second time file loaded it is read into array without errors reported, it seem like a timing issue?
>
> There is no problem to just write to the textarea first time but for some reason i can not use textFromFileload at all i must copy the value to my own variable and even then it will not be read in the first time i load, but the second time i press button to load it work.
>
> function loadGraph()
> {
> textFromFileLoaded="";
> var fileToLoad = document.getElementById("fileToLoad").files[0];
> var fileReader = new FileReader();
> fileReader.onload = function(fileLoadedEvent)
> {
> textFromFileLoaded = fileLoadedEvent.target.result;
> document.debug.data.value = textFromFileLoaded;
> mytext=textFromFileLoaded;
> };
> fileReader.readAsText(fileToLoad, "UTF-8");
> //arr=[];
>
> alert(mytext);
> sub=mytext.split("!");
> for (var x=0;x<sub.length;sub++){
> dataitem=sub[x].split("*");
> alert(dataitem[1]);
> for(var a=0;a<dataitem.length;a++){
> arr[a].hold=false;
> arr[a].rposX=parseInt(dataitem[4]);
> arr[a].rposY=parseInt(dataitem[5]);
> arr[a].rwidth=parseInt(dataitem[6]);
> arr[a].rheigth=parseInt(dataitem[7]);
> arr[a].rcolor=dataitem[8];
> arr[a].bcolor=dataitem[9];
> links=dataitem[1].split(",");
> for (var b=0;b<dataitem;b++) {
> arr[a].nodelinks[b]=parseInt(links[b]);
> }
> }
> }
> }
A real stupid way would be to have a listener upon the textarea to to call another function that actually write the data to array, because when that is written one know the value can not be undefined?
And even if it is one could copy the values from the field doing the readin to array in another file.
But i must say it feel like a workaround.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 08:08 -0800 |
| Message-ID | <c358c43f-dcda-4bec-a2e8-b57c1b6e27d2@googlegroups.com> |
| In reply to | #32267 |
Den måndag 23 januari 2017 kl. 16:41:49 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 23 januari 2017 kl. 15:27:03 UTC+1 skrev jonas.t...@gmail.com:
> > Den måndag 23 januari 2017 kl. 12:59:19 UTC+1 skrev jonas.t...@gmail.com:
> > > Den måndag 23 januari 2017 kl. 12:29:37 UTC+1 skrev jonas.t...@gmail.com:
> > > > Well i come so far i can save the graph data to a textfile i did go for "\r\n" as node/record separator and i use star "*" to separate data-items in each node/record.
> > > >
> > > > So i end up with something like this in my textfile
> > > > 0*1,3,7*false*847*122*10*10*#F6A3D3*#F6A3D3
> > > > 1*0,5,6*false*950*370*10*10*#D3D85E*#D3D85E
> > > > 2*4,6,7*false*352*617*10*10*#7C9F6D*#7C9F6D
> > > > 3*0,5,7*false*600*20*10*10*#A5DD6F*#A5DD6F
> > > > 4*2,5,6*false*250*369*10*10*#994CF6*#994CF6
> > > > 5*1,3,4*false*352*122*10*10*#76A9EE*#76A9EE
> > > > 6*1,2,4*false*599*720*10*10*#B4E9C8*#B4E9C8
> > > > 7*0,2,3*false*832*549*10*10*#994CF6*#994CF6
> > > >
> > > > Now i want to read back a graph to array in script.
> > > > arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
> > > >
> > > > I was thinking sub=arr.split("\r\n")
> > > > And then for each record dataitem=sub.split("\r\n")
> > > >
> > > > And last for links=dataitem[1].split(",")
> > > >
> > > > Does it seem sound?
> > >
> > > function loadGraph()
> > > {
> > >
> > > var fileToLoad = document.getElementById("fileToLoad").files[0];
> > > var fileReader = new FileReader();
> > > fileReader.onload = function(fileLoadedEvent)
> > > {
> > > var textFromFileLoaded = fileLoadedEvent.target.result;
> > > document.debug.data.value += textFromFileLoaded;
> > > };
> > > fileReader.readAsText(fileToLoad, "UTF-8");
> > >
> > > arr=[];
> > > sub=textFromFileLoaded.split("\r\n");
> > > for (var x=0;x<sub.length;sub++){
> > > dataitem=sub[x].split("*");
> > > for(var a=0;a<dataitem.length;a++){
> > > arr[a].hold=dataitem[3];
> > > arr[a].rposX=dataitem[4];
> > > arr[a].rposY=dataitem[5];
> > > arr[a].rwidth=dataitem[6];
> > > arr[a].rcolor=dataitem[7];
> > > arr[a].bcolor=dataitem[8];
> > > dataitem[2].split(",")
> > > for (var b=0;b<dataitem;b++) {
> > > arr[a].nodelinks[b]=dataitem[b]
> > > }
> > > }
> > > }
> > > }
> >
> > Well now the gist seem to work but there must be some problem with javascript
> > I manage to get an alert on the data if i "load twice", isn't that strange.
> >
> > alert(textFromFileLoaded);
> > sub=textFromFileLoaded.split("!");
> >
> > "X3LOADSAVE.js:46 Uncaught ReferenceError: textFromFileLoaded is not defined
> > at loadGraph (X3LOADSAVE.js:46)
> > at HTMLButtonElement.onclick (0GRAPH.HTML?filename=N8L3circle.txt:31)"
> >
> > But second time file loaded it is read into array without errors reported, it seem like a timing issue?
> >
> > There is no problem to just write to the textarea first time but for some reason i can not use textFromFileload at all i must copy the value to my own variable and even then it will not be read in the first time i load, but the second time i press button to load it work.
> >
> > function loadGraph()
> > {
> > textFromFileLoaded="";
> > var fileToLoad = document.getElementById("fileToLoad").files[0];
> > var fileReader = new FileReader();
> > fileReader.onload = function(fileLoadedEvent)
> > {
> > textFromFileLoaded = fileLoadedEvent.target.result;
> > document.debug.data.value = textFromFileLoaded;
> > mytext=textFromFileLoaded;
> > };
> > fileReader.readAsText(fileToLoad, "UTF-8");
> > //arr=[];
> >
> > alert(mytext);
> > sub=mytext.split("!");
> > for (var x=0;x<sub.length;sub++){
> > dataitem=sub[x].split("*");
> > alert(dataitem[1]);
> > for(var a=0;a<dataitem.length;a++){
> > arr[a].hold=false;
> > arr[a].rposX=parseInt(dataitem[4]);
> > arr[a].rposY=parseInt(dataitem[5]);
> > arr[a].rwidth=parseInt(dataitem[6]);
> > arr[a].rheigth=parseInt(dataitem[7]);
> > arr[a].rcolor=dataitem[8];
> > arr[a].bcolor=dataitem[9];
> > links=dataitem[1].split(",");
> > for (var b=0;b<dataitem;b++) {
> > arr[a].nodelinks[b]=parseInt(links[b]);
> > }
> > }
> > }
> > }
>
> A real stupid way would be to have a listener upon the textarea to to call another function that actually write the data to array, because when that is written one know the value can not be undefined?
> And even if it is one could copy the values from the field doing the readin to array in another file.
>
> But i must say it feel like a workaround.
Evidently i must also find away to reset this array.
arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
How will i easiest way achieve that?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 08:43 -0800 |
| Message-ID | <8faaf70c-8e7b-4dc5-a023-9ce2d2996c2c@googlegroups.com> |
| In reply to | #32268 |
Den måndag 23 januari 2017 kl. 17:08:17 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 23 januari 2017 kl. 16:41:49 UTC+1 skrev jonas.t...@gmail.com:
> > Den måndag 23 januari 2017 kl. 15:27:03 UTC+1 skrev jonas.t...@gmail.com:
> > > Den måndag 23 januari 2017 kl. 12:59:19 UTC+1 skrev jonas.t...@gmail.com:
> > > > Den måndag 23 januari 2017 kl. 12:29:37 UTC+1 skrev jonas.t...@gmail.com:
> > > > > Well i come so far i can save the graph data to a textfile i did go for "\r\n" as node/record separator and i use star "*" to separate data-items in each node/record.
> > > > >
> > > > > So i end up with something like this in my textfile
> > > > > 0*1,3,7*false*847*122*10*10*#F6A3D3*#F6A3D3
> > > > > 1*0,5,6*false*950*370*10*10*#D3D85E*#D3D85E
> > > > > 2*4,6,7*false*352*617*10*10*#7C9F6D*#7C9F6D
> > > > > 3*0,5,7*false*600*20*10*10*#A5DD6F*#A5DD6F
> > > > > 4*2,5,6*false*250*369*10*10*#994CF6*#994CF6
> > > > > 5*1,3,4*false*352*122*10*10*#76A9EE*#76A9EE
> > > > > 6*1,2,4*false*599*720*10*10*#B4E9C8*#B4E9C8
> > > > > 7*0,2,3*false*832*549*10*10*#994CF6*#994CF6
> > > > >
> > > > > Now i want to read back a graph to array in script.
> > > > > arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
> > > > >
> > > > > I was thinking sub=arr.split("\r\n")
> > > > > And then for each record dataitem=sub.split("\r\n")
> > > > >
> > > > > And last for links=dataitem[1].split(",")
> > > > >
> > > > > Does it seem sound?
> > > >
> > > > function loadGraph()
> > > > {
> > > >
> > > > var fileToLoad = document.getElementById("fileToLoad").files[0];
> > > > var fileReader = new FileReader();
> > > > fileReader.onload = function(fileLoadedEvent)
> > > > {
> > > > var textFromFileLoaded = fileLoadedEvent.target.result;
> > > > document.debug.data.value += textFromFileLoaded;
> > > > };
> > > > fileReader.readAsText(fileToLoad, "UTF-8");
> > > >
> > > > arr=[];
> > > > sub=textFromFileLoaded.split("\r\n");
> > > > for (var x=0;x<sub.length;sub++){
> > > > dataitem=sub[x].split("*");
> > > > for(var a=0;a<dataitem.length;a++){
> > > > arr[a].hold=dataitem[3];
> > > > arr[a].rposX=dataitem[4];
> > > > arr[a].rposY=dataitem[5];
> > > > arr[a].rwidth=dataitem[6];
> > > > arr[a].rcolor=dataitem[7];
> > > > arr[a].bcolor=dataitem[8];
> > > > dataitem[2].split(",")
> > > > for (var b=0;b<dataitem;b++) {
> > > > arr[a].nodelinks[b]=dataitem[b]
> > > > }
> > > > }
> > > > }
> > > > }
> > >
> > > Well now the gist seem to work but there must be some problem with javascript
> > > I manage to get an alert on the data if i "load twice", isn't that strange.
> > >
> > > alert(textFromFileLoaded);
> > > sub=textFromFileLoaded.split("!");
> > >
> > > "X3LOADSAVE.js:46 Uncaught ReferenceError: textFromFileLoaded is not defined
> > > at loadGraph (X3LOADSAVE.js:46)
> > > at HTMLButtonElement.onclick (0GRAPH.HTML?filename=N8L3circle.txt:31)"
> > >
> > > But second time file loaded it is read into array without errors reported, it seem like a timing issue?
> > >
> > > There is no problem to just write to the textarea first time but for some reason i can not use textFromFileload at all i must copy the value to my own variable and even then it will not be read in the first time i load, but the second time i press button to load it work.
> > >
> > > function loadGraph()
> > > {
> > > textFromFileLoaded="";
> > > var fileToLoad = document.getElementById("fileToLoad").files[0];
> > > var fileReader = new FileReader();
> > > fileReader.onload = function(fileLoadedEvent)
> > > {
> > > textFromFileLoaded = fileLoadedEvent.target.result;
> > > document.debug.data.value = textFromFileLoaded;
> > > mytext=textFromFileLoaded;
> > > };
> > > fileReader.readAsText(fileToLoad, "UTF-8");
> > > //arr=[];
> > >
> > > alert(mytext);
> > > sub=mytext.split("!");
> > > for (var x=0;x<sub.length;sub++){
> > > dataitem=sub[x].split("*");
> > > alert(dataitem[1]);
> > > for(var a=0;a<dataitem.length;a++){
> > > arr[a].hold=false;
> > > arr[a].rposX=parseInt(dataitem[4]);
> > > arr[a].rposY=parseInt(dataitem[5]);
> > > arr[a].rwidth=parseInt(dataitem[6]);
> > > arr[a].rheigth=parseInt(dataitem[7]);
> > > arr[a].rcolor=dataitem[8];
> > > arr[a].bcolor=dataitem[9];
> > > links=dataitem[1].split(",");
> > > for (var b=0;b<dataitem;b++) {
> > > arr[a].nodelinks[b]=parseInt(links[b]);
> > > }
> > > }
> > > }
> > > }
> >
> > A real stupid way would be to have a listener upon the textarea to to call another function that actually write the data to array, because when that is written one know the value can not be undefined?
> > And even if it is one could copy the values from the field doing the readin to array in another file.
> >
> > But i must say it feel like a workaround.
>
> Evidently i must also find away to reset this array.
>
> arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
>
> How will i easiest way achieve that?
I did it this way basicly reinitialize using the number of records/nodes in file. Before i load the values so now it works...
Well it it wasn't for the timing issue, having to load the thing twice.
for (var m = 0; m <=sub.length ; m ++ )
{
arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
}
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 09:41 -0800 |
| Message-ID | <931577e5-a727-4243-99af-d0b436760cc8@googlegroups.com> |
| In reply to | #32269 |
Den måndag 23 januari 2017 kl. 17:43:17 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 23 januari 2017 kl. 17:08:17 UTC+1 skrev jonas.t...@gmail.com:
> > Den måndag 23 januari 2017 kl. 16:41:49 UTC+1 skrev jonas.t...@gmail.com:
> > > Den måndag 23 januari 2017 kl. 15:27:03 UTC+1 skrev jonas.t...@gmail.com:
> > > > Den måndag 23 januari 2017 kl. 12:59:19 UTC+1 skrev jonas.t...@gmail.com:
> > > > > Den måndag 23 januari 2017 kl. 12:29:37 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > Well i come so far i can save the graph data to a textfile i did go for "\r\n" as node/record separator and i use star "*" to separate data-items in each node/record.
> > > > > >
> > > > > > So i end up with something like this in my textfile
> > > > > > 0*1,3,7*false*847*122*10*10*#F6A3D3*#F6A3D3
> > > > > > 1*0,5,6*false*950*370*10*10*#D3D85E*#D3D85E
> > > > > > 2*4,6,7*false*352*617*10*10*#7C9F6D*#7C9F6D
> > > > > > 3*0,5,7*false*600*20*10*10*#A5DD6F*#A5DD6F
> > > > > > 4*2,5,6*false*250*369*10*10*#994CF6*#994CF6
> > > > > > 5*1,3,4*false*352*122*10*10*#76A9EE*#76A9EE
> > > > > > 6*1,2,4*false*599*720*10*10*#B4E9C8*#B4E9C8
> > > > > > 7*0,2,3*false*832*549*10*10*#994CF6*#994CF6
> > > > > >
> > > > > > Now i want to read back a graph to array in script.
> > > > > > arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
> > > > > >
> > > > > > I was thinking sub=arr.split("\r\n")
> > > > > > And then for each record dataitem=sub.split("\r\n")
> > > > > >
> > > > > > And last for links=dataitem[1].split(",")
> > > > > >
> > > > > > Does it seem sound?
> > > > >
> > > > > function loadGraph()
> > > > > {
> > > > >
> > > > > var fileToLoad = document.getElementById("fileToLoad").files[0];
> > > > > var fileReader = new FileReader();
> > > > > fileReader.onload = function(fileLoadedEvent)
> > > > > {
> > > > > var textFromFileLoaded = fileLoadedEvent.target.result;
> > > > > document.debug.data.value += textFromFileLoaded;
> > > > > };
> > > > > fileReader.readAsText(fileToLoad, "UTF-8");
> > > > >
> > > > > arr=[];
> > > > > sub=textFromFileLoaded.split("\r\n");
> > > > > for (var x=0;x<sub.length;sub++){
> > > > > dataitem=sub[x].split("*");
> > > > > for(var a=0;a<dataitem.length;a++){
> > > > > arr[a].hold=dataitem[3];
> > > > > arr[a].rposX=dataitem[4];
> > > > > arr[a].rposY=dataitem[5];
> > > > > arr[a].rwidth=dataitem[6];
> > > > > arr[a].rcolor=dataitem[7];
> > > > > arr[a].bcolor=dataitem[8];
> > > > > dataitem[2].split(",")
> > > > > for (var b=0;b<dataitem;b++) {
> > > > > arr[a].nodelinks[b]=dataitem[b]
> > > > > }
> > > > > }
> > > > > }
> > > > > }
> > > >
> > > > Well now the gist seem to work but there must be some problem with javascript
> > > > I manage to get an alert on the data if i "load twice", isn't that strange.
> > > >
> > > > alert(textFromFileLoaded);
> > > > sub=textFromFileLoaded.split("!");
> > > >
> > > > "X3LOADSAVE.js:46 Uncaught ReferenceError: textFromFileLoaded is not defined
> > > > at loadGraph (X3LOADSAVE.js:46)
> > > > at HTMLButtonElement.onclick (0GRAPH.HTML?filename=N8L3circle.txt:31)"
> > > >
> > > > But second time file loaded it is read into array without errors reported, it seem like a timing issue?
> > > >
> > > > There is no problem to just write to the textarea first time but for some reason i can not use textFromFileload at all i must copy the value to my own variable and even then it will not be read in the first time i load, but the second time i press button to load it work.
> > > >
> > > > function loadGraph()
> > > > {
> > > > textFromFileLoaded="";
> > > > var fileToLoad = document.getElementById("fileToLoad").files[0];
> > > > var fileReader = new FileReader();
> > > > fileReader.onload = function(fileLoadedEvent)
> > > > {
> > > > textFromFileLoaded = fileLoadedEvent.target.result;
> > > > document.debug.data.value = textFromFileLoaded;
> > > > mytext=textFromFileLoaded;
> > > > };
> > > > fileReader.readAsText(fileToLoad, "UTF-8");
> > > > //arr=[];
> > > >
> > > > alert(mytext);
> > > > sub=mytext.split("!");
> > > > for (var x=0;x<sub.length;sub++){
> > > > dataitem=sub[x].split("*");
> > > > alert(dataitem[1]);
> > > > for(var a=0;a<dataitem.length;a++){
> > > > arr[a].hold=false;
> > > > arr[a].rposX=parseInt(dataitem[4]);
> > > > arr[a].rposY=parseInt(dataitem[5]);
> > > > arr[a].rwidth=parseInt(dataitem[6]);
> > > > arr[a].rheigth=parseInt(dataitem[7]);
> > > > arr[a].rcolor=dataitem[8];
> > > > arr[a].bcolor=dataitem[9];
> > > > links=dataitem[1].split(",");
> > > > for (var b=0;b<dataitem;b++) {
> > > > arr[a].nodelinks[b]=parseInt(links[b]);
> > > > }
> > > > }
> > > > }
> > > > }
> > >
> > > A real stupid way would be to have a listener upon the textarea to to call another function that actually write the data to array, because when that is written one know the value can not be undefined?
> > > And even if it is one could copy the values from the field doing the readin to array in another file.
> > >
> > > But i must say it feel like a workaround.
> >
> > Evidently i must also find away to reset this array.
> >
> > arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
> >
> > How will i easiest way achieve that?
>
> I did it this way basicly reinitialize using the number of records/nodes in file. Before i load the values so now it works...
>
>
> Well it it wasn't for the timing issue, having to load the thing twice.
>
> for (var m = 0; m <=sub.length ; m ++ )
> {
> arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
> }
This code actually load the graph. well the second time i load it.....
function loadGraph()
{
textFromFileLoaded="";
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
textFromFileLoaded = fileLoadedEvent.target.result;
document.debug.data.value = textFromFileLoaded;
mytext=textFromFileLoaded;
};
fileReader.readAsText(fileToLoad, "UTF-8");
alert(mytext);
sub=mytext.split("!");
for (var m = 0; m <=sub.length ; m ++ )
{
arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
}
var x=0;
while (x<sub.length-1){
dataitem=[];
dataitem=sub[x].split("*");
//alert(sub[x]);
var a=0;
while(a<dataitem.length){
links=dataitem[1].split(",");
var b=0;
while (b<links.length) {
arr[x].nodelinks[b]=parseInt(links[b]);
b++;
}
arr[x].hold=false;
arr[x].rposX=parseInt(dataitem[3]);
arr[x].rposY=parseInt(dataitem[4]);
arr[x].rwidth=parseInt(dataitem[5]);
arr[x].rheigth=parseInt(dataitem[6]);
arr[x].rcolor=dataitem[7];
arr[x].bcolor=dataitem[8];
a++;
}
x++;
}
textToSave="";
//Test print to textarea, so array actually hold the values.
for (var m = 0; m < nodes; m ++ ) {
textToSave+=m+"*"+arr[m].nodelinks+"*"+arr[m].hold+"*"+arr[m].rposX+"*"+arr[m].rposY+"*"+arr[m].rwidth+"*"+arr[m].rheigth+"*"+arr[m].rcolor+"*"+arr[m].bcolor+"!";
}
document.debugtwo.datatwo.value = textToSave;
}
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2017-01-23 10:29 -0800 |
| Message-ID | <2fd047d8-bee3-4192-8c4a-799c84d6876c@googlegroups.com> |
| In reply to | #32271 |
jonas.t...@gmail.com wrote: > [... code ...] copy and paste your JavaScript into here and fix the problems you see: <http://jshint.com/>
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 11:24 -0800 |
| Message-ID | <fb96a259-8a1b-4202-b615-3ef6fed59ac7@googlegroups.com> |
| In reply to | #32272 |
Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
> jonas.t...@gmail.com wrote:
>
> > [... code ...]
>
> copy and paste your JavaScript into here and fix the problems you see:
>
> <http://jshint.com/>
Well i think i can see what is going on but i just don't understand the inline functions within functions.
What i probably wan't is to make textFromFileLoaded visible outside the {} paragraphs, but i am a bit lost i really do not understand this code.
I find it strange though that i can not define a global variable mytext and copy textFromFileLoaded to it? And why does it work the second time.
fileReader.onload = function(fileLoadedEvent)
{
textFromFileLoaded = fileLoadedEvent.target.result;
document.debug.data.value = textFromFileLoaded;
mytext=textFromFileLoaded;
};
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 11:38 -0800 |
| Message-ID | <4d6a078b-9944-4244-8fb6-d5b23ed42635@googlegroups.com> |
| In reply to | #32275 |
Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
> > jonas.t...@gmail.com wrote:
> >
> > > [... code ...]
> >
> > copy and paste your JavaScript into here and fix the problems you see:
> >
> > <http://jshint.com/>
>
> Well i think i can see what is going on but i just don't understand the inline functions within functions.
> What i probably wan't is to make textFromFileLoaded visible outside the {} paragraphs, but i am a bit lost i really do not understand this code.
>
> I find it strange though that i can not define a global variable mytext and copy textFromFileLoaded to it? And why does it work the second time.
>
> fileReader.onload = function(fileLoadedEvent)
> {
> textFromFileLoaded = fileLoadedEvent.target.result;
> document.debug.data.value = textFromFileLoaded;
> mytext=textFromFileLoaded;
>
> };
But the good part load graph works i just have to push load button two times ;)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 11:56 -0800 |
| Message-ID | <1863dd79-c818-446e-8720-6db25d522ea8@googlegroups.com> |
| In reply to | #32276 |
Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
> > Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
> > > jonas.t...@gmail.com wrote:
> > >
> > > > [... code ...]
> > >
> > > copy and paste your JavaScript into here and fix the problems you see:
> > >
> > > <http://jshint.com/>
> >
> > Well i think i can see what is going on but i just don't understand the inline functions within functions.
> > What i probably wan't is to make textFromFileLoaded visible outside the {} paragraphs, but i am a bit lost i really do not understand this code.
> >
> > I find it strange though that i can not define a global variable mytext and copy textFromFileLoaded to it? And why does it work the second time.
> >
> > fileReader.onload = function(fileLoadedEvent)
> > {
> > textFromFileLoaded = fileLoadedEvent.target.result;
> > document.debug.data.value = textFromFileLoaded;
> > mytext=textFromFileLoaded;
> >
> > };
>
> But the good part load graph works i just have to push load button two times ;)
This is my "working with two loads" code but if someone straight away can say the cause why i can't load mytext first time and it say undefined or howto use textFromFileLoade outside the brackets "function?", i am all ears.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-01-23 20:36 +0000 |
| Message-ID | <87sho9v7hj.fsf@bsb.me.uk> |
| In reply to | #32278 |
jonas.thornvall@gmail.com writes:
> Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com:
>> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
>> > Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
>> > > jonas.t...@gmail.com wrote:
>> > >
>> > > > [... code ...]
>> > >
>> > > copy and paste your JavaScript into here and fix the problems you see:
>> > >
>> > > <http://jshint.com/>
>> >
>> > Well i think i can see what is going on but i just don't understand the inline functions within functions.
>> > What i probably wan't is to make textFromFileLoaded visible outside the {} paragraphs, but i am a bit lost i really do not understand this code.
>> >
>> > I find it strange though that i can not define a global variable mytext and copy textFromFileLoaded to it? And why does it work the second time.
>> >
>> > fileReader.onload = function(fileLoadedEvent)
>> > {
>> > textFromFileLoaded = fileLoadedEvent.target.result;
>> > document.debug.data.value = textFromFileLoaded;
>> > mytext=textFromFileLoaded;
>> >
>> > };
>>
>> But the good part load graph works i just have to push load button two times ;)
>
> This is my "working with two loads" code but if someone straight away
> can say the cause why i can't load mytext first time and it say
> undefined or howto use textFromFileLoade outside the brackets
> "function?", i am all ears.
Have you posted a link to a site that exhibits the problem? Code
snippets are unlikely going to get anyone tor reply.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 19:54 -0800 |
| Message-ID | <2542f4ea-03ea-4c27-88d4-6c7a49854e21@googlegroups.com> |
| In reply to | #32280 |
Den måndag 23 januari 2017 kl. 21:36:45 UTC+1 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
>
> > Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com:
> >> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
> >> > Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
> >> > > jonas.t...@gmail.com wrote:
> >> > >
> >> > > > [... code ...]
> >> > >
> >> > > copy and paste your JavaScript into here and fix the problems you see:
> >> > >
> >> > > <http://jshint.com/>
> >> >
> >> > Well i think i can see what is going on but i just don't understand the inline functions within functions.
> >> > What i probably wan't is to make textFromFileLoaded visible outside the {} paragraphs, but i am a bit lost i really do not understand this code.
> >> >
> >> > I find it strange though that i can not define a global variable mytext and copy textFromFileLoaded to it? And why does it work the second time.
> >> >
> >> > fileReader.onload = function(fileLoadedEvent)
> >> > {
> >> > textFromFileLoaded = fileLoadedEvent.target.result;
> >> > document.debug.data.value = textFromFileLoaded;
> >> > mytext=textFromFileLoaded;
> >> >
> >> > };
> >>
> >> But the good part load graph works i just have to push load button two times ;)
> >
> > This is my "working with two loads" code but if someone straight away
> > can say the cause why i can't load mytext first time and it say
> > undefined or howto use textFromFileLoade outside the brackets
> > "function?", i am all ears.
>
> Have you posted a link to a site that exhibits the problem? Code
> snippets are unlikely going to get anyone tor reply.
>
> --
> Ben.
Well it bascily working, to load and save graphs with some glitches, i will go on with the draw and edit tool the bug finding is for another day, right now the program only autogenerate regular graphs load, save and snapshot them to HDD "txt and jpg".
loadsave.js "below"
function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}
function savepng() {
var mypic = canvas.toDataURL('image/jpg',0.5);
var anobject = document.createElement('a');
anobject.href = mypic;
anobject.download = document.snap.filename.value;
anobject.click();
}
function saveGraph(){
var textToSave="";
for (var m = 0; m < nodes; m ++ ) {
var xx=parseInt(arr[m].rposX);
var yy=parseInt(arr[m].rposY);
textToSave+=m+"*"+arr[m].nodelinks+"*"+arr[m].hold+"*"+xx+"*"+yy+"*"+arr[m].rwidth+"*"+arr[m].rheigth+"*"+arr[m].rcolor+"*"+arr[m].bcolor+"\r\n";
}
var textToSaveAsBlob = new Blob([textToSave], {type:"text/plain"});
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
var fileNameToSaveAs = document.savegraph.filename.value;
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
function loadGraph()
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
document.debug.data.value = textFromFileLoaded;
mytext=textFromFileLoaded;
};
fileReader.readAsText(fileToLoad, "UTF-8");
var sub=mytext.split("\r\n");
nodes=sub.length-1;
//document.NoNodes.nodeval.value=nodes;
for (var m = 0; m <sub.length ; m ++ )
{
arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
}
var x=0;
while (x<sub.length){
var dataitem=[];
dataitem=sub[x].split("*");
var nlinks=dataitem[1].split(",");
var b=0;
while (b<nlinks.length) {
arr[x].nodelinks[b]=parseInt(nlinks[b]);
b++;
}
arr[x].hold=false;
arr[x].rposX=parseInt(dataitem[3]);
arr[x].rposY=parseInt(dataitem[4]);
arr[x].rwidth=parseInt(dataitem[5]);
arr[x].rheigth=parseInt(dataitem[6]);
arr[x].rcolor=dataitem[7];
arr[x].bcolor=dataitem[8];
x++;
}
}
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-23 20:10 -0800 |
| Message-ID | <f72b13db-ce21-4abc-ae3e-8d870b314a5d@googlegroups.com> |
| In reply to | #32288 |
Den tisdag 24 januari 2017 kl. 04:54:15 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 23 januari 2017 kl. 21:36:45 UTC+1 skrev Ben Bacarisse:
> > jonas.thornvall@gmail.com writes:
> >
> > > Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com:
> > >> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
> > >> > Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
> > >> > > jonas.t...@gmail.com wrote:
> > >> > >
> > >> > > > [... code ...]
> > >> > >
> > >> > > copy and paste your JavaScript into here and fix the problems you see:
> > >> > >
> > >> > > <http://jshint.com/>
> > >> >
> > >> > Well i think i can see what is going on but i just don't understand the inline functions within functions.
> > >> > What i probably wan't is to make textFromFileLoaded visible outside the {} paragraphs, but i am a bit lost i really do not understand this code.
> > >> >
> > >> > I find it strange though that i can not define a global variable mytext and copy textFromFileLoaded to it? And why does it work the second time.
> > >> >
> > >> > fileReader.onload = function(fileLoadedEvent)
> > >> > {
> > >> > textFromFileLoaded = fileLoadedEvent.target.result;
> > >> > document.debug.data.value = textFromFileLoaded;
> > >> > mytext=textFromFileLoaded;
> > >> >
> > >> > };
> > >>
> > >> But the good part load graph works i just have to push load button two times ;)
> > >
> > > This is my "working with two loads" code but if someone straight away
> > > can say the cause why i can't load mytext first time and it say
> > > undefined or howto use textFromFileLoade outside the brackets
> > > "function?", i am all ears.
> >
> > Have you posted a link to a site that exhibits the problem? Code
> > snippets are unlikely going to get anyone tor reply.
> >
> > --
> > Ben.
> Well it bascily working, to load and save graphs with some glitches, i will go on with the draw and edit tool the bug finding is for another day, right now the program only autogenerate regular graphs load, save and snapshot them to HDD "txt and jpg".
>
>
> loadsave.js "below"
>
> function destroyClickedElement(event)
> {
> document.body.removeChild(event.target);
> }
>
> function savepng() {
> var mypic = canvas.toDataURL('image/jpg',0.5);
> var anobject = document.createElement('a');
> anobject.href = mypic;
> anobject.download = document.snap.filename.value;
> anobject.click();
> }
>
> function saveGraph(){
> var textToSave="";
> for (var m = 0; m < nodes; m ++ ) {
> var xx=parseInt(arr[m].rposX);
> var yy=parseInt(arr[m].rposY);
> textToSave+=m+"*"+arr[m].nodelinks+"*"+arr[m].hold+"*"+xx+"*"+yy+"*"+arr[m].rwidth+"*"+arr[m].rheigth+"*"+arr[m].rcolor+"*"+arr[m].bcolor+"\r\n";
> }
> var textToSaveAsBlob = new Blob([textToSave], {type:"text/plain"});
> var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
> var fileNameToSaveAs = document.savegraph.filename.value;
> var downloadLink = document.createElement("a");
> downloadLink.download = fileNameToSaveAs;
> downloadLink.innerHTML = "Download File";
> downloadLink.href = textToSaveAsURL;
> downloadLink.onclick = destroyClickedElement;
> downloadLink.style.display = "none";
> document.body.appendChild(downloadLink);
> downloadLink.click();
> }
>
> function loadGraph()
> {
> var fileToLoad = document.getElementById("fileToLoad").files[0];
> var fileReader = new FileReader();
> fileReader.onload = function(fileLoadedEvent)
> {
> var textFromFileLoaded = fileLoadedEvent.target.result;
> document.debug.data.value = textFromFileLoaded;
> mytext=textFromFileLoaded;
> };
> fileReader.readAsText(fileToLoad, "UTF-8");
>
> var sub=mytext.split("\r\n");
> nodes=sub.length-1;
> //document.NoNodes.nodeval.value=nodes;
> for (var m = 0; m <sub.length ; m ++ )
> {
> arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
> }
> var x=0;
> while (x<sub.length){
> var dataitem=[];
> dataitem=sub[x].split("*");
> var nlinks=dataitem[1].split(",");
> var b=0;
>
> while (b<nlinks.length) {
> arr[x].nodelinks[b]=parseInt(nlinks[b]);
> b++;
> }
> arr[x].hold=false;
> arr[x].rposX=parseInt(dataitem[3]);
> arr[x].rposY=parseInt(dataitem[4]);
> arr[x].rwidth=parseInt(dataitem[5]);
> arr[x].rheigth=parseInt(dataitem[6]);
> arr[x].rcolor=dataitem[7];
> arr[x].bcolor=dataitem[8];
> x++;
> }
> }
Here is a graph after loading.
https://1drv.ms/i/s!AonBnYlXpxi4gaJSPlkC-AE-LeqCIA
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-01-24 14:27 +0000 |
| Message-ID | <87d1fcttwu.fsf@bsb.me.uk> |
| In reply to | #32288 |
jonas.thornvall@gmail.com writes: > Den måndag 23 januari 2017 kl. 21:36:45 UTC+1 skrev Ben Bacarisse: >> jonas.thornvall@gmail.com writes: >> > Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com: >> >> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com: >> >> > Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO): >> >> > > jonas.t...@gmail.com wrote: <snip> >> > This is my "working with two loads" code but if someone straight away >> > can say the cause why i can't load mytext first time and it say >> > undefined or howto use textFromFileLoade outside the brackets >> > "function?", i am all ears. >> >> Have you posted a link to a site that exhibits the problem? Code >> snippets are unlikely going to get anyone tor reply. <snip> > Well it bascily working, Ah, OK. That's another reason you may not get many responses. You post so many followups to yourself that people might get the idea you post first and investigate later. Anyone looking at a problem might feel they are wasting their time since you'll fix it yourself in the man time. I see you posted more code with no URL. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-24 08:24 -0800 |
| Message-ID | <91deb8b3-36f6-4513-a2b5-abf229efb6fb@googlegroups.com> |
| In reply to | #32298 |
Den tisdag 24 januari 2017 kl. 15:27:33 UTC+1 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
>
> > Den måndag 23 januari 2017 kl. 21:36:45 UTC+1 skrev Ben Bacarisse:
> >> jonas.thornvall@gmail.com writes:
> >> > Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com:
> >> >> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
> >> >> > Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
> >> >> > > jonas.t...@gmail.com wrote:
> <snip>
> >> > This is my "working with two loads" code but if someone straight away
> >> > can say the cause why i can't load mytext first time and it say
> >> > undefined or howto use textFromFileLoade outside the brackets
> >> > "function?", i am all ears.
> >>
> >> Have you posted a link to a site that exhibits the problem? Code
> >> snippets are unlikely going to get anyone tor reply.
> <snip>
> > Well it bascily working,
>
> Ah, OK. That's another reason you may not get many responses. You post
> so many followups to yourself that people might get the idea you post
> first and investigate later. Anyone looking at a problem might feel they
> are wasting their time since you'll fix it yourself in the man time.
>
> I see you posted more code with no URL.
>
> <snip>
> --
> Ben.
Well i don't think it is a bug problem the problem is that i do not understand how the invoked function do work. I simply do not get how a variable within the invoked function "textFromFileLoaded" manage to write the data to a textarea. But when i try to use it after the invoked? function code it is undefined. So as you can see i tried to copy it to a global variable mytext. Problem is when mytext is called after the function it is undefined.
So i understand, that i just do not understand how this type of invoked functions work, in any normal case the global variable mytext could not be undefined. I have not the faintest idea what is going on, so there is nothing to look for.
function o_gush(){
etc
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
document.debug.data.value = textFromFileLoaded;
mytext=textFromFileLoaded;
};
fileReader.readAsText(fileToLoad, "UTF-8");
**do** something withh mytext----->undefined WHY????????????????? It wrote to textarea usin textFromFileLoeded yet neither textFromFileLoaded nor mytext exist outside paragraph?????? Well unless you load again..........
etc}
[toc] | [prev] | [next] | [standalone]
| From | Jake Jarvis <pig_in_shoes@yahoo.com> |
|---|---|
| Date | 2017-01-24 17:42 +0100 |
| Message-ID | <o68034$fje$1@dont-email.me> |
| In reply to | #32299 |
Am 24.01.2017 um 17:24 schrieb jonas.thornvall@gmail.com:
> Den tisdag 24 januari 2017 kl. 15:27:33 UTC+1 skrev Ben Bacarisse:
>> jonas.thornvall@gmail.com writes:
>>
>>> Den måndag 23 januari 2017 kl. 21:36:45 UTC+1 skrev Ben Bacarisse:
>>>> jonas.thornvall@gmail.com writes:
>>>>> Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com:
>>>>>> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
>>>>>>> Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
>>>>>>>> jonas.t...@gmail.com wrote:
>> <snip>
>>>>> This is my "working with two loads" code but if someone straight away
>>>>> can say the cause why i can't load mytext first time and it say
>>>>> undefined or howto use textFromFileLoade outside the brackets
>>>>> "function?", i am all ears.
>>>>
>>>> Have you posted a link to a site that exhibits the problem? Code
>>>> snippets are unlikely going to get anyone tor reply.
>> <snip>
>>> Well it bascily working,
>>
>> Ah, OK. That's another reason you may not get many responses. You post
>> so many followups to yourself that people might get the idea you post
>> first and investigate later. Anyone looking at a problem might feel they
>> are wasting their time since you'll fix it yourself in the man time.
>>
>> I see you posted more code with no URL.
>>
>> <snip>
>> --
>> Ben.
>
> Well i don't think it is a bug problem the problem is that i do not understand how the invoked function do work. I simply do not get how a variable within the invoked function "textFromFileLoaded" manage to write the data to a textarea. But when i try to use it after the invoked? function code it is undefined. So as you can see i tried to copy it to a global variable mytext. Problem is when mytext is called after the function it is undefined.
>
> So i understand, that i just do not understand how this type of invoked functions work, in any normal case the global variable mytext could not be undefined. I have not the faintest idea what is going on, so there is nothing to look for.
>
> function o_gush(){
> etc
> fileReader.onload = function(fileLoadedEvent)
> {
> var textFromFileLoaded = fileLoadedEvent.target.result;
> document.debug.data.value = textFromFileLoaded;
> mytext=textFromFileLoaded;
> };
> fileReader.readAsText(fileToLoad, "UTF-8");
> **do** something withh mytext----->undefined WHY????????????????? It wrote to textarea usin textFromFileLoeded yet neither textFromFileLoaded nor mytext exist outside paragraph?????? Well unless you load again..........
> etc}
>
Have you considered sprinkling your code with some debug messages, so as
to make sure the flow of the program is what you think it ought to be?
When you write "try to use it after the", what do you mean exactly?
Time or location?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-24 08:54 -0800 |
| Message-ID | <cdbe2741-c99e-4f76-9779-7bf1f6c5f6d7@googlegroups.com> |
| In reply to | #32300 |
Den tisdag 24 januari 2017 kl. 17:42:54 UTC+1 skrev Jake Jarvis:
> Am 24.01.2017 um 17:24 schrieb jonas.thornvall@gmail.com:
> > Den tisdag 24 januari 2017 kl. 15:27:33 UTC+1 skrev Ben Bacarisse:
> >> jonas.thornvall@gmail.com writes:
> >>
> >>> Den måndag 23 januari 2017 kl. 21:36:45 UTC+1 skrev Ben Bacarisse:
> >>>> jonas.thornvall@gmail.com writes:
> >>>>> Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com:
> >>>>>> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
> >>>>>>> Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
> >>>>>>>> jonas.t...@gmail.com wrote:
> >> <snip>
> >>>>> This is my "working with two loads" code but if someone straight away
> >>>>> can say the cause why i can't load mytext first time and it say
> >>>>> undefined or howto use textFromFileLoade outside the brackets
> >>>>> "function?", i am all ears.
> >>>>
> >>>> Have you posted a link to a site that exhibits the problem? Code
> >>>> snippets are unlikely going to get anyone tor reply.
> >> <snip>
> >>> Well it bascily working,
> >>
> >> Ah, OK. That's another reason you may not get many responses. You post
> >> so many followups to yourself that people might get the idea you post
> >> first and investigate later. Anyone looking at a problem might feel they
> >> are wasting their time since you'll fix it yourself in the man time.
> >>
> >> I see you posted more code with no URL.
> >>
> >> <snip>
> >> --
> >> Ben.
> >
> > Well i don't think it is a bug problem the problem is that i do not understand how the invoked function do work. I simply do not get how a variable within the invoked function "textFromFileLoaded" manage to write the data to a textarea. But when i try to use it after the invoked? function code it is undefined. So as you can see i tried to copy it to a global variable mytext. Problem is when mytext is called after the function it is undefined.
> >
> > So i understand, that i just do not understand how this type of invoked functions work, in any normal case the global variable mytext could not be undefined. I have not the faintest idea what is going on, so there is nothing to look for.
> >
> > function o_gush(){
> > etc
> > fileReader.onload = function(fileLoadedEvent)
> > {
> > var textFromFileLoaded = fileLoadedEvent.target.result;
> > document.debug.data.value = textFromFileLoaded;
> > mytext=textFromFileLoaded;
> > };
> > fileReader.readAsText(fileToLoad, "UTF-8");
> > **do** something withh mytext----->undefined WHY????????????????? It wrote to textarea usin textFromFileLoeded yet neither textFromFileLoaded nor mytext exist outside paragraph?????? Well unless you load again..........
> > etc}
> >
>
> Have you considered sprinkling your code with some debug messages, so as
> to make sure the flow of the program is what you think it ought to be?
>
> When you write "try to use it after the", what do you mean exactly?
> Time or location?
Well i always imagined that code is executed linear line after line and if there is a paragraph with loops or function calls, after the code inside the paragraph executed the code below it is executed. That is my general understanding of programming languages that things return after the paragraph code executed. If this is not the case with javascript, i do wonder what this new paradigm called and who come up with it, because it really isn't obvious.
So where do you suggest the program go after the fileloading paragraph executed, because i am really out of knowledge on that part?
And if it is not to 5he line of code below it after paragraph i seriously doubt the sanity of the one who implemented this invoked function call feature. Things should be transparent not upto guess work or bible studies.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-24 09:04 -0800 |
| Message-ID | <9f7c88aa-e608-4ad7-a0f2-18f919f37809@googlegroups.com> |
| In reply to | #32301 |
Den tisdag 24 januari 2017 kl. 17:54:52 UTC+1 skrev jonas.t...@gmail.com:
> Den tisdag 24 januari 2017 kl. 17:42:54 UTC+1 skrev Jake Jarvis:
> > Am 24.01.2017 um 17:24 schrieb jonas.thornvall@gmail.com:
> > > Den tisdag 24 januari 2017 kl. 15:27:33 UTC+1 skrev Ben Bacarisse:
> > >> jonas.thornvall@gmail.com writes:
> > >>
> > >>> Den måndag 23 januari 2017 kl. 21:36:45 UTC+1 skrev Ben Bacarisse:
> > >>>> jonas.thornvall@gmail.com writes:
> > >>>>> Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com:
> > >>>>>> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
> > >>>>>>> Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
> > >>>>>>>> jonas.t...@gmail.com wrote:
> > >> <snip>
> > >>>>> This is my "working with two loads" code but if someone straight away
> > >>>>> can say the cause why i can't load mytext first time and it say
> > >>>>> undefined or howto use textFromFileLoade outside the brackets
> > >>>>> "function?", i am all ears.
> > >>>>
> > >>>> Have you posted a link to a site that exhibits the problem? Code
> > >>>> snippets are unlikely going to get anyone tor reply.
> > >> <snip>
> > >>> Well it bascily working,
> > >>
> > >> Ah, OK. That's another reason you may not get many responses. You post
> > >> so many followups to yourself that people might get the idea you post
> > >> first and investigate later. Anyone looking at a problem might feel they
> > >> are wasting their time since you'll fix it yourself in the man time.
> > >>
> > >> I see you posted more code with no URL.
> > >>
> > >> <snip>
> > >> --
> > >> Ben.
> > >
> > > Well i don't think it is a bug problem the problem is that i do not understand how the invoked function do work. I simply do not get how a variable within the invoked function "textFromFileLoaded" manage to write the data to a textarea. But when i try to use it after the invoked? function code it is undefined. So as you can see i tried to copy it to a global variable mytext. Problem is when mytext is called after the function it is undefined.
> > >
> > > So i understand, that i just do not understand how this type of invoked functions work, in any normal case the global variable mytext could not be undefined. I have not the faintest idea what is going on, so there is nothing to look for.
> > >
> > > function o_gush(){
> > > etc
> > > fileReader.onload = function(fileLoadedEvent)
> > > {
> > > var textFromFileLoaded = fileLoadedEvent.target.result;
> > > document.debug.data.value = textFromFileLoaded;
> > > mytext=textFromFileLoaded;
> > > };
> > > fileReader.readAsText(fileToLoad, "UTF-8");
> > > **do** something withh mytext----->undefined WHY????????????????? It wrote to textarea usin textFromFileLoeded yet neither textFromFileLoaded nor mytext exist outside paragraph?????? Well unless you load again..........
> > > etc}
> > >
> >
> > Have you considered sprinkling your code with some debug messages, so as
> > to make sure the flow of the program is what you think it ought to be?
> >
> > When you write "try to use it after the", what do you mean exactly?
> > Time or location?
>
> Well i always imagined that code is executed linear line after line and if there is a paragraph with loops or function calls, after the code inside the paragraph executed the code below it is executed. That is my general understanding of programming languages that things return after the paragraph code executed. If this is not the case with javascript, i do wonder what this new paradigm called and who come up with it, because it really isn't obvious.
>
> So where do you suggest the program go after the fileloading paragraph executed, because i am really out of knowledge on that part?
>
> And if it is not to 5he line of code below it after paragraph i seriously doubt the sanity of the one who implemented this invoked function call feature. Things should be transparent not upto guess work or bible studies.
Just to be clear about it if i call the function a second time, it will execute the code "below" brackets/paragraph of fileloading. So for me it is a mystery, i suggested it may be something with IRQ and timing of file loading? Because it is and outside javascript call?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-24 11:07 -0800 |
| Message-ID | <57dc4904-2c4c-4dfd-bd85-4c05682f0526@googlegroups.com> |
| In reply to | #32302 |
Den tisdag 24 januari 2017 kl. 18:04:54 UTC+1 skrev jonas.t...@gmail.com:
> Den tisdag 24 januari 2017 kl. 17:54:52 UTC+1 skrev jonas.t...@gmail.com:
> > Den tisdag 24 januari 2017 kl. 17:42:54 UTC+1 skrev Jake Jarvis:
> > > Am 24.01.2017 um 17:24 schrieb jonas.thornvall@gmail.com:
> > > > Den tisdag 24 januari 2017 kl. 15:27:33 UTC+1 skrev Ben Bacarisse:
> > > >> jonas.thornvall@gmail.com writes:
> > > >>
> > > >>> Den måndag 23 januari 2017 kl. 21:36:45 UTC+1 skrev Ben Bacarisse:
> > > >>>> jonas.thornvall@gmail.com writes:
> > > >>>>> Den måndag 23 januari 2017 kl. 20:39:06 UTC+1 skrev jonas.t...@gmail.com:
> > > >>>>>> Den måndag 23 januari 2017 kl. 20:24:35 UTC+1 skrev jonas.t...@gmail.com:
> > > >>>>>>> Den måndag 23 januari 2017 kl. 19:29:54 UTC+1 skrev Michael Haufe (TNO):
> > > >>>>>>>> jonas.t...@gmail.com wrote:
> > > >> <snip>
> > > >>>>> This is my "working with two loads" code but if someone straight away
> > > >>>>> can say the cause why i can't load mytext first time and it say
> > > >>>>> undefined or howto use textFromFileLoade outside the brackets
> > > >>>>> "function?", i am all ears.
> > > >>>>
> > > >>>> Have you posted a link to a site that exhibits the problem? Code
> > > >>>> snippets are unlikely going to get anyone tor reply.
> > > >> <snip>
> > > >>> Well it bascily working,
> > > >>
> > > >> Ah, OK. That's another reason you may not get many responses. You post
> > > >> so many followups to yourself that people might get the idea you post
> > > >> first and investigate later. Anyone looking at a problem might feel they
> > > >> are wasting their time since you'll fix it yourself in the man time.
> > > >>
> > > >> I see you posted more code with no URL.
> > > >>
> > > >> <snip>
> > > >> --
> > > >> Ben.
> > > >
> > > > Well i don't think it is a bug problem the problem is that i do not understand how the invoked function do work. I simply do not get how a variable within the invoked function "textFromFileLoaded" manage to write the data to a textarea. But when i try to use it after the invoked? function code it is undefined. So as you can see i tried to copy it to a global variable mytext. Problem is when mytext is called after the function it is undefined.
> > > >
> > > > So i understand, that i just do not understand how this type of invoked functions work, in any normal case the global variable mytext could not be undefined. I have not the faintest idea what is going on, so there is nothing to look for.
> > > >
> > > > function o_gush(){
> > > > etc
> > > > fileReader.onload = function(fileLoadedEvent)
> > > > {
> > > > var textFromFileLoaded = fileLoadedEvent.target.result;
> > > > document.debug.data.value = textFromFileLoaded;
> > > > mytext=textFromFileLoaded;
> > > > };
> > > > fileReader.readAsText(fileToLoad, "UTF-8");
> > > > **do** something withh mytext----->undefined WHY????????????????? It wrote to textarea usin textFromFileLoeded yet neither textFromFileLoaded nor mytext exist outside paragraph?????? Well unless you load again..........
> > > > etc}
> > > >
> > >
> > > Have you considered sprinkling your code with some debug messages, so as
> > > to make sure the flow of the program is what you think it ought to be?
> > >
> > > When you write "try to use it after the", what do you mean exactly?
> > > Time or location?
> >
> > Well i always imagined that code is executed linear line after line and if there is a paragraph with loops or function calls, after the code inside the paragraph executed the code below it is executed. That is my general understanding of programming languages that things return after the paragraph code executed. If this is not the case with javascript, i do wonder what this new paradigm called and who come up with it, because it really isn't obvious.
> >
> > So where do you suggest the program go after the fileloading paragraph executed, because i am really out of knowledge on that part?
> >
> > And if it is not to 5he line of code below it after paragraph i seriously doubt the sanity of the one who implemented this invoked function call feature. Things should be transparent not upto guess work or bible studies.
>
> Just to be clear about it if i call the function a second time, it will execute the code "below" brackets/paragraph of fileloading. So for me it is a mystery, i suggested it may be something with IRQ and timing of file loading? Because it is and outside javascript call?
I guess file read and write is system calls and the code below is for some reason executed before the system actually fetched and transfered the data into the variable. ***I think that is what happens***. And at second call there is no problem because the data is already there. I even tried a dummy loop doing something before accessing mytext but it did not help it was basically a counter up to a million adding the counter values, maybe it simply was to fast executed.
Yeah i know that it indeed do sound weird, but if that is the case can you do anything about it?
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web