Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #32581 > unrolled thread

File reading

Started byjonas.thornvall@gmail.com
First post2017-02-09 22:18 -0800
Last post2017-02-10 01:27 -0800
Articles 7 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  File reading jonas.thornvall@gmail.com - 2017-02-09 22:18 -0800
    Re: File reading jonas.thornvall@gmail.com - 2017-02-09 23:11 -0800
    Re: File reading jonas.thornvall@gmail.com - 2017-02-09 23:16 -0800
      Re: File reading "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-10 09:00 +0100
        Re: File reading jonas.thornvall@gmail.com - 2017-02-10 00:45 -0800
          Re: File reading "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-10 09:57 +0100
            Re: File reading jonas.thornvall@gmail.com - 2017-02-10 01:27 -0800

#32581 — File reading

Fromjonas.thornvall@gmail.com
Date2017-02-09 22:18 -0800
SubjectFile reading
Message-ID<444d98f0-baf6-4c2a-a36b-712ea50fc739@googlegroups.com>
I have saved files with "graphtext" each node is stored on a single line and separated with newline /r/n.

Every line have several dataitems, each dataitem is separated by "*".

Each node can have "no links" or a number of links named nodelinks, the nodelinks is separated using ",".

When i split text into noderows and then split the noderows inot dataitem array, sometimes the node have no links "nodelinks is undefined"= dataitem[1], so it can't be split. 

I try to look if there is anything to split in dataitem[1] "nodelinks" but of course sometimes it is undefined.
I forgot totally how to deal with such situations?

How can i check if dataitem[1] is undefined and how do i deal with it?
I also wonder if dataitem[1]=="1" and i split will there be one element in nlinks? var nlinks=dataitem[1].split(",");


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;

        var radarray=textFromFileLoaded.split("\r\n");
    nodes=radarray.length-1;
    //document.NoNodes.nodeval.value=nodes;
    for (var m = 0; m <radarray.length ; m ++ )
    {
      arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
    }
    var x=0;
    while (x<radarray.length){
       var dataitem=[];
       dataitem=radarray[x].split("*");
      ?????????????????????????????????????????????????????????
      if (dataitem[1]!="") { 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++;
    }
    };
    fileReader.readAsText(fileToLoad, "UTF-8");
}

[toc] | [next] | [standalone]


#32582

Fromjonas.thornvall@gmail.com
Date2017-02-09 23:11 -0800
Message-ID<9fdc35a3-eecc-4ccf-aae6-94db622456d7@googlegroups.com>
In reply to#32581
Den fredag 10 februari 2017 kl. 07:18:18 UTC+1 skrev jonas.t...@gmail.com:
> I have saved files with "graphtext" each node is stored on a single line and separated with newline /r/n.
> 
> Every line have several dataitems, each dataitem is separated by "*".
> 
> Each node can have "no links" or a number of links named nodelinks, the nodelinks is separated using ",".
> 
> When i split text into noderows and then split the noderows inot dataitem array, sometimes the node have no links "nodelinks is undefined"= dataitem[1], so it can't be split. 
> 
> I try to look if there is anything to split in dataitem[1] "nodelinks" but of course sometimes it is undefined.
> I forgot totally how to deal with such situations?
> 
> How can i check if dataitem[1] is undefined and how do i deal with it?
> I also wonder if dataitem[1]=="1" and i split will there be one element in nlinks? var nlinks=dataitem[1].split(",");
> 
> 
> 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;
> 
>         var radarray=textFromFileLoaded.split("\r\n");
>     nodes=radarray.length-1;
>     //document.NoNodes.nodeval.value=nodes;
>     for (var m = 0; m <radarray.length ; m ++ )
>     {
>       arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
>     }
>     var x=0;
>     while (x<radarray.length){
>        var dataitem=[];
>        dataitem=radarray[x].split("*");
>       ?????????????????????????????????????????????????????????
>       if (dataitem[1]!="") { 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++;
>     }
>     };
>     fileReader.readAsText(fileToLoad, "UTF-8");
> }

Example data
0*1,2,3,4,5,6*false*920*410*10*10*#588CF8*#588CF8
1*0,2,3,4,5,6*false*800*160*10*10*#8D5FB9*#8D5FB9
2*0,1,3,4,5,6*false*529*98*10*10*#97EE86*#97EE86
3*0,1,2,4,5,6*false*312*271*10*10*#EBC9D7*#EBC9D7
4*0,1,2,3,5,6*false*312*549*10*10*#5FE3AE*#5FE3AE
5*0,1,2,3,4,6*false*529*722*10*10*#F3D45C*#F3D45C
6*0,1,2,3,4,5*false*800*660*10*10*#E5F4F7*#E5F4F7
7**false*244*470*10*10*gray*gray
8**false*482*481*10*10*gray*gray
9**false*615*394*10*10*gray*gray
10**false*568*260*10*10*gray*gray
11**false*479*355*10*10*gray*gray
12**false*410*210*10*10*gray*gray
13**false*333*123*10*10*gray*gray
14**false*701*147*10*10*gray*gray
15**false*775*339*10*10*gray*gray
16**false*750*405*10*10*gray*gray
17**false*775*473*10*10*gray*gray
18**false*690*525*10*10*gray*gray
19**false*645*576*10*10*gray*gray

