Alpha Video Training
Results 1 to 21 of 21

Thread: "Invalid Table Handle" in background Thread

  1. #1
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default "Invalid Table Handle" in background Thread

    I developed a background Thread using data from a file, so as to get the logic correct before dropping into a thread which monitors port 30003.
    It worked fine using the test data thus:

    Code:
    dim MonitorArray[2000] as c
    dim MonitorModeS[2000] as c
    dim VarArray[23] as c
    dim incr as n = 1
    fp = file.open("D:\My Databases\SBS\MsgLogs\Testdata.csv",FILE_RW_SHARED)
    tbl = table.open("Logging",FILE_RW_SHARED)
    idx = tbl.index_primary_put("Mode_S")
    WHILE fp.eof() = .f.
    	bsOutput = fp.read_line()
    	bsOutput = substr(bsOutput,at("MSG",bsOutput))
    	IF left(bsOutput,3) = "MSG" THEN
    		bsOutcrlf = comma_to_crlf(bsOutput)
    		VarArray.clear()
    		dim j as n = 1
    		FOR each VarRead in bsOutcrlf
    			VarArray[j] = VarRead
    			j = j + 1
    		next
    		IF inlist(VarArray[2],"3","4","8") THEN
    			rec = tbl.fetch_find(VarArray[5])
    			checkModeS = MonitorModeS.find(VarArray[5])
    			IF rec > 0 .and. CheckModeS = 0 THEN
    				MonitorArray[incr] = padr(tbl.reg,10," ")+"["+padr(tbl.Icaotypecode	,4," ")+"]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			END IF
    			IF CheckModeS > 0 .and. VarArray[2] = "3" .and. val(VarArray[15]) <> 0 THEN
    				IF right(ut(MonitorArray[CheckModeS]),1) <> "+" THEN
    					MonitorArray[CheckModeS] = MonitorArray[CheckModeS]+"+"
    				END IF
    			END IF
    			IF rec < 0 .and. CheckModeS = 0 THEN
    				MonitorArray[incr] = padr(VarArray[5],8," ")+"[New]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			END IF
    		END IF
    	END IF
    END WHILE
    fp.flush()
    fp.close()
    tbl.close()
    I then re-wrote the code as Thread Script:

    Code:
    thread_create("TestMonitorArrayThread",<<%code%
    xbasic_error_log("d:\My Databases\SBS\MsgLogs\thread_error_log.txt")
    dim MonitorThreadRunFlag as l = .t.
    dim global MonitorArray[2000] as c
    dim global MonitorModeS[2000] as c
    dim VarArray[23] as c
    dim incr as n = 1
    dim CheckModeS as n
    dim bsOutput as c
    dim bsOutcrlf as c
    dim j as n
    dim Tbl as P
    dim rec as n
    Tbl = table.open("logging",FILE_RW_SHARED)
    idx = Tbl.index_primary_put("ModeS")
    dim bs as p = sockets.open("127.0.0.1",30003,"C")
    while MonitorThreadRunFlag
    	bsOutput = bs.readline()
    	IF left(bsOutput,3) = "MSG" THEN
    		bsOutcrlf = comma_to_crlf(bsOutput)
    		VarArray.clear()
    		j = 1
    		for each VarRead in bsOutcrlf
    			VarArray[j] = VarRead
    			j = j + 1
    		next
    		if inlist(VarArray[2],"3","4","8") then
    			rec = Tbl.fetch_find(VarArray[5])
    			CheckModeS = MonitorModeS.find(VarArray[5])
    			if rec > 0 .and. CheckModeS = 0 then
    				MonitorArray[incr] = padr(Tbl.reg,10," ")+"["+padr(Tbl.ICAOTypeCode,4," ")+"]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			end if
    			if CheckModeS > 0 .and. VarArray[2] = "3" .and. val(VarArray[15]) <> 0 then
    				if right(ut(MonitorArray[CheckModeS]),1) <> "+" then
    					MonitorArray[CheckModeS] = MonitorArray[CheckModeS]+"+"
    				end if
    			end if
    			if rec < 0 .and. CheckModeS = 0 then
    				MonitorArray[incr] = padr(VarArray[5],8," ")+"[New]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			end if
    		end if
    	end if
    end while
    bs.close()
    Tbl.close()
    %code%)
    I keep getting "Invalid Table Handle" on running the Thread (Second example above but it works ok on the first. :confused:

    Why does it work in one but not the other??
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  2. #2
    "Certified" Alphaholic Tim Kiebert's Avatar
    Real Name
    Tim Kiebert
    Join Date
    Jul 2004
    Location
    Geelong, Victoria, Australia
    Posts
    2,785

    Default Re: "Invalid Table Handle" in background Thread

    This is just a guess but the table.open() may require a full path and file name for the table when used in a thread.
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

  3. #3
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default Re: "Invalid Table Handle" in background Thread

    Thanks Tim, but this command worked in a previous version of the thread:(
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  4. #4
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default Re: "Invalid Table Handle" in background Thread

    OK, I think I've sorted it:-

    changed

    Code:
    rec = tbl.fetch_find(VarArray[5])
    IF rec > 0 .and. CheckModeS = 0 THEN
        MonitorArray[incr] = padr(tbl.reg,10," ")+"["+padr(tbl.ICAOTypeCode,4," ")+"]"
    to

    Code:
    tblalias = table.current()
    rec = tblalias.fetch_find(VarArray[5])
    IF rec > 0 .and. CheckModeS = 0 THEN
        MonitorArray[incr] = padr(tblalias.reg,10," ")+"["+padr(tblalias.ICAOTypeCode,4," ")+"]"
    but now I get error message from thread:

    Sun Jan 21 10:05:52 2007

    Thread: TestMonitorArrayThread
    Script: TEMPLATE
    Line: 26
    rec = tblalias.fetch_find(VarArray[5])
    Conflicting expression data types
    Execution Stack:
    0#26 rec = tblalias.fetch_find(VarArray[5])
    in the Thread Xbasic coding
    dim rec as n
    and
    dim VarArray[23] as c

    so what the heck is happening here?:confused:
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  5. #5
    "Certified" Alphaholic Marcel Kollenaar's Avatar
    Real Name
    Marcel
    Join Date
    Apr 2003
    Location
    Twente
    Posts
    1,514

    Default Re: "Invalid Table Handle" in background Thread

    Graham,

    The function THREAD_CREATE( Thread_Name as C, Code as C [, Variables as P ] ) has an optional parameter variables.

    Why do you the opening of the tables inside the thread?

    I would place this outside the thread and pass it to the thread by the 3th parameter.

    You get something like:

    Code:
    'Create a pipe.
    hPipe = CreateNamedPipeA(lpszPipename,\
                             PIPE_ACCESS_DUPLEX,\
                             PIPE_TYPE_MESSAGE .OR. PIPE_READMODE_MESSAGE .OR. PIPE_WAIT,\
                             PIPE_UNLIMITED_INSTANCES,\
                             BUFFSIZE,\
                             BUFFSIZE,\
                             20000,\' Wait for connection within 20 seconds
                             NULL)' No security structure passed.
    
    name_space = local_variables()
    
    thread_create("ServerA5P", <<%code%
    XBASIC_ERROR_LOG("c:\ServerA5P.log") 
    
    while keep_running
    
    fSuccess.b = ReadFile(\
                       name_space.hPipe,\'Handle to pipe
                       chRequest,\'buffer to recieve data
                       BUFFSIZE,\'size of the buffer
                       cbBytesRead,\'number of bytes read
                       NULL)'not overlapped I/O
    
    ' In case of error there is a soundable alarm.
    ' In threads is no graphical I/O alowed.
    
    name_space.main_loop = .F.
    chReply = "Server has stopped by Client request."
    name_space.chReply = chReply
    
    fSuccess.b = WriteFile(\
                       name_space.hPipe,\'Handle to pipe
                       chReply,\'buffer to send data from
                       cbReplyBytes,\'size of the reply string
                       cbWritten,\'number of bytes written
                       NULL)'not overlapped I/O
    
    FlushFileBuffers(name_space.hPipe)
    
    end while
    %code%, name_space)'<<<<<< By this parameter you can access the outside variables name_space.
    I do not know if this is the solution for your problem but it may help to reduce some future problems. I think you have to keep the thread code and what you are doing as small as possible.
    Last edited by Marcel Kollenaar; 01-21-2007 at 08:21 AM. Reason: Editor problem, pushed the wrong button!
    Marcel

    I hear and I forget. I see and I remember. I do and I understand.
    ---- Confusius ----

  6. #6
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default Re: "Invalid Table Handle" in background Thread

    Thanks Marcel,

    if I DIM all variables before

    Code:
    Thread_create("name",<<%code%
       do something
    %code%,NS)
    does that mean I refer to all variables with prefix NS?

    i.e. tbl = table.open("Logging",FILE_RW_SHARED)
    dim Incr as n = 1
    I would refer to them as
    ns.tbl.fetch_first()
    and
    ns.incr
    ??

    Later @ 13:00

    Tried the thread out using the variable NS as a pointer to my local.variables() all seemed to work, but it came to the same result:(

    Sun Jan 21 13:07:03 2007

    Thread: TestMonitorArrayThread
    Script: TEMPLATE
    Line: 14
    ns.rec = ns.tblalias.fetch_find(ns.VarArray[5])
    Conflicting expression data types
    Execution Stack:
    0#14 ns.rec = ns.tblalias.fetch_find(ns.VarArray[5])
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  7. #7
    "Certified" Alphaholic
    Real Name
    Peter Wayne
    Join Date
    Apr 2000
    Posts
    1,728

    Default Re: "Invalid Table Handle" in background Thread

    Graham,
    Try this:

    Code:
    for each VarRead in bsOutcrlf
    	VarArray[j] = VarRead.value
    	j = j + 1
    next
    I don't know if it will solve your problem but I believe t's an error in your code and may account for the invalid variable type message you're getting.

  8. #8
    "Certified" Alphaholic Marcel Kollenaar's Avatar
    Real Name
    Marcel
    Join Date
    Apr 2003
    Location
    Twente
    Posts
    1,514

    Default Re: "Invalid Table Handle" in background Thread

    Quote Originally Posted by Graham Wickens View Post
    ....does that mean I refer to all variables with prefix NS?

    i.e. tbl = table.open("Logging",FILE_RW_SHARED)
    dim Incr as n = 1
    I would refer to them as
    ns.tbl.fetch_first()
    and
    ns.incr
    Yes.
    Marcel

    I hear and I forget. I see and I remember. I do and I understand.
    ---- Confusius ----

  9. #9
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default Re: "Invalid Table Handle" in background Thread

    Hi Peter,
    tried it with dot value, but still got the same error!!
    This is getting daft, as these Thread worked in a previous existance:(
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  10. #10
    "Certified" Alphaholic Marcel Kollenaar's Avatar
    Real Name
    Marcel
    Join Date
    Apr 2003
    Location
    Twente
    Posts
    1,514

    Default Re: "Invalid Table Handle" in background Thread

    Maybe you have a character number mismatch?

    Test with TYPEOF() the type of the variables. Write the result in variables outside the thread. You cannot use screen output.

    Where did you create the ns.rec = ns.tblalias.fetch_find(ns.VarArray[5]) inside the thread or outside?
    Last edited by Marcel Kollenaar; 01-21-2007 at 10:51 AM. Reason: Wrong solution, tried a better one!
    Marcel

    I hear and I forget. I see and I remember. I do and I understand.
    ---- Confusius ----

  11. #11
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default Re: "Invalid Table Handle" in background Thread

    created inside thread.
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  12. #12
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default Re: "Invalid Table Handle" in background Thread

    What is maddening about this problem is that when I run the script that simulates the thread and reads a sequential file with 10,837 records in it, the code is identical to that in the thread, other than the While .. end while is changed to fp.eof() of the input sequential csv file it works perfectly.:mad:
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  13. #13
    "Certified" Alphaholic
    Real Name
    Peter Wayne
    Join Date
    Apr 2000
    Posts
    1,728

    Default Re: "Invalid Table Handle" in background Thread

    You might also try

    dim simpleVar as c=VarArray[5]
    and then do a tbl.fetch_find(simpleVar)

  14. #14
    "Certified" Alphaholic Marcel Kollenaar's Avatar
    Real Name
    Marcel
    Join Date
    Apr 2003
    Location
    Twente
    Posts
    1,514

    Default Re: "Invalid Table Handle" in background Thread

    Quote Originally Posted by Graham Wickens View Post
    created inside thread.
    You cannot reference the name_space from the outside first and than use a .variable - tblalias - created inside the thread IMHO.:(

    Or and I have not tested that, the thread variables are visible from the outside?

    Why do you want to use such construction?

    --------------------- added --------------------------

    Addition to Peters story:

    had a similar problem with:

    Code:
    'Sources is a pointer to a list of all the installed TWAIN devices.
    sources = tw.InstalledSources()
    For Each devName In sources
      ' Create a new entry in the choice list.
      TopParent:dropdown1.choice.list.insert()
      ' :TwainForm:dropdown1.choice.list[i].text = devName 'Results in a type mismatch error.
      TopParent:dropdown1.choice.list[i].text = convert_type(devName,"C")
      TopParent:dropdown1.choice.list[i].value = convert_type(devName,"C")
      ' increment the index.
      i = i + 1
    Next devName
    I had to use convert_type(devName,"C") to overcome this problem.

    In your case it could be: ns.rec = ns.tblalias.fetch_find(convert_type(ns.VarArray[5],"C"))

    ---------------- added 2 -----------------

    Graham, do you have an isolated example that I can test?
    Last edited by Marcel Kollenaar; 01-21-2007 at 03:28 PM.
    Marcel

    I hear and I forget. I see and I remember. I do and I understand.
    ---- Confusius ----

  15. #15
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default Re: "Invalid Table Handle" in background Thread

    Attached Zip has both the test data and the Thread. The logic is sound in that it creates the end result I was after, must be something to do with Variable scope? You will have to change any specific filenames and directories. I've added all the test data as its a small file when zipped.
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  16. #16
    "Certified" Alphaholic Marcel Kollenaar's Avatar
    Real Name
    Marcel
    Join Date
    Apr 2003
    Location
    Twente
    Posts
    1,514

    Default Re: "Invalid Table Handle" in background Thread

    Graham,

    I unzipped it and looked at it. Can you provide me with the syntax and information you get from the Dim bs as p = sockets.open("127.0.0.1",30003,"C") device? I can make a file-clone to simulate it.

    However, it now 00:40 in the night and it will be this evening at about 19:00 when I start again.

    :)
    Marcel

    I hear and I forget. I see and I remember. I do and I understand.
    ---- Confusius ----

  17. #17
    "Certified" Alphaholic
    Real Name
    Peter Wayne
    Join Date
    Apr 2000
    Posts
    1,728

    Default Re: "Invalid Table Handle" in background Thread

    Graham,
    There's no index named "mode_s" in the exampleLogFile table. I'll change the index name in the code to "modes" if that's the right index.

  18. #18
    "Certified" Alphaholic
    Real Name
    Peter Wayne
    Join Date
    Apr 2000
    Posts
    1,728

    Default Re: "Invalid Table Handle" in background Thread

    Graham,
    The main problem appears to be that the thread doesn't keep the table pointer open. I inserted a tbl.persist() and then the script works (after fixing a few more small errors). Here's what I got:
    Code:
    thread_code=<<%code%
    xbasic_error_log("c:\threads\Thread_error_log.txt")
    'dim MonitorThreadRunFlag as l = .t.
    dim MonitorArray[2000] as c
    dim MonitorModeS[2000] as c
    dim VarArray[23] as c
    dim incr as n = 1
    dim k as n = 1
    dim rec as n
    dim CheckModeS as n
    dim bsOutput as c
    dim bsOutcrlf as c
    'dim MonitorVarArray[2000,23] as c
    if file.exists("c:\threads\Output.txt") then
    	file.remove("c:\threads\Output.txt")
    end if
    dim fp as p= file.create("c:\threads\Output.txt",FILE_RW_SHARED)
    tbl = table.open("c:\threads\examplelogfile",FILE_RW_SHARED)
    idx = tbl.index_primary_put("ModeS")
    'dim bs as p = sockets.open("127.0.0.1",30003,"C")
    tbl.persist()
    dim bs as p= file.open("c:\threads\Testdata.csv",FILE_RO_SHARED)
    
    'WHILE MonitorThreadRunFlag
    bsOutput=bs.read_line()
    WHILE bs.eof() = .f.
    	bsOutput = substr(bsOutput,at("MSG",bsOutput))
    	IF left(bsOutput,3) = "MSG" THEN
    		bsOutcrlf = comma_to_crlf(bsOutput)
    		VarArray.clear()
    '		dim j as n = 1
    '		FOR each VarRead in bsOutcrlf
    '			VarArray[j] = VarRead
    '			j = j + 1
    '		next
    		VarArray.initialize(bsOutcrlf)
    		IF inlist(VarArray[2],"3","4","8") THEN
    			simple_value = convert_type(VarArray[5],"C")
    			rec = tbl.fetch_find(simple_value)
    			CheckModeS = MonitorModeS.find(Simple_value)
    			IF rec > 0 .and. CheckModeS = 0 THEN
    				MonitorArray[incr] = padr(tbl.reg,9," ")+"["+padr(tbl.ICAOTypeCode,4," ")+"]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			END IF
    			IF CheckModeS > 0 .and. VarArray[2] = "3" .and. val(VarArray[15]) <> 0 THEN
    				IF right(ut(MonitorArray[CheckModeS]),1) <> "+" THEN
    					MonitorArray[CheckModeS] = MonitorArray[CheckModeS]+"+"
    				END IF
    			END IF
    			IF rec < 0 .and. CheckModeS = 0 THEN
    				MonitorArray[incr] = padr(VarArray[5],8," ")+"[New]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			END IF
    		END IF
    	END IF
    	fp.write_line("Processed line "+bsOutput)
    	bsOutput = bs.read_line()
    END WHILE
    bs.close()
    tbl.close()
    fp.write_line("Thread Test Ended at "+time("",now()))
    fp.flush()
    fp.close()
    %code%
    
    thread_create("TestMonitorArrayThread",thread_code)
    Using this code I was able to read and process the entire csv file in a background thread. I assume you can do the same with sockets.

  19. #19
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default Re: "Invalid Table Handle" in background Thread

    I had a re-think overnight and went back to my original script from about three weeks ago and got it to work.[this was before I read Peter's latest message].

    Code:
    dim MonitorThreadRunFlag as l = .t.
    dim global MonitorArray[2000] as c
    dim global MonitorModeS[2000] as c
    dim VarArray[23] as c
    dim incr as n = 1
    dim j as n = 1
    dim rec as n
    dim CheckModeS as n
    dim bsOutput as c
    dim bsOutcrlf as c
    dim global MonitorVarArray[2000,23] as c
    dim bs as p = sockets.open("127.0.0.1",30003,"C")
    ns  = local_variables()
    thread_create("TestMonitorArrayThread",<<%code%
    xbasic_error_log("d:\my databases\sbs\MsgLogs\Thread_error_log.txt")
    WHILE MonitorThreadRunFlag
    	bsOutput = bs.readline()
    	IF left(bsOutput,3) = "MSG" THEN
    		bsOutcrlf = comma_to_crlf(bsOutput)
    		VarArray.clear()
    		dim j as n = 1
    		FOR each VarRead in bsOutcrlf
    			VarArray[j] = VarRead
    			j = j + 1
    		next
    		IF inlist(VarArray[2],"3","4","8") THEN
    			CheckModeS = MonitorModeS.find(VarArray[5])
    			if CheckModeS = 0 then
    			    tbl = table.open("logging",FILE_RW_SHARED)
    				idx = tbl.index_primary_put("Mode_S")
    				rec = tbl.fetch_find(VarArray[5])
    				IF rec > 0 .and. CheckModeS = 0 THEN
    					MonitorArray[incr] = padr(tbl.reg,9," ")+"["+padr(tbl.ICAOTypeCode,4," ")+"]"
    					MonitorModeS[incr] = VarArray[5]
    					incr = incr + 1
    				END IF
    				tbl.close()
    			end if	
    			IF CheckModeS > 0 .and. VarArray[2] = "3" .and. val(VarArray[15]) <> 0 THEN
    				IF right(ut(MonitorArray[CheckModeS]),1) <> "+" THEN
    					MonitorArray[CheckModeS] = MonitorArray[CheckModeS]+"+"
    				END IF
    			END IF
    			IF rec < 0 .and. CheckModeS = 0 THEN
    				MonitorArray[incr] = padr(VarArray[5],8," ")+"[New]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			END IF
    		END IF
    	END IF
    END WHILE
    bs.close()
    tbl.close()
    %code%,ns)
    ui_msg_box("Thread Test","Ended at "+time("",now()))
    I shall now go away and digest Peter's Suggestion.
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  20. #20
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    785

    Default Re: "Invalid Table Handle" in background Thread

    Taking all that I have learnt on-board, I finally have a thread that runs ok.
    thanks to Marcel,Tim & Peter for your inputs.

    for anyone interested the final version is thus:

    Code:
    thread_code=<<%code%
    dim MonitorThreadRunFlag as l = .t.
    dim global MonitorArray[2000] as c
    dim global MonitorModeS[2000] as c
    dim VarArray[23] as c
    dim incr as n = 1
    dim rec as n
    dim CheckModeS as n
    dim bsOutput as c
    dim bsOutcrlf as c
    dim bs as p = sockets.open("127.0.0.1",30003,"C")
    dim path as c = "d:\my databases\sbs\MsgLogs\"
    IF file.exists(Path+"SBSMonitorErrorLog.txt")
    	file.remove(Path+"SBSMonitorErrorLog.txt")
    END IF
    xbasic_error_log(Path+"SBSMonitorErrorLog.txt")
    tbl = table.open("logging",FILE_RW_SHARED)
    idx = tbl.index_primary_put("Mode_S")
    WHILE MonitorThreadRunFlag
    	bsOutput = bs.readline()
    	IF left(bsOutput,3) = "MSG" THEN
    		bsOutcrlf = comma_to_crlf(bsOutput)
    		VarArray.clear()
    		VarArray.initialize(bsOutcrlf)
    		IF inlist(VarArray[2],"3","4","8") THEN
    			CheckModeS = MonitorModeS.find(VarArray[5])
    			IF CheckModeS = 0 THEN
    				rec = tbl.fetch_find(VarArray[5])
    				IF rec > 0 .and. CheckModeS = 0  THEN
    					IF isblank("tbl.as") THEN
    						MonitorArray[incr] = padr(tbl.reg,9," ")+"["+padr(tbl.ICAOTypeCode,4," ")+"]"
    						MonitorModeS[incr] = VarArray[5]
    						incr = incr + 1
    					END IF
    				END IF
    			END IF
    			IF CheckModeS > 0 .and. VarArray[2] = "3" .and. val(VarArray[15]) <> 0 THEN
    				IF right(ut(MonitorArray[CheckModeS]),1) <> "+" THEN
    					MonitorArray[CheckModeS] = MonitorArray[CheckModeS]+"+"
    				END IF
    			END IF
    			IF rec < 0 .and. CheckModeS = 0 THEN
    				MonitorArray[incr] = padr(VarArray[5],8," ")+"[New]"
    				MonitorModeS[incr] = VarArray[5]
    				incr = incr + 1
    			END IF
    		END IF
    	END IF
    END WHILE
    bs.close()
    tbl.close()
    %code%
    
    thread_create("TestMonitorArrayThread",Thread_code)
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  21. #21
    "Certified" Alphaholic Marcel Kollenaar's Avatar
    Real Name
    Marcel
    Join Date
    Apr 2003
    Location
    Twente
    Posts
    1,514

    Default Correction!

    Quote Originally Posted by Graham Wickens
    does that mean I refer to all variables with prefix NS?

    i.e. tbl = table.open("Logging",FILE_RW_SHARED)
    dim Incr as n = 1
    I would refer to them as
    ns.tbl.fetch_first()
    and
    ns.incr
    Quote Originally Posted by Marcel Kollenaar View Post
    Yes. <<<<wrong
    Now I'm busy again with my own threads and sockets and looking at Grahams code again I have to correct my answer here. It has to be 'No'. There is no need for prefix them, just passing the ns-pointer in thread_create("thread_name", thread_code, ns) is enough. All variables outside the thread can be used when you use dim ns as P = local_variables()
    Last edited by Marcel Kollenaar; 03-16-2007 at 06:38 PM. Reason: Some grammar stuff
    Marcel

    I hear and I forget. I see and I remember. I do and I understand.
    ---- Confusius ----

Similar Threads

  1. Obscure "invalid table handle" error
    By brett s in forum Alpha Five Version 7
    Replies: 5
    Last Post: 11-13-2006, 06:44 PM
  2. migrating from a5v5 causes "not valid index handle"
    By eeetee in forum Alpha Five Version 6
    Replies: 6
    Last Post: 05-30-2006, 05:42 PM
  3. error message"invalid key length"
    By aaron nash in forum Alpha Five Version 5
    Replies: 2
    Last Post: 05-31-2003, 04:32 PM
  4. How to "copy" a thread
    By Wanda Tucker in forum Alpha Five Version 5
    Replies: 15
    Last Post: 12-23-2002, 06:12 PM
  5. Help with "Bad Object Handle"
    By Tony Watts in forum Alpha Five Version 5
    Replies: 3
    Last Post: 09-26-2002, 08:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •