|
Post by DARKNIGHT on Dec 11, 2022 13:40:58 GMT -5
Hello everyone, the problem I am currently having is another old one that has plaqued me for years. when I code a program to write lines of data to a data file, it seems that somewhere
along the line, that a line is skipped causing a Read Error. How can I stop this? everytime I have to open the Data File and Manually fix this.
IE:
5623,J Schlock,Joe 2256,T Smith,Tom
6846,B Jones,Bill
here is a snippit of my code that writes the DataFile I left out the Log In and Auto Number Gen Subs, as they do not apply to the problem at hand
[CNA] let AG$="ON" ' * Auto Gen user ID status let Un$="" cls locate 25,3:print"<<<<< CREATE NEW USER ACCOUNT >>>>>" locate 5,5:print" Auto-Gen ID [ "; AG$;" ]" locate 5,6:print"--------------------------------------------------------------------------------------------" locate 5,7:print" User Name: USER ID #: " locate 5,8:print"--------------------------------------------------------------------------------------------" locate 5,9:print" Enter User's First Name For The Account : "
35 locate 20,7:input"";Un$ ' * User Login Name if Un$="" then notice" ACCOUNT CREATION ERROR"+CHR$(13)+" YOU MUST PROVIDE A USER NAME FOR THIS ACCOUNT":GOTO 40
40 locate 48,9:input "";Udn$ '* User Display Name if Udn$="" then notice" PLEASE ENTER USER'S FIRST NAME"+chr$(13) + "FOR ACCOUNT DISPLAY PURPOSES":goto 40
[WriteNew] ' *Create New account open"UR" for Append as #7 print #7,Un$;",";num;",";Udn$; close #7 locate 5,9:print"**********************************************************************************" locate 5,10:print" PLEASE MAKE A NOTE OF YOUR LOG IN INFORMATION," locate 5,11:print" AND KEEP IT IN A SAFE PLACE FOR FUTURE USE" locate 5,12:print"*********************************************************************************" locate 5,14:input" PRESS 'ENTER' AFTER YOU HAVE DONE THIS >";RT$ cls goto [LogIn]
is there a way to remedy this, or is it just the nature of the beast?
Thanks in Advance, Jim
|
|
|
Post by Rod on Dec 11, 2022 16:04:59 GMT -5
Your [WriteNew] code block does not really match the file format you list. You have it as user name number and udns$ whatever that is. You also close the writing line with a ; which suppresses the CrLf pair that is normally added when a string is sent. This new line pair works with input when you read the data back to segment each record.
So we need to see the real code.
Best to open the file and read in each character and print the asc() value. That way you will see what the hidden character values ar that are breaking the line up. This will help debug.
|
|
|
Post by xxgeek on Dec 11, 2022 16:11:29 GMT -5
After running this in a loop and entering the data asked for I noticed some problems. It is not very intuitive. Very easy for whoever enters the data to make mistakes. There is nothing in the code to check if the data is "worthy", whether or not it is numeric, or alphanumeric, or in the correct format. I could enter anything, and I did. How many people use this, and enter their own data?
If a user makes a mistake it can cause untold problems in the data.
Also, what the user sees is a bit messy, I cleaned that up a bit. Makes it less confusing if the cursor is in the right place to enter the data.
The "skipping lines" may be user error, but since I am not familiar with this kind of data input I cannot say for sure. Someone else will be along to discuss that part.
My advice would be to write in some code to make sure the user can't mess up the file being appended by checking what is inputted to verify it is in the correct format, and whether it is numeric when it is supposed to be, and alphanumeric when it is supposed to be, and doesn't include any other things like 20 empty spaces etc..
It would be even better if one or two people did the actual data entry Users can do all sorts of things you don't expect. Always check before writing to the file. Even then, they'll find a way.
'5623,J Schlock,Joe '2256,T Smith,Tom
'6846,B Jones,Bill
'here is a snippit of my code that writes the DataFile 'I left out the Log In and Auto Number Gen Subs, as they do not apply to the problem at hand
[CNA] let AG$="ON" ' * Auto Gen user ID status let Un$="" cls locate 5,3 : print "<<<<< CREATE NEW USER ACCOUNT >>>>>" locate 5,5 : print " Auto-Gen ID [ "; AG$;" ]" 'locate 5,6 : print "-------------------------" locate 5,7 : print " Enter: USER ID # : " 'locate 5,8 : print "-------------------------" locate 5,9 : print " Enter User First Name For The Account : "
35 locate 24, 7 : input"";Un$ ' * User Login Name if Un$="" then notice" ACCOUNT CREATION ERROR"+CHR$(13)+" YOU MUST PROVIDE A USER NAME FOR THIS ACCOUNT":GOTO 40
40 locate 45,9 : input "";Udn$ '* User Display Name if Udn$="" then notice" PLEASE ENTER USER'S FIRST NAME"+chr$(13) + "FOR ACCOUNT DISPLAY PURPOSES":goto 40
[WriteNew] ' *Create New account open"UR" for Append as #7 print #7,Un$;",";num;",";Udn$; close #7 'locate 5,9 : print "************************************************************************" locate 5,10 : print " PLEASE MAKE A NOTE OF YOUR LOG IN INFORMATION," locate 5,11 : print " AND KEEP IT IN A SAFE PLACE FOR FUTURE USE" 'locate 5,12 : print "***********************************************************************" locate 5,14 input " PRESS 'ENTER' AFTER YOU HAVE DONE THIS >";RT$ cls goto [CNA] [\code]
|
|
|
Post by DARKNIGHT on Dec 11, 2022 17:49:00 GMT -5
to Rod: thanks for your input,
the reason that the data is written as that, is because it is just a mockup of the real data file. and I see now that I got the order wrong.it is just an example to show how a line is skipped when the data is written to the file, as the actual file contains my true name and of family members, as test data.
Udn$ is User dsisplay name. when a user succesfully logs in, they are sent to a page which displays a welcome message so it is displayed as Welcome Rod, instead of R Jones / smith Etc.
and also now realize that the trailing Semi-colon is not necessary, as the file is being written in seperate lines, and not one long continuous line of data.
I thank you for your assistance. I will try the ASC code Idea maybe it will shed some light on what is going on
XXGeek, thanks for letting me know that I forgot to add input error testing, I will be sure to do that,and do some polishing of my code.
thanks to everyone who gave advice on this
when I get all the bugs fixed, I might get a wild hair, and submit the entire code, Sans my data of course...
someone might find it instructive and / or useful. for me it is just an exercise in my love of coding as a hobby and brushing up on LB basic, after several years away from it.
|
|
|
Post by tsh73 on Dec 12, 2022 1:48:39 GMT -5
Jim, so program you posted does not show problem you are talking about. It does not put empty strings - it does not break string at all.
If problem is still there post working example showing it. Is data entered always come from Input? If you are reading from a textbox, then value could be pasted containing line break In that case, line like a$=trim$(a$) will remove it.
|
|
|
Post by DARKNIGHT on Dec 12, 2022 4:14:57 GMT -5
input always comes from standard input statements. it is very "Dos-ey. and the data is always written to the file in the same format. I haven't had any error msgs coming up.
Einstein would have called it "Spooky action" LOL But I know there is a reason this is happening, just perplexed at to what that is ... I'll just post he code in its entirety if you think that will help. I dont plan to make this an executable and try to sell it anyway. consider it like donating organs in the name of science hehe
Run this setup program first, as it creates all the data files needed for the program to work properly
rem **************************************************** rem * * * PROGRAM FILE SETUP * * * rem * Run Only once to Create DataFiles * rem *****************************************************
rem ** Create index of used # count open "ucount" for output as #1 print #1,0 close #1
rem ** Create File for used ID numbers open "usednums" for append as #3 print #3,0000 close #3
print"<<<< SETUP FILES HAVE BEEN CREATED >>>>" print" THE LOG IN PROGRAM IS NOW READY FOR USE!" end
and here is the actual full program : Enter "New" for user name and "Admin" as ID # at the Login to create a new user account..
' **** USER ACCOUNT LOG IN W/ AUTO GENERATED USER ID # ****
[LogIn] cls locate 7,5:print" [ PLEASE, LOG IN TO YOUR ACCOUNT ]" locate 5,6:print"--------------------------------------------------------------------------------------------" locate 5,7:print" User Name: ID #: " locate 5,8:print"--------------------------------------------------------------------------------------------"
10 locate 20,7:input "";Un$ if Un$="" then let Msg$="USER NAME": goto [LogErr] 20 locate 62,7:input "";ID$ if ID$=""then let Msg$="USER ID #":goto [LogErr] 30 if Un$="New"and ID$="Admin" then goto [CNA]
[FetchUD] open"UR" for input as #7 if eof(#7) <> 0 then [LF]
[ReadLoop] input #7,un$ input #7,id$ input #7,Dn$ if Un$=un$ and ID$=id$ then close #7:goto [LP] 'if Un$<un$ and ID$<id$ then close #7: goto [NUA] if eof(#7) = 0 then [ReadLoop]
[LF] notice "LOG IN ERROR"+chr$(13)+"YOU ENTERED AN INCORRECT USER NAME OR ID # " close #7:goto [LogIn] end
[LogErr]
notice " YOU MUST PROVIDE A ";Msg$; " TO LOG IN" goto [LogIn] end
[NUA] Notice"ACCOUNT ERROR"+CHR$(13)+"YOU CURRENTLY DO NOT HAVE AN" +chr$(13)+ "ACTIVE ACCOUNT ON THIS SYSTEM"+chr$(13)+" SEE SYSTEM ADMIN TO REGISTER FOR ACCESS RIGHTS" goto [LogIn]
[CNA] let AG$="ON" let Un$="" cls locate 25,3:print"<<<<< CREATE NEW USER ACCOUNT >>>>>" locate 5,5:print" Auto-Gen ID [ "; AG$;" ]" locate 5,6:print"--------------------------------------------------------------------------------------------" locate 5,7:print" User Name: USER ID #: " locate 5,8:print"--------------------------------------------------------------------------------------------" locate 5,9:print" Enter User's First Name For The Account : "
35 locate 20,7:input"";Un$ ' * User Login Name if Un$="" then notice" ACCOUNT CREATION ERROR"+CHR$(13)+" YOU MUST PROVIDE A USER DISPLAY NAME FOR THIS ACCOUNT":GOTO 35
40 locate 48,9:input "";Udn$ if Udn$="" then notice" PLEASE ENTER USER'S FIRST NAME"+chr$(13) + "FOR ACCOUNT DISPLAY PURPOSES":goto 40
' * Generate User ID for Account
50 let num=int(rnd(1)*10000) if num<1000 then goto 50
' ** get current used num entry count ** open "ucount" for input as #1 input #1, cnt close #1
'** compare gen. # to used # list open "usednums" for input as #2 for x=1 to cnt input #2,unum if unum=num then goto 50 ',* if number used/ gen another next x close #2
' ** get current used num entry count as ref.** open "ucount" for input as #1 input #1,cnt close #1 let cnt=cnt+1' * augment used num cnt by 1
'** save new num cnt to HD ** open "ucount" for output as #1 print #1,cnt close #1
'** add new gen # to used # list ** open "usednums" for append as #3 print #3,num close #3 locate 67,7:print num
[WriteNew] '*Create New account open"UR" for Append as #7 locate 1,1:print #7,Un$;",";num;",";Udn$; close #7 locate 5,9:print"**********************************************************************************" locate 5,10:print" PLEASE MAKE A NOTE OF YOUR LOG IN INFORMATION," locate 5,11:print" AND KEEP IT IN A SAFE PLACE FOR FUTURE USE" locate 5,12:print"*********************************************************************************" locate 5,14:input" PRESS 'ENTER' AFTER YOU HAVE DONE THIS >";RT$ cls goto [LogIn]
[LP]
cls locate 23,2:print" WELCOME, ";upper$(Dn$) locate 23,3:print"-------------------------------------------------" locate 23,6:print" YOUR HOME PAGE WOULD BE DISPLAYED AT THIS POINT"
thats all of it. I still am in the debugging stages hope you can find out what I am doing wrong, it isn't just this program, it happens in others I have written too.
Jim.
|
|
|
Post by tsh73 on Dec 12, 2022 4:55:26 GMT -5
I strongly suspect this is the problem
for x=1 to cnt input #2,unum if unum=num then goto 50 ',* if number used/ gen another next x Having GOTO out of the loop does not work reliably in LB and is strongly adviced AGAINST.
Set a flag, exit with EXIT FOR After NEXT, chechk flag and GOTO if ncessary.
flag=0 for x=1 to cnt input #2,unum if unum=num then flag=1: exit for ',* if number used/ gen another next x if flag goto 50
That would explain why other programs has same problem - because you likely do it all the time. (It is not blame or something. In Pascal it is official way to leave loops. Some BASICs works with this too - I think even LB5. But in LB4 it just happened not to work).
|
|
|
Post by Rod on Dec 12, 2022 6:57:11 GMT -5
Aside from the exit for that is required we really need to know what is breaking the line in the file. ASC() will tell us. Either your program is storing an extra CRLF pair or your use is pressing ENTER which may break the line. You only write to the file at one point in the program, so to debug you should print out what is being sent to the file. Print out the hidden characters with ASC()
for n= 1 to len(s$) print asc(mid$(s$,n,1));" = ";mid$(s$,n,1) next
|
|
|
Post by tsh73 on Dec 12, 2022 7:27:25 GMT -5
My guess that due to jumping out of FOR loop, some other jumps went wrong. And somehow we got to writing with empty variables. Hence empty line.
(I think one cannot posibly feed CR LF through mainwin Input, cant't he? So new line characters cannot appear out of thin air. ) EDIT especially because we cannot Paste in mainwin Input, at all
|
|
|
Post by Rod on Dec 12, 2022 7:43:58 GMT -5
Yes, I agree FOR loop jump is probably the problem. Perhaps this will show it happening.
[WriteNew] '*Create New account
if Un$="" or num=0 or Udn$="" then notice "Program error, empty string info!"
open"UR" for Append as #7 locate 1,1:print #7,Un$;",";num;",";Udn$; close #7 locate 5,9:print"**********************************************************************************" locate 5,10:print" PLEASE MAKE A NOTE OF YOUR LOG IN INFORMATION," locate 5,11:print" AND KEEP IT IN A SAFE PLACE FOR FUTURE USE" locate 5,12:print"*********************************************************************************" locate 5,14:input" PRESS 'ENTER' AFTER YOU HAVE DONE THIS >";RT$ cls goto [LogIn]
|
|
|
Post by DARKNIGHT on Dec 12, 2022 15:58:35 GMT -5
Rod, I added the code you submitted and found there were no blank entries in the current Data. strangething is, I added a new account and then intended to run the program with the ASC check in it and it wrote and read the data just fine! no blank. I dont get it. let me try adding another Account and see what it does this time. like I said "Spooky Action"
ok tried to add another user, and got an error that the record is past the last entry. which equates to a blank line? Nope, now it is tacking the new entry onto the one above it in the Data file. I did'nt change the code in my main program but copied and pasted the read sub into a new program and added the code for the ASc char check. I will recheck my code in the main program and try to figure out ehat went wrong now. I might have acidently changed something that caused this.
As Marvin the Martiian said long ago" OH DRAT! these computers are so naughty and complicated, I could just pinch them!"
Update:
found the problem, and eleviated it. and it seems to be alright thus far.... Fingers crossed / Touch wood! at least it isn't tacking data onto prior line now....
|
|
|
Post by tsh73 on Dec 12, 2022 16:46:13 GMT -5
Code you last posted has extra semicolon on print, here
locate 1,1:print #7,Un$;",";num;",";Udn$; That make new users stack into long broken string.
Just remove last semicolon.
|
|
|
Post by Walt Decker on Dec 12, 2022 18:53:29 GMT -5
Little tip: Do not use semicolons and spread your code out so you can see it more easily. In most instances the tokenizer disregards white space.
print #7,Un$;",";num;",";Udn$;
print #7, Un$ + ","; num; "," + Udn$
|
|
|
Post by Rod on Dec 13, 2022 2:57:20 GMT -5
Having slept on it I now remember why I really want to understand what is in the file. As posted the code should never write a blank line because NUM will list as 0 not a space. So if this really is the code it would be impossible to write a blank line because the only place the file is written is [writefile]
|
|
|
Post by DARKNIGHT on Dec 13, 2022 15:08:32 GMT -5
Thanks to everyone for your help and sugestions on this project. strangely enough, the weird anomaly has stopped now, and the entries are being written and reading properly. now I have moved onto the user home page.and it is GUI so I may dificulties on that front and if so. I will be back for assistance, Thank You All Jim
|
|