rocca
New Member
Posts: 6
|
Post by rocca on Mar 9, 2021 9:49:12 GMT
I have a question.
This program represents a meter reading and energy consumption per month,
I would have liked the data to be saved per month with the option
consumption every other year, so a total of 12 months of consumption.
I would like some help and suggestions on how to work this out
nomainwin WindowWidth = 592 : WindowHeight = 380 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) BackgroundColor$ = "lightgray" ForegroundColor$ = "blue" TextboxColor$ = "white"
statictext #main,"Meterstand Maand Nacht",20, 39, 150, 20 statictext #main,"Deze maand", 226, 1, 95, 20 textbox #main.textbox1, 226, 26, 65, 30 statictext #main.st1 "-", 320,29,20,30 statictext #main,"Vorige maand",340, 1, 95,20 textbox #main.textbox2, 342, 26, 65, 30 statictext #main.st2 "=", 440,29,20,30 statictext #main,"verbruik /maand", 460, 1, 100, 20 textbox #main.textbox3, 462, 26, 65, 30 statictext #main,"Meterstand Maand Dag", 20, 75, 150, 20 textbox #main.textbox4, 226, 73, 65, 30 statictext #main.st3, "-", 320, 76, 20, 30 textbox #main.textbox5, 342, 73, 65, 30 statictext #main.st4,"=", 440, 76, 20, 30 textbox #main.textbox6, 462, 73, 65, 30 statictext #main,"Meterstand Gas", 20, 126, 160, 20 textbox #main.textbox7, 226, 123, 65, 30 statictext #main.st5, "-", 320, 126, 20, 20 textbox #main.textbox8,342, 123, 65, 30 statictext #main.st6,"=",440, 126, 20, 20 textbox #main.textbox9,462, 123, 65, 30 statictext #main.st7, "Vandaag : ";date$(), 20, 1, 200, 20 button #main.button4, "&Stop", [buttonClick], UL, 235, 311, 122, 25 button #main.button5, "&Open", [openfile], UL, 20, 311, 122, 25 button #main.button6, "&bewaar", [save], UL, 440, 311, 122, 25 ' button #main.button7, "Print", [print], UL, 310, 311, 122, 25 open "METERSTAND PER MAAND " for window as #main
print d$," " print #main, "trapclose [quit.main]" print #main, "font Arial 10"
#main.st7, "!font times_new_roman 10 bold" #main.textbox1 " " #main.textbox2 " " #main.textbox4 " " #main.textbox5 " " #main.textbox7 " " #main.textbox8 " "
[reDo] timer 0 #main.textbox1 "!contents? a$" #main.textbox2 "!contents? b$" #main.textbox3 val(a$)-val(b$);nv$ #main.textbox4 "!contents? c$" #main.textbox5 "!contents? d$" #main.textbox6 val(c$)-val(d$);dv$ #main.textbox7 "!contents? e$" #main.textbox8 "!contents? f$" #main.textbox9 val(e$)-val(f$);gv$ timer 150, [reDo]
wait
[save]
if file$="" then filedialog "BEWAAR METERSTAND",currentdir$+".dat",file$ if file$="" then wait end if #main.textbox1 "!contents? a$" #main.textbox2 "!contents? b$" #main.textbox3 "!contents? nv$" #main.textbox4 "!contents? c$" #main.textbox5 "!contents? d$" #main.textbox6 "!contents? dv$" #main.textbox7 "!contents? e$" #main.textbox8 "!contents? f$" #main.textbox9 "!contents? gv$" open file$;".dat" for output as #f ' print #f, content$ close #f let currentdir$=file$ 'print #main, "!setfocus"
wait
[openfile]
filedialog "OPEN METERSTAND",currentdir$+".dat",file$ if file$="" then wait '#main "!cls" open file$ for input as #f #main.textbox1 "!contents? a$" #main.textbox2 "!contents? b$" #main.textbox3 "!contents? nv$" #main.textbox4 "!contents? c$" #main.textbox5 "!contents? d$" #main.textbox6 "!contents? dv$" #main.textbox7 "!contents? e$" #main.textbox8 "!contents? f$" #main.textbox9 "!contents? gv$" close #f let currentdir$=file$ '#main "!setfocus"
wait
[quit.main] Close #main END
[buttonClick] close #main : end
|
|
|
Post by tsh73 on Mar 9, 2021 11:21:19 GMT
Hello as for now, program does not save anything at all
I suggest starting from deciding/inventing data save format Basically we have 3 meter value per month we could save month, in some format, like say 2021_03 for March 2021 and three numbers (Night Day Gas) and we should be able to read it back (probably add buttons to move "current" month back and forth, to be able to see data from say Jan 2021)
Consumption could be calculated like (this month - previous month) values If you have an array a() and (i) corresponds to current month, then this month consumption would be (a(i)-a(i-1)) and year (from this month) consumption would be (a(i)-a(i-12)).
EDIT just to say, Google translate do wonders with text in code in unknown languages.
|
|
|
Post by Rod on Mar 9, 2021 14:05:08 GMT
Dont use the timer, get rid of that. The user will fill in the boxes then click a button. When that button is clicked is the time to go and read the input, do the calculations, show them and save it all to a file.
I would open the file at the start and show the last readings. Then textboxes to get the new readings, textboxes to calculate how much has been used and the cost?
You can open the file automatically at the start, you can save the file automatically at the end. So you just need a Submit button.
You will need to decide how to store the data. Just use a comma delimited string. perhaps
accountno,yyyymmdd,read1,read2,gas,etc,etc
|
|
rocca
New Member
Posts: 6
|
Post by rocca on Mar 10, 2021 7:27:45 GMT
thanks for the help I now have some code to edit to finish this regards
|
|
|
Post by xxgeek on Mar 11, 2021 21:45:53 GMT
Just for kicks, here's the english version editted a little to show the text before it gets overlapped by buttons.
nomainwin WindowWidth = 800 : WindowHeight = 320 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) BackgroundColor$ = "lightgray" ForegroundColor$ = "black " TextboxColor$ = "white"
statictext #main,"Meter Reading Month Night", 15, 85, 225, 20 statictext #main,"This Month", 300, 51, 120, 20 textbox #main.textbox1, 270, 76, 150, 30 statictext #main.st1 "-", 427, 81, 20, 30 statictext #main,"Last Month", 475, 51, 150, 20 textbox #main.textbox2, 440, 76, 150, 30 statictext #main.st2 "=", 601, 83, 20, 30 statictext #main,"Consumed / Month", 620, 51, 150, 20 textbox #main.textbox3, 620, 76, 150, 30 statictext #main,"Meter Reading Month Day", 15, 127, 200, 20 textbox #main.textbox4, 270, 120, 150, 30 statictext #main.st3, "-", 427, 126, 20, 30 textbox #main.textbox5, 440, 120, 150, 30 statictext #main.st4,"=", 601, 126, 20, 30 textbox #main.textbox6, 620, 120, 150, 30 statictext #main,"Meter Reading Gas", 15, 173, 160, 20 textbox #main.textbox7, 270, 165, 150, 30 statictext #main.st5, "-", 427, 167, 20, 20 textbox #main.textbox8, 440, 165, 150, 30 statictext #main.st6,"=", 601, 167, 20, 20 textbox #main.textbox9, 620, 165, 150, 30 statictext #main.st7, "Today : ";date$(), 325, 11, 200, 20 button #main.button4, "&Stop", [buttonClick], UL, 60, 225, 85, 40 button #main.button5, "&Open", [openfile], UL, 310, 210, 75, 25 button #main.button6, "&Save", [save], UL, 480, 210, 75, 25 button #main.button7, "Print", [print], UL, 660, 210, 75, 25 open "Meter reading Per Month " for dialog_nf as #main
print d$," " print #main, "trapclose [quit.main]" print #main, "font Arial 12 bold"
#main.st7, "!font Arial 12 bold" #main.textbox1 " " #main.textbox2 " " #main.textbox4 " " #main.textbox5 " " #main.textbox7 " " #main.textbox8 " " [reDo] timer 0 #main.textbox1 "!contents? a$" #main.textbox2 "!contents? b$" #main.textbox3 val(a$)-val(b$);nv$ #main.textbox4 "!contents? c$" #main.textbox5 "!contents? d$" #main.textbox6 val(c$)-val(d$);dv$ #main.textbox7 "!contents? e$" #main.textbox8 "!contents? f$" #main.textbox9 val(e$)-val(f$);gv$ timer 150, [reDo] wait
[save] if file$="" then filedialog "Save Meter Standard",currentdir$ + ".dat",file$ if file$ = "" then wait end if #main.textbox1 "!contents? a$" #main.textbox2 "!contents? b$" #main.textbox3 "!contents? nv$" #main.textbox4 "!contents? c$" #main.textbox5 "!contents? d$" #main.textbox6 "!contents? dv$" #main.textbox7 "!contents? e$" #main.textbox8 "!contents? f$" #main.textbox9 "!contents? gv$"
open file$;".dat" for output as #f print #f, content$ close #f currentdir$=file$ print #main, "!setfocus" wait [openfile] filedialog "Open Meter Standard",currentdir$+".dat",file$ if file$="" then wait '#main "!cls" open file$ for input as #f #main.textbox1 "!contents? a$" #main.textbox2 "!contents? b$" #main.textbox3 "!contents? nv$" #main.textbox4 "!contents? c$" #main.textbox5 "!contents? d$" #main.textbox6 "!contents? dv$" #main.textbox7 "!contents? e$" #main.textbox8 "!contents? f$" #main.textbox9 "!contents? gv$" close #f currentdir$=file$ wait
[quit.main] Close #main END [buttonClick] close #main : end
|
|
rocca
New Member
Posts: 6
|
Post by rocca on Mar 12, 2021 7:55:41 GMT
Beautiful xxgeek but I can't get that timer out if you would like a solution
|
|
|
Post by Rod on Mar 12, 2021 9:46:04 GMT
Ok, I changed a few things and got rid of the timer. First off I used meaningful names for the controls and the variables. That way it is a LOT easier to match up variables to controls and formula. Second I added a hidden enter button. You are supposed to use TAB to move from textbox to textbox but few users know that. So the hidden enter button helps. Now the user can fill out the boxes in any order and when the form is complete they can press SUBMIT to complete the form. I also automated the file handling. It is a simple file for now but can easily be improved.
The code at the top creates the file first time in. Delete that part if you want to see the program remember what you keyed in.
open "reading.dat" for output as #r #r "155,15,1300" close #r
nomainwin WindowWidth = 800 : WindowHeight = 320 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) BackgroundColor$ = "lightgray" ForegroundColor$ = "black " TextboxColor$ = "white"
statictext #main,"Meter Reading Month Night", 15, 85, 225, 20 statictext #main,"This Month", 300, 51, 120, 20 textbox #main.newnight, 270, 76, 150, 30 statictext #main.st1 "-", 427, 81, 20, 30 statictext #main,"Last Month", 475, 51, 150, 20 textbox #main.oldnight, 440, 76, 150, 30 statictext #main.st2 "=", 601, 83, 20, 30 statictext #main,"Consumed / Month", 620, 51, 150, 20 textbox #main.connight, 620, 76, 150, 30 statictext #main,"Meter Reading Month Day", 15, 127, 200, 20 textbox #main.newday, 270, 120, 150, 30 statictext #main.st3, "-", 427, 126, 20, 30 textbox #main.oldday, 440, 120, 150, 30 statictext #main.st4,"=", 601, 126, 20, 30 textbox #main.conday, 620, 120, 150, 30 statictext #main,"Meter Reading Gas", 15, 173, 160, 20 textbox #main.newgas, 270, 165, 150, 30 statictext #main.st5, "-", 427, 167, 20, 20 textbox #main.oldgas, 440, 165, 150, 30 statictext #main.st6,"=", 601, 167, 20, 20 textbox #main.congas, 620, 165, 150, 30 statictext #main.st7, "Today : ";date$(), 325, 11, 200, 20 button #main.button4, "SUBMIT", [submit], UL, 270, 225, 500, 40 button #main.default, "Hidden Enter",[enter],UL,-100,-100,0,0 open "Meter reading Per Month " for dialog_nf as #main
#main "trapclose [quit.main]" #main "font Arial 12 bold" #main.st7 "!font Arial 12 bold" gosub [openfile] wait
[enter] #main.newnight "!contents? newnight$" if newnight$<>"" then #main.connight val(newnight$)-val(oldnight$) #main.newday "!contents? newday$" if newday$<>"" then #main.conday val(newday$)-val(oldday$) #main.newgas "!contents? newgas$" if newgas$<>"" then #main.congas val(newgas$)-val(oldgas$) wait
[submit] #main.newnight "!contents? newnight$" if newnight$<>"" then #main.connight val(newnight$)-val(oldnight$) #main.newday "!contents? newday$" if newday$<>"" then #main.conday val(newday$)-val(oldday$) #main.newgas "!contents? newgas$" if newgas$<>"" then #main.congas val(newgas$)-val(oldgas$) if newnight$<>"" and newday$<>"" and newgas$<>"" then open "reading.dat" for output as #r #r newnight$;",";newday$;",";newgas$ close #r else notice "Enter all readings!" end if wait
[openfile] open "reading.dat" for input as #r inputcsv #r,oldday$,oldnight$,oldgas$ #main.oldnight oldnight$ #main.oldday oldday$ #main.oldgas oldgas$ #main.newnight "" #main.newday "" #main.newgas "" #main.connight "0" #main.conday "0" #main.congas "0" close #r newnight$="" newday$="" newgas$="" #main.newnight "!setfocus" return
[quit.main] Close #main END
|
|
|
Post by xxgeek on Mar 12, 2021 17:51:00 GMT
inputcsv #r, oldday$, oldnight$, oldgas$ Syntax error in this line Rod, program won't start. Is inputcsv supposed to be a string?
EDIT -
I editted it to open "reading.dat" for output as #r #r, oldday$;"," ;oldnight$;","; oldgas$
Seems to work now, but may not be working as planned. I have no idea.
Plus I changed the font size on my end to 8 because the text started overlapping buttons.That problem of text size is most likely because I'm in WINE and fonts are limited.
|
|
|
Post by Rod on Mar 12, 2021 18:08:48 GMT
Ahh good spot, inputcsv is Liberty BASIC. I will code a fix when I get a bit of time. Probably input the entire file and parse with word$
|
|
|
Post by xxgeek on Mar 12, 2021 18:17:51 GMT
ok, I guess what I wrote won't work. The math is no longer being done in the form.
Once I got it to run I got an error "trying to writie to file open for input" and thought changing to "output" would help, but no.
I see you're on it, so have at it .
|
|
|
Post by Rod on Mar 12, 2021 19:28:42 GMT
Ok my mistake, this is alternative to inputcsv
[openfile] open "reading.dat" for input as #r r$=input$(#r,lof(#r)) oldday$=word$(r$,1,",") oldnight$=word$(r$,2,",") oldgas$=word$(r$,3,",") #main.oldnight oldnight$ #main.oldday oldday$ #main.oldgas oldgas$ #main.newnight "" #main.newday "" #main.newgas "" #main.connight "0" #main.conday "0" #main.congas "0" close #r newnight$="" newday$="" newgas$="" #main.newnight "!setfocus" return
Yes it makes a difference how you open the file.
|
|
|
Post by xxgeek on Mar 12, 2021 21:21:16 GMT
Working fine now, and writes a file to the same folder as the .bas file is started from.
Not knowing what this actually is for, I'm thinking maybe the file should be "append" ed instead of "input" ed?
I guess only rocca knows that fore sure.
|
|
rocca
New Member
Posts: 6
|
Post by rocca on Mar 13, 2021 15:48:19 GMT
This does not work like the launcher, The intention is to to obtain an overview of the consumption of energy, electricity and gas. To be compared per month see appendix, it is ultimately intended that there will be a possibility to get a total, from the use to recover from the use, which can then be printed
consumed / month here NOW comes the same values as in this Month and that is not correct, here should be the difference of this Month_ last Month
|
|
|
Post by xxgeek on Mar 13, 2021 23:54:08 GMT
rocca - I'm having a hard time understanding "exactly" what you need.
If I understand you correctly this is what you're trying to do.
1. First run, - log date (Month Day Year) along with all the values you add from each meter to a dat file.
2. Second run - call up the log from dat file for previous month [do the math] log the values, along with date to the dat file with out overwriting the dat file (possibly a new dat file with a different name or just "append" the one dat file?.
3.Reapeat 2 every month.
4. Keep logs/dat file/files for month after month and year after year?
5. Also an option to print to "real paper" when desired or just print to say "Notepad" to have a look at the entire logged data?
Am I understanding you? btw - Do you program? Are you familiar with JB code at all?
|
|
rocca
New Member
Posts: 6
|
Post by rocca on Mar 14, 2021 7:54:58 GMT
basically it is a file of the meter readings every month. At the end of the year, a total of the consumption per meter. With jb I am not very confident but I try to get into it, without help it is not easy
|
|