|
Post by donnybowers on Feb 14, 2022 23:16:46 GMT
This will calculate the number of years between a BC date and an AD date.
WindowWidth=345 WindowHeight=200 UpperLeftX=1 UpperLeftY=1 nomainwin
statictext #main.st1, "Year BC",10,10,80,30 textbox #main.bc, 100,10,70,30 statictext #main.st2, "Year AD",10,50,80,30 textbox #main.ad, 100,50,70,30 statictext #main.st3, "# Years",10,90,80,30 textbox #main.years, 100,90,70,30 button #main.default, "Calculate", [calculate], UL, 10,130,100,30 button #main.clear, "Clear", [clear], UL, 120,130,100,30 button #main.cancel, "Cancel", [quit], UL, 230,130,100,30
open "BC/AD Years Calculator" for dialog as #main #main, "trapclose [quit]" #main.st1, "!font size 16" #main.bc, "!font size 16" #main.st2, "!font size 16" #main.ad, "!font size 16" #main.st3, "!font size 16" #main.years, "!font size 16" #main.default, "!font size 12" #main.clear, "!font size 12" #main.cancel, "!font size 12" #main.bc, "!setfocus" wait
[calculate] #main.bc, "!contents? bc$"; #main.ad, "!contents? ad$"; #main.years, "!contents? years$"; bc=val(bc$) ad=val(ad$) years=val(years$) ' notice bc$;" - ";ad$;" - ";years$ : end if bc$="" and ad$="" then notice "Not enough data" : wait if bc$="" and years$="" then notice "Not enough data" : wait if ad$="" and years$="" then notice "Not enough data" : wait
if bc$<>"" and ad$<>"" then years=ad-(0-bc)-1 print #main.years, str$(years) end if if bc$<>"" and years$<>"" then ad=(0-bc)+years+1 print #main.ad, str$(ad) end if
if ad$<>"" and years$<>"" then bc=ad-years-1 bc=bc-bc-bc print #main.bc, str$(bc) wait end if wait
[clear] #main.bc, "" #main.ad, "" #main.years, "" #main.bc, "!setfocus" wait [quit] close #main END
|
|
|
Post by jarych on Jun 30, 2022 19:09:23 GMT
Your idea is excellent. I did not try running your program but obviously it is a fine exercise in making a Windows program to do a simple task using user-input. This appears to handle user input mistakes, too. EVERY beginner programmer at Just BASIC and Liberty BASIC should examine your sample program.
|
|
|
Post by honkytonk on Jul 5, 2022 13:25:26 GMT
My contribution for number of day
NOMAINWIN mapw=350: maph= 300 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 mois$ = "Janvier Février Mars Avril Mai Juin Juillet Aout Septempbre Octobre Novembre Décenbre" today$ = date$("mm/dd/yyyy") j = date$(today$) jsem$ = word$("Mar Mer Jeu x Ven Sam x Dim Lun",int((j/7-int(j/7))*10)+1) date$ = jsem$+" "+mid$(today$,4,2)+" "+word$(mois$, val(today$))+" "+left$(time$(),5)'right$(today$,4) BUTTON #w.conv, "/", [conv], UL, 20, 35, 25, 25 TEXTBOX #w.deb, 20 , 70, 150, 30 TEXTBOX #w.fin, 190 , 70, 150, 30 BUTTON #w.c, "C", [c], UL, 310, 35, 25, 25 BUTTON #w.valdeb, "Validate", [valdeb], UL, 45, 110, 100, 25 BUTTON #w.valfin, "Validate", [valfin], UL, 210, 110, 100, 25 BUTTON #w.calc, "Compute", [calc], UL, 125, 150, 100, 25 TEXTBOX #w.resu, 90 , 190, 170, 30 TEXTBOX #w.dat, 80 , 250, 250, 25 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Jours de date à date" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.deb, "!font courrier 14 bold": #w.fin, "!font courrier 14 bold": #w.resu, "!font courrier 14 bold" #w.valdeb, "!font courrier 12 bold": #w.valfin, "!font courrier 12 bold" #w.dat, "!font courrier 12 bold": #w.calc, "!font courrier 12 bold" #w.g, "down;fill darkpink;color white;backcolor darkpink" #w.g, "font courrier 12 bold" #w.g, "place 70 20": #w.g, "\Start": #w.g, "place 240 20": #w.g, "\End" #w.g, "place 110 50": #w.g, "\Month / Day / Year" : #w.g, "place 10 260": #w.g, "\To day:" #w.deb, "1/1/1901": #w.fin, "1/1/1901" #w.g, "flush" d$ = date$( ): dd$=right$(d$,4) date$= jsem$+" "+mid$(today$,4,2)+" "+word$(mois$, val(today$))+" "+dd$+" "+left$(time$(),5)'******** #w.dat, date$ #w.calc, "!disable" c=1 wait [conv] c=c+1: if c=3 then c=1 if c=1 then conv=0 if c=2 then conv=1 if conv=0 then #w.g, "color darkpink;backcolor darkpink" #w.g, "place 105 30": #w.g, "boxfilled 270 55" #w.g, "color white;backcolor darkpink" #w.g, "place 110 50": #w.g, "\Month / Day / Year" end if if conv=1 then #w.g, "color darkpink;backcolor darkpink" #w.g, "place 105 30": #w.g, "boxfilled 270 55" #w.g, "color white;backcolor darkpink" #w.g, "place 110 50": #w.g, "\Day / Month / Year" end if #w.conv, word$("/ \",c) wait [c] #w.resu, "" wait [valdeb] #w.deb, "!contents? deb$": deb=val(deb$): #w.dat, "!contents? date$" jdeb=date$(deb$): d=1 if conv=1 then jo$="": mo$="": d$="" an$=right$(deb$,4) for x=1 to 3 jo$=jo$+mid$(deb$,x,1) if mid$(deb$,x,1)="/" then s1=x: exit for next x for x=s1+1 to s1+3 mo$=mo$+mid$(deb$,x,1) if mid$(deb$,x,1)="/" then exit for next x d$=mo$+jo$+an$ jdeb=date$(d$): d=1 end if if d=1 and f=1 then #w.calc, "!enable" wait [valfin] #w.fin, "!contents? fin$": fin=val(fin$): #w.dat, "!contents? date$" jfin=date$(fin$): f=1 if conv=1 then jo$="": mo$="": f$="" an$=right$(fin$,4) for x=1 to 3 jo$=jo$+mid$(fin$,x,1) if mid$(fin$,x,1)="/" then s1=x: exit for next x for x=s1+1 to s1+3 mo$=mo$+mid$(fin$,x,1) if mid$(fin$,x,1)="/" then exit for next x f$=mo$+jo$+an$ jfin=date$(f$): f=1 end if if d=1 and f=1 then #w.calc, "!enable" wait [calc] #w.resu, str$(jfin-jdeb);" Days": d=0: f=0 wait [closeHelp] CLOSE #w END
|
|
|
Post by jarych on Jul 5, 2022 17:08:10 GMT
honkytonk, program interface looks nice; but when I put in start and last date to cover about 4 years, program gave a result of about 44000 days. I did not look in detail at your sample code, but four years span should be approximately 1460 days, or very close to this.
|
|
|
Post by honkytonk on Jul 6, 2022 7:08:54 GMT
You must have made a bad manipulation (forgotten validation) Because for 4 years the soft give 1461 days for me, for both formats.
|
|
|
Post by honkytonk on Jul 6, 2022 8:18:49 GMT
Now, with this code, manipulation errors are no longer possible
NOMAINWIN mapw=350: maph= 350 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 mois$ = "Janvier Février Mars Avril Mai Juin Juillet Aout Septempbre Octobre Novembre Décenbre" today$ = date$("mm/dd/yyyy") j = date$(today$) jsem$ = word$("Mar Mer Jeu x Ven Sam x Dim Lun",int((j/7-int(j/7))*10)+1) date$ = jsem$+" "+mid$(today$,4,2)+" "+word$(mois$, val(today$))+" "+left$(time$(),5)'right$(today$,4) BUTTON #w.conv, "/", [conv], UL, 20, 35, 25, 25 TEXTBOX #w.deb, 20 , 70, 150, 30 TEXTBOX #w.fin, 190 , 70, 150, 30 BUTTON #w.c, "New", [c], UL, 290, 35, 50, 25 BUTTON #w.valdeb, "Validate", [valdeb], UL, 45, 110, 100, 25 BUTTON #w.valfin, "Validate", [valfin], UL, 210, 110, 100, 25 BUTTON #w.calc, "Compute", [calc], UL, 125, 150, 100, 25 TEXTBOX #w.resu, 90 , 190, 170, 30 TEXTBOX #w.dat, 80 , 250, 250, 25 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Jours de date à date" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.deb, "!font courrier 14 bold": #w.fin, "!font courrier 14 bold": #w.resu, "!font courrier 14 bold" #w.valdeb, "!font courrier 12 bold": #w.valfin, "!font courrier 12 bold" #w.dat, "!font courrier 12 bold": #w.calc, "!font courrier 12 bold": #w.c, "!font courrier 12 bold" #w.g, "down;fill darkpink;color white;backcolor darkpink" #w.g, "font courrier 12 bold" #w.g, "place 70 20": #w.g, "\Start": #w.g, "place 240 20": #w.g, "\End" #w.g, "place 110 50": #w.g, "\Month / Day / Year" : #w.g, "place 10 260": #w.g, "\To day:" #w.deb, "1/1/1901": #w.fin, "1/1/1901": #w.c, "!disable" #w.g, "flush" d$ = date$( ): dd$=right$(d$,4) date$= jsem$+" "+mid$(today$,4,2)+" "+word$(mois$, val(today$))+" "+dd$+" "+left$(time$(),5)'******** #w.dat, date$ #w.calc, "!disable" c=1 wait [conv] c=c+1: if c=3 then c=1 if c=1 then conv=0 if c=2 then conv=1 if conv=0 then #w.g, "color darkpink;backcolor darkpink" #w.g, "place 105 30": #w.g, "boxfilled 270 55" #w.g, "color white;backcolor darkpink" #w.g, "place 110 50": #w.g, "\Month / Day / Year" end if if conv=1 then #w.g, "color darkpink;backcolor darkpink" #w.g, "place 105 30": #w.g, "boxfilled 270 55" #w.g, "color white;backcolor darkpink" #w.g, "place 110 50": #w.g, "\Day / Month / Year" end if #w.conv, word$("/ \",c) wait [c] #w.resu, "": #w.deb, "!enable": #w.fin, "!enable" #w.valdeb, "!enable": #w.valfin, "!enable": #w.calc, "!disable" wait [valdeb] #w.deb, "!contents? deb$": deb=val(deb$): #w.dat, "!contents? date$" jdeb=date$(deb$): d=1 if conv=1 then jo$="": mo$="": d$="" an$=right$(deb$,4) for x=1 to 3 jo$=jo$+mid$(deb$,x,1) if mid$(deb$,x,1)="/" then s1=x: exit for next x for x=s1+1 to s1+3 mo$=mo$+mid$(deb$,x,1) if mid$(deb$,x,1)="/" then exit for next x d$=mo$+jo$+an$ jdeb=date$(d$): d=1 end if if d=1 and f=1 then #w.calc, "!enable" wait [valfin] #w.fin, "!contents? fin$": fin=val(fin$): #w.dat, "!contents? date$" jfin=date$(fin$): f=1 if conv=1 then jo$="": mo$="": f$="" an$=right$(fin$,4) for x=1 to 3 jo$=jo$+mid$(fin$,x,1) if mid$(fin$,x,1)="/" then s1=x: exit for next x for x=s1+1 to s1+3 mo$=mo$+mid$(fin$,x,1) if mid$(fin$,x,1)="/" then exit for next x f$=mo$+jo$+an$ jfin=date$(f$): f=1 end if if d=1 and f=1 then #w.calc, "!enable" wait [calc] #w.g, "color darkpink;backcolor darkpink" #w.g, "place 10 280": #w.g, "box 200 320" #w.resu, str$(jfin-jdeb);" Days": d=0: f=0 #w.deb, "!disable": #w.fin, "!disable" #w.valdeb, "!disable": #w.valfin, "!disable" #w.g, "color white;backcolor darkpink" #w.g, "place 20 300": #w.g, "\ ";deb$;" ";fin$ #w.c, "!enable" wait [closeHelp] CLOSE #w END
|
|