Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32314
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Read in file to array. |
| Date | 2017-01-24 21:35 +0000 |
| Message-ID | <240120172135245529%timstreater@greenbee.net> (permalink) |
| References | (14 earlier) <o68034$fje$1@dont-email.me> <cdbe2741-c99e-4f76-9779-7bf1f6c5f6d7@googlegroups.com> <9f7c88aa-e608-4ad7-a0f2-18f919f37809@googlegroups.com> <57dc4904-2c4c-4dfd-bd85-4c05682f0526@googlegroups.com> <2f259308-c08a-485f-8007-1cc7d5d64f33@googlegroups.com> |
In article <2f259308-c08a-485f-8007-1cc7d5d64f33@googlegroups.com>,
<jonas.thornvall@gmail.com> wrote:
>Den tisdag 24 januari 2017 kl. 20:07:12 UTC+1 skrev jonas.t...@gmail.com:
>> 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?
>
>Well i could probably change function to call and let that function call
>loadGraph two times, but as i say really do not understand what is happening,
>as soon any of the skilled programmers tell me that it is a timing issue with
>system call i will think up something.
>
>For me it seem hard to beleive it is some bug in code that dissapear the
>second time you load the function, it seem the part that load the I/O data is
>not in phase with the runtime execution of the script.
>
>One would thought it should had waited and data acknowledged loaded, but maybe the processes somehow run in different threads with priorities.
I already explained what is likely going on and what you should do
about it. Can't you read?
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web