[toc] | [prev] | [next] | [standalone]


#32583

Fromjonas.thornvall@gmail.com
Date2017-02-09 23:16 -0800
Message-ID<301b665d-d492-4ebf-a89e-2ec8b542c828@googlegroups.com>
In reply to#32581
Den fredag 10 februari 2017 kl. 07:18:18 UTC+1 skrev jonas.t...@gmail.com:
> I have saved files with "graphtext" each node is stored on a single line and separated with newline /r/n.
> 
> Every line have several dataitems, each dataitem is separated by "*".
> 
> Each node can have "no links" or a number of links named nodelinks, the nodelinks is separated using ",".
> 
> When i split text into noderows and then split the noderows inot dataitem array, sometimes the node have no links "nodelinks is undefined"= dataitem[1], so it can't be split. 
> 
> I try to look if there is anything to split in dataitem[1] "nodelinks" but of course sometimes it is undefined.
> I forgot totally how to deal with such situations?
> 
> How can i check if dataitem[1] is undefined and how do i deal with it?
> I also wonder if dataitem[1]=="1" and i split will there be one element in nlinks? var nlinks=dataitem[1].split(",");
> 
> 
> 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;
> 
>         var radarray=textFromFileLoaded.split("\r\n");
>     nodes=radarray.length-1;
>     //document.NoNodes.nodeval.value=nodes;
>     for (var m = 0; m <radarray.length ; m ++ )
>     {
>       arr[m] ={nodelinks : [], hold : false, rposX : 0, rposY : 0, rwidth : 10, rheigth : 10, rcolor : "red" , bcolor : "green"};
>     }
>     var x=0;
>     while (x<radarray.length){
>        var dataitem=[];
>        dataitem=radarray[x].split("*");
>       ?????????????????????????????????????????????????????????
>       if (dataitem[1]!="") { 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++;
>     }
>     };
>     fileReader.readAsText(fileToLoad, "UTF-8");
> }

Solved it !== had to check against the datatype.

[toc] | [prev] | [next] | [standalone]


#32586

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-02-10 09:00 +0100
Message-ID<XnsA7185BA8DCAADeejj99@194.109.6.166>
In reply to#32583
jonas.thornvall@gmail.com wrote on 10 Feb 2017 in comp.lang.javascript:

> Solved it !== had to check against the datatype.

So can you please stop using this NG as your personal mirror,
and only ask pertinent Qs AFTER you have analized them yourself. 

Do you know what '!==' means overhere?

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#32588

Fromjonas.thornvall@gmail.com
Date2017-02-10 00:45 -0800
Message-ID<688c219b-76c1-422b-9867-4ed6bd539e93@googlegroups.com>
In reply to#32586
Den fredag 10 februari 2017 kl. 09:00:37 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 10 Feb 2017 in comp.lang.javascript:
> 
> > Solved it !== had to check against the datatype.
> 
> So can you please stop using this NG as your personal mirror,
> and only ask pertinent Qs AFTER you have analized them yourself. 
> 
> Do you know what '!==' means overhere?
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

not equal value OR not equal datatype

[toc] | [prev] | [next] | [standalone]


#32589

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2017-02-10 09:57 +0100
Message-ID<XnsA7186549EE74Beejj99@194.109.6.166>
In reply to#32588
jonas.thornvall@gmail.com wrote on 10 Feb 2017 in comp.lang.javascript:

> Den fredag 10 februari 2017 kl. 09:00:37 UTC+1 skrev Evertjan.:
>> jonas.thornvall@gmail.com wrote on 10 Feb 2017 in comp.lang.javascript:
>> 
>> > Solved it !== had to check against the datatype.

>> [..] 
>> Do you know what '!==' means overhere?

> not equal value OR not equal datatype

So I may safely conclude, 
that you did NOT have 'to check against the datatype'?

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#32591

Fromjonas.thornvall@gmail.com
Date2017-02-10 01:27 -0800
Message-ID<001a25ea-5e43-4ed7-9782-d909e8a22c6e@googlegroups.com>
In reply to#32589
Den fredag 10 februari 2017 kl. 09:57:25 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 10 Feb 2017 in comp.lang.javascript:
> 
> > Den fredag 10 februari 2017 kl. 09:00:37 UTC+1 skrev Evertjan.:
> >> jonas.thornvall@gmail.com wrote on 10 Feb 2017 in comp.lang.javascript:
> >> 
> >> > Solved it !== had to check against the datatype.
> 
> >> [..] 
> >> Do you know what '!==' means overhere?
> 
> > not equal value OR not equal datatype
> 
> So I may safely conclude, 
> that you did NOT have 'to check against the datatype'?
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

I have never said that not equal should not be used, i only said it is weird to look for not equal, here is not equal the exception isn't it?

"do until condition" seems straighforward.

In this case i do not see how it apply i can hardly look for.
If equal when i want to sort out the exceptions?

But i do find "while not conditions"
a bit backward, especially if it is building up to more complex structures, i prefer to not use negations. Because sooner or later it become confusing.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web