Page 1 of 1 1
Topic Options
#42653 - 2003-07-09 07:44 PM open file
anna Offline
Getting the hang of it

Registered: 2001-08-21
Posts: 71
Loc: Los Angeles, cA
I have the following code when I am running it manually it works perfect, as soon as I login it can not open the file:

IF Open(1,"c:\templog.txt",2)= 0
?"@ERROR : @SERROR"
sleep 1
$result = ReadLine(1)
$x = SUBSTR("$result",20,15)
$ = Close(1)
ELSE
? "File not open"
sleep 2
EndIf
? $x
Any ideas?

Top
#42654 - 2003-07-09 07:50 PM Re: open file
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
What is the return code for the OPEN function?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42655 - 2003-07-09 07:51 PM Re: open file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Check whether the file exists by using EXIST and use the error code liberally to debug the code. Also put a DEBUG ON into the first line of your code, this will allow you to step through code. Finally, please post code in between [CODE] tags.
_________________________
There are two types of vessels, submarines and targets.

Top
#42656 - 2003-07-09 07:51 PM Re: open file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
What happens when you display that error message in the ELSE portion of your script ?

IF Open(1,"c:\templog.txt",2)= 0
?"@ERROR : @SERROR"
sleep 1
$result = ReadLine(1)
$x = SUBSTR("$result",20,15)
$ = Close(1)
ELSE
? "File not open"
?"@ERROR : @SERROR"
sleep 2
EndIf
? $x

-Shawn

Top
#42657 - 2003-07-09 07:53 PM Re: open file
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Try this:

$rc = Open(1,"c:\templog.txt",2)
IF $rc = 0
? "file open"
$result = ReadLine(1)
$x = SUBSTR("$result",20,15)
? "substr = " + $x
$ = Close(1)
ELSE
? "File not open: Return code = " + $rc
? "Hit any key to continue"
Get $
EndIf


[ 09. July 2003, 19:56: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42658 - 2003-07-09 07:58 PM Re: open file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, little translation by myself too:
code:
IF Open(1,"c:\templog.txt")
? "File not open"
?"@ERROR : @SERROR"
sleep 2
exit 1
ENDIF

$result = ReadLine(1)
$x = SUBSTR("$result",20,15)
$ = Close(1)

_________________________
!

download KiXnet

Top
#42659 - 2003-07-09 08:52 PM Re: open file
anna Offline
Getting the hang of it

Registered: 2001-08-21
Posts: 71
Loc: Los Angeles, cA
I get the following error message:
File not open: Return code = -3

Top
#42660 - 2003-07-09 09:02 PM Re: open file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
-3 means file handle is already in use ... try changing this line:

IF Open(1,"c:\templog.txt")

to this:

IF Open(10,"c:\templog.txt")

use file handle 10.

-Shawn

Top
#42661 - 2003-07-09 09:07 PM Re: open file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
anna, you obviously are not giving us the whole script.
although shawns solution works on many cases, that is not the ultimate way.

if you can't post your whole code...
I can say that check out every file you open before this piece with filehandle "1" and close them before calling this piece.
_________________________
!

download KiXnet

Top
#42662 - 2003-07-09 09:09 PM Re: open file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well, was going to mention FreeFileHandle() but didn't want to muddy the waters this early in the game ...
Top
#42663 - 2003-07-09 09:13 PM Re: open file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure shawn.
I know you are not a noobie and probably just wanted to let me have one more reply [Wink]
thanks.
_________________________
!

download KiXnet

Top
#42664 - 2003-07-09 09:16 PM Re: open file
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Well, at least I contributed to get to the real problem so that you guys can fix it.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42665 - 2003-07-09 09:22 PM Re: open file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
By not mentioning FreeFileHandle(), I left the door wide open for you buddy ... but you didn't swoop in and take the bait ... sorry.

Well at least you said I'm not a boobie, i mean noobie. [Wink]

[ 09. July 2003, 21:26: Message edited by: Shawn ]

Top
#42666 - 2003-07-09 09:24 PM Re: open file
anna Offline
Getting the hang of it

Registered: 2001-08-21
Posts: 71
Loc: Los Angeles, cA
guys,

I've changed the file number to 4 and it works perfectly. We have a login.kix that runs for every user, in that script we are using file number 1. I didn't notice it. thank you so much, you guys are the best!

Top
#42667 - 2003-07-09 09:26 PM Re: open file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Our pleasure, anytime anna !
Top
#42668 - 2003-07-09 09:29 PM Re: open file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
says shawn "the boobie" tassie [Big Grin]
_________________________
!

download KiXnet

Top
#42669 - 2003-07-09 09:55 PM Re: open file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Shawn... [Eek!]
Top
#42670 - 2003-07-09 09:57 PM Re: open file
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
anna, you may want to look into using my OpenFile() UDF. It would have avoided the error entirely. Although it does not yet use FreeFileHandle() is does find a free file handle and is backward compatible to 4.02.

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000267#000000

[ 09. July 2003, 21:57: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42671 - 2003-07-09 09:59 PM Re: open file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Big kiss # I love you both. You too Hoby. Anna too!
Top
#42672 - 2003-07-09 10:11 PM Re: open file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Wow, love fest! May I join too? [Big Grin]

Anna: I would highly recommend to replace all hardcoded file handles with the FREEFILEHANDLE(). The script fragment below will loop until a free filehandle has been received, thus up to ten files can be opened at the same time.
code:
$handle=freefilehandle()
while not $handle
$handle=freefilehandle()
sleep 0.1
loop
$rc = Open($handle,"c:\templog.txt",2)
IF $rc = 0
? "file open"
$result = ReadLine($handle)
$x = SUBSTR("$result",20,15)
? "substr = " + $x
$ = Close($handle)
ELSE
? "File not open: Return code = " + $rc
? "Hit any key to continue"
Get $
EndIf

_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 3139 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.079 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org