|
Post by DARKNIGHT on Feb 1, 2024 17:51:07 GMT -5
Hey Guys, its me Jim. As you can see, I changed my profile pic and screen name.
R/A File question:
----------------------
the only remaining question I have now is , if I want to add a new, Single entry at the end of the R/A File, how do I have the program advance the current Entry # by 1 ,before I write the data , so I wont be overwriting an existing entry? R/A files are fairly new to me, so please bare with me.... thanks in Advance again, Man
|
|
|
Post by tsh73 on Feb 2, 2024 0:43:28 GMT -5
Say you have record length 100 You get your file length (lof(#1)), say 2000 That means you now have 2000/100 = 20 records To add new one, you write 21st one So
PUT #1,21 will do.
EDIT the main point in RA files is "RANDOM ACCESS" You do not adwance by one record You instantly get/put record by number
|
|
|
Post by DARKNIGHT on Feb 2, 2024 15:00:57 GMT -5
thanks tsh73! I am so used to using sequential file Ops, R/A is rather new to me. I will try your code. thanks!
|
|
|
Post by DARKNIGHT on Feb 2, 2024 17:43:07 GMT -5
Hey tsh,
I just realized that I may not have included my Add new Entry sub in the code I posted. I get what you were trying to say, just not sure how to use it in my code.
sorry to be such a pain. or seem thick in the head.... Thanks in advance
[Add_Record] cls locate 8,6:print"[ ADD NEW RECORD ]" locate 5,7:print"=============================================================" locate 5,8:print"| NAME: | ID #: |" locate 5,9:print"=============================================================" locate 5,11:print"==========================================================" locate 5,12:print"| ADDRESS: |" locate 5,13:print"==========================================================" locate 8,15:print" [ CONTACT INFO ]" locate 5,16:print"==============================================================" locate 5,17:print"| PHONE: EMAIL: |" locate 5,18:print"=============================================================="
[Input] locate 14,8:input"";Name$ locate 58,8:input"";IDnumber locate 19,12:input"";Address$ locate 17,17:input"";Phone$ locate 42,17:input"";Email$
[correct?] locate 8,19:input"Are All Entries Correct ? <y/n> ";ec$ locate 8,19:print" " if ec$="y" then [Save] if ec$="n" then [Edit] gosub [Input]
[Save] PUT #1,4 locate 8,19:print"<<< New Record Saved >>> " locate 8,21:input"Press 'Enter' for Roster -> ";ret$ cls gosub [Draw_Form]
[Edit] 'Place numbers next to each entry prompt let a=1 for x=1 to 5 if x=1 then let h=6:let v=8 '* Name if x=2 then let h=49:let v=8 '* ID # if x=3 then let h=7:let v=12 '* Address if x=4 then let h=7:let v=17 '* Phone if x=5 then let h=32:let v=17 '* Email locate h,v:print"[";a;"]" let a=a+1 next x
[Sel_Edit_Field]' *Field # to Edit locate 8,19:input"Enter # next to entry you want to correct:";c$ if c=1 then let h=14:let v=8:let Name$="":locate h,v:print" " '* Name if c=2 then let h=58:let v=8:let IDnumber=0:locate h,v:print" " '* ID # if c=3 then let h=19:let v=12:let Address$="":locate h,v:print" " '* Address if c=4 then let h=17:let v=17:let Phone$="":locate h,v:print" " '* Phone # if c=5 then let h=42:let v=17:let Email$="":locate h,v:print" " '* Email if c=0 then [Sel_Field] locate h,v:print" " locate h,v:input"";Name$:gosub [correct?]
|
|
|
Post by tsh73 on Feb 3, 2024 4:33:38 GMT -5
Hello Jim problem is what your code is incomplete. You have [Add_Record] But there is no code jumping there. May be some menu needed, like * view * add new * edit * exit
Thre is more then one way to build a program out of pieces you provided.
As for adding record without overwriting Your [Draw_Form] code puts number or records+1 into "a" variable
So to add next record you should change
[Save] PUT #1,4 to
[Save] PUT #1,a
|
|
|
Post by tsh73 on Feb 3, 2024 5:20:16 GMT -5
Also, you are using GOSUB wrong It is for jumping to subroutine to be returned back by RETURN If you never going to come back, use plain GOTO
|
|
|
Post by tsh73 on Feb 3, 2024 6:26:28 GMT -5
Added simple front menu. Rearranged pieces of code, changed most GOSUB to GOTO, used RETURN where we are returning from GOSUB Put lot's of indents to show what's going on. Jim, please use [ CODE ] then posting your code - this preserves indenting.
Now view / add new / edit then adding new mostly work (I can't help pressing TAB to go next field then entering new record) Really, v, h and field size should be arrays so by field c you can clear old field as
locate h(c),v(c):print space$(w(c))
' --------------------------------- gosub [CreateIfNotExists]
'--- main loop ------------------ [menu] print "--------------" print "1. View" print "2. Add new" print "3. -Edit record" print "4. -Delete record" print "0. Exit" [no_good] input act if act<0 or act >3 then [no_good]
select case act case 1 gosub [View] case 2 gosub [Add_Record] case 3 print "Edit record: Feature not realised" case 4 print "Delete record: Feature not realised" case 0 print "Bye then" close #1 end end select
GOTO [menu] '----------------------------
[CreateIfNotExists] 'does file exists at all? if fileExists(DefaultDir$, "members2.dat") = 0 then 'file not exists, so we went and write initial 3 records to it gosub [OpenFile] gosub [Set_Data] else 'opem file, leave it open gosub [OpenFile] end if return
[OpenFile] ' OPEN "members2.dat" FOR RANDOM AS #1 LEN= 76 ' Set LEN to 122 W/ Phone and Email / 76 W/o OPEN "members2.dat" FOR RANDOM AS #1 LEN= 122 recLen = 76 recLen = 122 'to be used for checking against LOF FIELD #1,_' set up the fields for file opened as #1 30 AS Name$,_ ' Name$ , string 40 AS Address$,_ ' Address$, string 6 AS IDnumber,_ ' IDnumber, numeric 16 AS Phone$,_ ' Phone #, String * - | Rem'ed out because of Errors 30 AS Email$ ' Email , String * - | return
[Set_Data]' *** CREATES RECORDS- on first time use *** for a=1 to 3 if a=1 then let Name$ = "Public, John, Q.": Address$ = "456 Maple Street, Anytown, USA":IDnumber = 9274:Phone$="(482)-160-8721":Email$="johnQP@Yahoo.com" if a=2 then let Name$ = "Jones, Alfred, R.":Address$ = "227 15th Av, New York New York, USA":IDnumber = 4365:Phone$="(218)-521-1276":Email$="AlfJones@Gamil.com" if a=3 then let Name$ = "Smith, Robert, T.":Address$ = "952 Bridge St, Burlington VT, USA":IDnumber = 1028:Phone$="(701)-882-7174":Email$="RobSmith@Aol.com" PUT #1,a next a print"Records Written" return
[View] 'JB wants some line between labels [Draw_Form] cls let a=1:let b=10 locate 8,6:print"[ MEMBER LIST ]" locate 5,7:print"========================================" locate 5,8:print"| ENT # | NAME: | ID #: |" locate 5,9:print"========================================"
[Fetch_Recs] if (a * recLen) > lof(#1) then goto [select] 'no more records GET #1,a
[Fill_Roster] locate 8,b:print a locate 15,b:print Name$' locate 38,b:print IDnumber let a=a+1:let b=b+1 goto [Fetch_Recs]
[select] locate 5,b+1:print"========================================" locate 5,b+2:Print" TYPE ENT # TO VIEW DETAILS" locate 5,b+3:input" (Enter back to menu) ->:";ent if ent = 0 then return 'to menu if ent=0 or ent > a-1 then locate 36,b+2:print" ":goto [select] gosub [Fetch_Rec] 'show single rec goto [Draw_Form] 'back to roster
'------------------------------------ [drawRecHeader] locate 5,7:print"===========================================================" locate 5,8:print"| NAME: | ID #: |" locate 5,9:print"===========================================================" locate 5,11:print"==========================================================" locate 5,12:print"| ADDRESS: |" locate 5,13:print"==========================================================" locate 8,15:print" [ CONTACT INFO ]" locate 5,16:print"==========================================================" locate 5,17:print"| PHONE: EMAIL: |" locate 5,18:print"==========================================================" return
[Fetch_Rec] cls locate 8,6:print"[ MEMBER LIST ]" gosub [drawRecHeader] Get #1, ent locate 14,8:print Name$ locate 54,8:print IDnumber locate 17,12:print Address$ locate 15,17:print Phone$ locate 38,17:print Email$ locate 7,21:input"Press 'Enter' to return to Roster -> ";rt$ return
[Add_Record] 'calculate record number nRecords=lof(#1)/recLen newRec=nRecords+1 cls locate 8,6:print"[ ADD NEW RECORD #";newRec;"]" gosub [drawRecHeader] [Input] locate 14,8:input"";Name$ locate 58,8:input"";IDnumber locate 19,12:input"";Address$ locate 17,17:input"";Phone$ locate 42,17:input"";Email$
[correct?] locate 8,19:print space$(50) locate 8,19:input"Are All Entries Correct ? <y/n> ";ec$ if ec$="y" then [Save] if ec$="n" then [Edit] goto [Input]
[Save] PUT #1,newRec locate 8,19:print space$(50) 'overwrite old line locate 8,20:print space$(50) 'overwrite old line locate 8,19:print"<<< New Record Saved >>> " locate 8,20:input"Press 'Enter' for menu -> ";ret$ cls return
[Edit] 'Place numbers next to each entry prompt let a=1 for x=1 to 5 if x=1 then let h=6:let v=8 '* Name if x=2 then let h=49:let v=8 '* ID # if x=3 then let h=7:let v=12 '* Address if x=4 then let h=7:let v=17 '* Phone if x=5 then let h=32:let v=17 '* Email locate h,v:print"[";a;"]" let a=a+1 next x
[Sel_Edit_Field]' *Field # to Edit locate 8,19:input"Enter # next to entry you want to correct:";c if c=1 then let h=14:let v=8:let Name$="":locate h,v:print" " '* Name if c=2 then let h=58:let v=8:let IDnumber=0:locate h,v:print" " '* ID # if c=3 then let h=19:let v=12:let Address$="":locate h,v:print" " '* Address if c=4 then let h=17:let v=17:let Phone$="":locate h,v:print" " '* Phone # if c=5 then let h=42:let v=17:let Email$="":locate h,v:print" " '* Email if c=0 then [Sel_Edit_Field] locate h,v:print" " select case c case 1: locate 14,8:input"";Name$ case 2: locate 58,8:input"";IDnumber case 3: locate 19,12:input"";Address$ case 4: locate 17,17:input"";Phone$ case 5: locate 42,17:input"";Email$ end select
goto [correct?]
'-------------------------------- 'from the help file ' File Operations ' Testing for File Existence function fileExists(path$, filename$) dim info$(0, 0) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
|
Post by tsh73 on Feb 3, 2024 13:39:03 GMT -5
Just did that
Also added marking record as deleted be prepending chr$(0) to Name$ works on/off
and made editing part work (though how same code works for editing both new and old record I cannot explain)
'modification: let's consider recorts with names starting from Chr$(0) deleted. 'so this triggers delete/undelete: 'if left$(Name$,1)=chr$(0) then Name$=mid$(Name$,2) else Name$=chr$(0)+Name$
' --------------------------------- gosub [CreateIfNotExists] gosub [setupFields]
'--- main loop ------------------ [menu] print "--------------" print "1. View" print "2. Add new" print "3. Edit record" print "4. Toggle delete" print "0. Exit" [no_good] input act if act<0 or act >4 then [no_good]
select case act case 1 gosub [View] case 2 gosub [Add_Record] case 3 gosub [EditRecord] case 4 gosub [ToggleDelete] case 0 print "Bye then" close #1 end end select
GOTO [menu] '----------------------------
[CreateIfNotExists] 'does file exists at all? if fileExists(DefaultDir$, "members2.dat") = 0 then 'file not exists, so we went and write initial 3 records to it gosub [OpenFile] gosub [Set_Data] else 'opem file, leave it open gosub [OpenFile] end if return
[OpenFile] ' OPEN "members2.dat" FOR RANDOM AS #1 LEN= 76 ' Set LEN to 122 W/ Phone and Email / 76 W/o OPEN "members2.dat" FOR RANDOM AS #1 LEN= 122 recLen = 76 recLen = 122 'to be used for checking against LOF FIELD #1,_' set up the fields for file opened as #1 30 AS Name$,_ ' Name$ , string 40 AS Address$,_ ' Address$, string 6 AS IDnumber,_ ' IDnumber, numeric 16 AS Phone$,_ ' Phone #, String * - | Rem'ed out because of Errors 30 AS Email$ ' Email , String * - | return
[Set_Data]' *** CREATES RECORDS- on first time use *** for a=1 to 3 if a=1 then let Name$ = "Public, John, Q.": Address$ = "456 Maple Street, Anytown, USA":IDnumber = 9274:Phone$="(482)-160-8721":Email$="johnQP@Yahoo.com" if a=2 then let Name$ = "Jones, Alfred, R.":Address$ = "227 15th Av, New York New York, USA":IDnumber = 4365:Phone$="(218)-521-1276":Email$="AlfJones@Gamil.com" if a=3 then let Name$ = "Smith, Robert, T.":Address$ = "952 Bridge St, Burlington VT, USA":IDnumber = 1028:Phone$="(701)-882-7174":Email$="RobSmith@Aol.com" PUT #1,a next a print"Records Written" return
[View] 'JB wants some line between labels [Draw_Form] cls let a=1:let b=10 locate 8,6:print"[ MEMBER LIST ]" locate 5,7:print"========================================" locate 5,8:print"| ENT # | NAME: | ID #: |" locate 5,9:print"========================================"
[Fetch_Recs] if (a * recLen) > lof(#1) then goto [select] 'no more records GET #1,a [Fill_Roster] locate 8,b:print a if left$(Name$,1)=chr$(0) then locate 15,b:print "* Deleted record *" else locate 15,b:print Name$' locate 38,b:print IDnumber end if let a=a+1:let b=b+1 goto [Fetch_Recs]
[select] locate 5,b+1:print"========================================" locate 5,b+2:Print" TYPE ENT # TO VIEW DETAILS" locate 5,b+3:input" (Enter back to menu) ->:";ent if ent = 0 then return 'to menu if ent=0 or ent > a-1 then locate 36,b+2:print" ":goto [select] gosub [Fetch_Rec] 'show single rec goto [Draw_Form] 'back to roster
'------------------------------------ [drawRecHeader] locate 5,7:print"===========================================================" locate 5,8:print"| NAME: | ID #: |" locate 5,9:print"===========================================================" locate 5,11:print"==========================================================" locate 5,12:print"| ADDRESS: |" locate 5,13:print"==========================================================" locate 8,15:print" [ CONTACT INFO ]" locate 5,16:print"==========================================================" locate 5,17:print"| PHONE: EMAIL: |" locate 5,18:print"==========================================================" return
[setupFields] 'screen fields params h0,h,v,w 'h2 is for field header, w is width 'just put that printform in editor (CrlC CtrlV) and write positions 'but actual widths are in FIELD statement, != these DATA 6,14,8,32 DATA 47,54,8,9 DATA 6,17,12,45 DATA 6,15,17,15 DATA 30,38,17,24 nFields=5 dim h0(nFields), h(nFields), v(nFields), w(nFields) for i = 1 to nFields read x1,x2,x3,x4 h0(i)=x1: h(i)=x2: v(i)=x3: w(i)=x4 next return
[Fetch_Rec] Get #1, ent if left$(Name$,1)=chr$(0) then print "record ";ent;" is deleted" else gosub [showRecord] end if locate 7,21:input"Press 'Enter' to return to Roster -> ";rt$ return
[showRecord] cls locate 8,6:print"[ MEMBER LIST ]" gosub [drawRecHeader] i=1:locate h(i),v(i):print Name$ i=2:locate h(i),v(i):print IDnumber i=3:locate h(i),v(i):print Address$ i=4:locate h(i),v(i):print Phone$ i=5:locate h(i),v(i):print Email$ return
[Add_Record] 'calculate record number nRecords=lof(#1)/recLen ent=nRecords+1 cls locate 8,6:print"[ ADD NEW RECORD #";ent;"]" gosub [drawRecHeader] [Input] i=1:locate h(i),v(i):input"";Name$ i=2:locate h(i),v(i):input"";IDnumber i=3:locate h(i),v(i):input"";Address$ i=4:locate h(i),v(i):input"";Phone$ i=5:locate h(i),v(i):input"";Email$
[correct?] locate 8,19:print space$(50) locate 8,19:input"Are All Entries Correct ? <y/n> ";ec$ if lower$(ec$)="y" then [Save] if lower$(ec$)="n" then [Edit] goto [correct?]
[Edit] 'Place numbers next to each entry prompt for i=1 to 5 locate h0(i),v(i):print"[";i;"]" next i
[Sel_Edit_Field]' *Field # to Edit locate 8,19:input"Enter # next to entry you want to correct:";c if c=0 or c > nFields then [Sel_Edit_Field] locate h(c),v(c):print space$(w(c)) locate h(c),v(c) select case c case 1: input"";Name$ case 2: input"";IDnumber case 3: input"";Address$ case 4: input"";Phone$ case 5: input"";Email$ end select goto [correct?] [Save] PUT #1,ent locate 8,19:print space$(50) 'overwrite old line locate 8,20:print space$(50) 'overwrite old line locate 8,19:print"<<< Record Saved >>> " locate 8,20:input"Press 'Enter' for menu -> ";ret$ cls return
[ToggleDelete] nRecords=lof(#1)/recLen input "Which record (1..";nRecords;")?" ;delRecord if delRecord<1 or delRecord>nRecords then print "Wrong record number" return end if GET #1,delRecord if left$(Name$,1)=chr$(0) then Name$=mid$(Name$,2) else Name$=chr$(0)+Name$ PUT #1,delRecord if left$(Name$,1)=chr$(0) then print "record ";delRecord;" Deleted" else print "record ";delRecord;" Undeleted" end if return
[EditRecord] nRecords=lof(#1)/recLen input "Which record (1..";nRecords;")?" ;ent if ent<1 or ent>nRecords then print "Wrong record number" return end if GET #1,ent
if left$(Name$,1)=chr$(0) then print "record ";ent;" is deleted" else gosub [showRecord] gosub [Edit] 'now this one is CONVOLUTED!!! end if return
'-------------------------------- 'from the help file ' File Operations ' Testing for File Existence function fileExists(path$, filename$) dim info$(0, 0) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
|
Post by metro on Feb 3, 2024 17:58:45 GMT -5
Hope ya don't mind my 2c. I hate full screen mainwin, so just a tweak from me
'modification: let's consider recorts with names starting from Chr$(0) deleted. 'so this triggers delete/undelete: 'if left$(Name$,1)=chr$(0) then Name$=mid$(Name$,2) else Name$=chr$(0)+Name$
' --------------------------------- gosub [CentreMainwin] gosub [CreateIfNotExists] gosub [setupFields]
'--- main loop ------------------ [menu] print "--------------" print "1. View" print "2. Add new" print "3. Edit record" print "4. Toggle delete" print "0. Exit" [no_good] input act if act<0 or act >4 then [no_good]
select case act case 1 gosub [View] case 2 gosub [Add_Record] case 3 gosub [EditRecord] case 4 gosub [ToggleDelete] case 0 print "Bye then... mainwin closing down is two seconds" close #1 timer 2000, closeWin wait end select
GOTO [menu] '----------------------------
[CreateIfNotExists] 'does file exists at all? if fileExists(DefaultDir$, "members2.dat") = 0 then 'file not exists, so we went and write initial 3 records to it gosub [OpenFile] gosub [Set_Data] else 'opem file, leave it open gosub [OpenFile] end if return
[OpenFile] ' OPEN "members2.dat" FOR RANDOM AS #1 LEN= 76 ' Set LEN to 122 W/ Phone and Email / 76 W/o OPEN "members2.dat" FOR RANDOM AS #1 LEN= 122 recLen = 76 recLen = 122 'to be used for checking against LOF FIELD #1,_' set up the fields for file opened as #1 30 AS Name$,_ ' Name$ , string 40 AS Address$,_ ' Address$, string 6 AS IDnumber,_ ' IDnumber, numeric 16 AS Phone$,_ ' Phone #, String * - | Rem'ed out because of Errors 30 AS Email$ ' Email , String * - | return
[Set_Data]' *** CREATES RECORDS- on first time use *** for a=1 to 3 if a=1 then let Name$ = "Public, John, Q.": Address$ = "456 Maple Street, Anytown, USA":IDnumber = 9274:Phone$="(482)-160-8721":Email$="johnQP@Yahoo.com" if a=2 then let Name$ = "Jones, Alfred, R.":Address$ = "227 15th Av, New York New York, USA":IDnumber = 4365:Phone$="(218)-521-1276":Email$="AlfJones@Gamil.com" if a=3 then let Name$ = "Smith, Robert, T.":Address$ = "952 Bridge St, Burlington VT, USA":IDnumber = 1028:Phone$="(701)-882-7174":Email$="RobSmith@Aol.com" PUT #1,a next a print"Records Written" return
[View] 'JB wants some line between labels [Draw_Form] cls let a=1:let b=10 locate 8,6:print"[ MEMBER LIST ]" locate 5,7:print"========================================" locate 5,8:print"| ENT # | NAME: | ID #: |" locate 5,9:print"========================================"
[Fetch_Recs] if (a * recLen) > lof(#1) then goto [select] 'no more records GET #1,a
[Fill_Roster] locate 8,b:print a if left$(Name$,1)=chr$(0) then locate 15,b:print "* Deleted record *" else locate 15,b:print Name$' locate 38,b:print IDnumber end if let a=a+1:let b=b+1 goto [Fetch_Recs]
[select] locate 5,b+1:print"========================================" locate 5,b+2:Print" TYPE ENT # TO VIEW DETAILS" locate 5,b+3:input" (Enter back to menu) ->:";ent if ent = 0 then return 'to menu if ent=0 or ent > a-1 then locate 36,b+2:print" ":goto [select] gosub [Fetch_Rec] 'show single rec goto [Draw_Form] 'back to roster
'------------------------------------ [drawRecHeader] locate 5,7:print"===========================================================" locate 5,8:print"| NAME: | ID #: |" locate 5,9:print"===========================================================" locate 5,11:print"==========================================================" locate 5,12:print"| ADDRESS: |" locate 5,13:print"==========================================================" locate 8,15:print" [ CONTACT INFO ]" locate 5,16:print"==========================================================" locate 5,17:print"| PHONE: EMAIL: |" locate 5,18:print"==========================================================" return
[setupFields] 'screen fields params h0,h,v,w 'h2 is for field header, w is width 'just put that printform in editor (CrlC CtrlV) and write positions 'but actual widths are in FIELD statement, != these DATA 6,14,8,32 DATA 47,54,8,9 DATA 6,17,12,45 DATA 6,15,17,15 DATA 30,38,17,24 nFields=5 dim h0(nFields), h(nFields), v(nFields), w(nFields) for i = 1 to nFields read x1,x2,x3,x4 h0(i)=x1: h(i)=x2: v(i)=x3: w(i)=x4 next return
[Fetch_Rec] Get #1, ent if left$(Name$,1)=chr$(0) then print "record ";ent;" is deleted" else gosub [showRecord] end if locate 7,21:input"Press 'Enter' to return to Roster -> ";rt$ return
[showRecord] cls locate 8,6:print"[ MEMBER LIST ]" gosub [drawRecHeader]
i=1:locate h(i),v(i):print Name$ i=2:locate h(i),v(i):print IDnumber i=3:locate h(i),v(i):print Address$ i=4:locate h(i),v(i):print Phone$ i=5:locate h(i),v(i):print Email$ return
[Add_Record] 'calculate record number nRecords=lof(#1)/recLen ent=nRecords+1 cls locate 8,6:print"[ ADD NEW RECORD #";ent;"]" gosub [drawRecHeader]
[Input] i=1:locate h(i),v(i):input"";Name$ i=2:locate h(i),v(i):input"";IDnumber i=3:locate h(i),v(i):input"";Address$ i=4:locate h(i),v(i):input"";Phone$ i=5:locate h(i),v(i):input"";Email$
[correct?] locate 8,19:print space$(50) locate 8,19:input"Are All Entries Correct ? <y/n> ";ec$ if lower$(ec$)="y" then [Save] if lower$(ec$)="n" then [Edit] goto [correct?]
[Edit] 'Place numbers next to each entry prompt for i=1 to 5 locate h0(i),v(i):print"[";i;"]" next i
[Sel_Edit_Field]' *Field # to Edit locate 8,19:input"Enter # next to entry you want to correct:";c if c=0 or c > nFields then [Sel_Edit_Field] locate h(c),v(c):print space$(w(c)) locate h(c),v(c) select case c case 1: input"";Name$ case 2: input"";IDnumber case 3: input"";Address$ case 4: input"";Phone$ case 5: input"";Email$ end select goto [correct?]
[Save] PUT #1,ent locate 8,19:print space$(50) 'overwrite old line locate 8,20:print space$(50) 'overwrite old line locate 8,19:print"<<< Record Saved >>> " locate 8,20:input"Press 'Enter' for menu -> ";ret$ cls return
[ToggleDelete] nRecords=lof(#1)/recLen input "Which record (1..";nRecords;")?" ;delRecord if delRecord<1 or delRecord>nRecords then print "Wrong record number" return end if GET #1,delRecord if left$(Name$,1)=chr$(0) then Name$=mid$(Name$,2) else Name$=chr$(0)+Name$ PUT #1,delRecord if left$(Name$,1)=chr$(0) then print "record ";delRecord;" Deleted" else print "record ";delRecord;" Undeleted" end if return
[EditRecord] nRecords=lof(#1)/recLen input "Which record (1..";nRecords;")?" ;ent if ent<1 or ent>nRecords then print "Wrong record number" return end if GET #1,ent
if left$(Name$,1)=chr$(0) then print "record ";ent;" is deleted" else gosub [showRecord] gosub [Edit] 'now this one is CONVOLUTED!!! end if return
'-------------------------------- 'from the help file ' File Operations ' Testing for File Existence function fileExists(path$, filename$) dim info$(0, 0) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
[CentreMainwin] global hMainwin CallDLL #user32, "GetActiveWindow",_ hMainwin As uLong 'returns handle of MainWin w=600 : h = 600 x=(DisplayWidth-600)/2 : y=(DisplayHeight-600)/2 CallDLL #user32, "MoveWindow",_ hMainwin As uLong,_ 'handle x As Long,_ 'x location y As Long,_ 'y location w As Long,_ 'width h As Long,_ 'height 1 As Boolean,_ 'repaint, 1=true r As Boolean 'nonzero=success
CallDll #user32, "SetWindowTextA",_ hMainwin as ulong,_ "DARK KNIGHT'S CONTACTS!" as ptr,_ result as void
calldll #user32, "SetMenu",_ hMainwin as ulong,_ 'handle of nongraphics window 0 as ulong,_ '0 removes the MENU BAR results as ulong
RETURN
SUB closeWin 'h1 Calldll #user32, "DestroyWindow",_ hMainwin as uLong,_ result as boolean 'nonzero=success END END SUB
|
|
|
Post by DARKNIGHT on Feb 3, 2024 22:18:35 GMT -5
Thanks guys! I did create a menu after initially posting the code, but I like yours better! the edit option is awesome! I am checking out the different options and so far really liking what I see!
[UPDATE]
sorry man, But I found a couple of errors in your code, that I am not sure how to correct.
(1) when I finish entering a new record into the form, if I select "y" for "Are All Entries Correct ? <y/n> ";ec$ I get the perplexing Error:
"Runtime error:indexed collections are indexed by integers"
(2) on the select record # to edit/Del, I get (1-0.24897959)?
instead of (1 - x )? { x being the Tot # of Recs, displayed as a whole # }
thanks Man, I really appreciate your input, submitting your code , and patience
you guys Rock!
|
|
|
Post by DARKNIGHT on Feb 4, 2024 1:47:18 GMT -5
Metro, I don't mind any input at all. I am always open to suggestions my friend
|
|
|
Post by tsh73 on Feb 4, 2024 2:22:36 GMT -5
Jim, As to fractional record number. It is calculated in code just before as Lof(#1)/recLen RecLen is 122 It is always should be written in portions of 122 bytes, so rec len is always integer Check you file size. Check if recLen still 122.
If it prints 0.24... then file size is about 0.24*122, about 30 bytes. Look into file. Does it look anything like it should? (If you delete file, next run supposed to create file with 3 records, 122*3=366 bytes
EDIT
it calculates
nRecords=lof(#1)/recLen but prints 0.24897959
That supposed to mean that lof(#1) (file length) is recLen * 0.24897959 But print 0.24897959*122 is 30.37551 print 0.24897959*76 is 18.9224488 - both not integer, impossible
Look from another angle I know file created with 3 records, so length is 3*122 Then recLen should be lof(#1)/0.24897959 it produces 1470.00001 Check: nRecords=lof(#1)/recLen nRecords=(122*3)/1470 is 0.24897959
So it looks like your program somehow changed value of recLen to 1470.
|
|
|
Post by tsh73 on Feb 4, 2024 14:50:41 GMT -5
Hello metro, I really like ability to move/resize/close minwin but 1) mainwin will not be fullscreen until you asked for it. Usually it is around 80x25 to match old DOS window 2) somehow, Liberty starts misbehave after that program finished a) I did some search (Ctrl F, then some Ctrl G) It gave some error and closed b) (after restart, loading running program again) I did some search Got some error windows about callback ( ) Then in hang second time (had to kill) Trying the same with version without API call woks without a problem. So I suspect something is wrong with these API calls.
|
|
|
Post by metro on Feb 4, 2024 18:10:57 GMT -5
Hello metro, I really like ability to move/resize/close minwin but 1) mainwin will not be fullscreen until you asked for it. Usually it is around 80x25 to match old DOS window 2) somehow, Liberty starts misbehave after that program finished a) I did some search (Ctrl F, then some Ctrl G) It gave some error and closed b) (after restart, loading running program again) I did some search Got some error windows about callback ( ) Then in hang second time (had to kill) Trying the same with version without API call woks without a problem. So I suspect something is wrong with these API calls. G'Day Anatoly
Hmm, I'll take a closer look to see if I understand what's causing that. The code came from newsletters produced over the years which seems to have worked in the past without consequences . No issues for me, BUT.... my OS in Linux/wine and maybe that's why I always only got fullscreen
thanks for the heads-up
|
|