|
Post by Rod on Mar 14, 2021 12:42:43 GMT
Post the example file you are working with and keep posting your code so we can see how you are getting on.
|
|
|
Post by xxgeek on Mar 15, 2021 5:55:36 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 It just so happens that I needed to learn how to work with the same type of data saving and retreaving thing for a project I have been working on. And you were right. "it's hard without help" So I took my time and learned a lot as I figured some things out. Your code had me confused for a number of reasons, not to mention it started out with what I believe is German? Sorry about the english, but I can't work in any other language other than code. I added to your original code to give more info, and left a few things for you to add if you desire. I hope it is what you were looking for. Some things to know. 1. It creates a file in the same folder the .bas file running it is located. That file is named - meter.dat meter.dat holds the values your program was saving. It is written over on each use of this program, but before it is, the values are added to the "Last Month" textbox when run the second, third etc time. 1st run, there are no values for Last Month, you must provide those. 2. I also added another file to the same folder called totals.txt' This file holds the above values, as well as some more, and can be added to as you'll see in the code. This mfile never gets written over, it gets appended, just so you have nom worries about losing the data by mistake. 3. I added a button [Show Log] this will show the totals.txt file is notepad, and can be printed from there if desired. you can edit the code and add or remove from what is recorded. I think the code is plain enough. 4. print button doesn't do anything. I left it there for you to work it out. 5. I don't show the open button, but left the code in case you want it. You don't need it, as the code opens the file meter.dat as soon as it is RUN , reads it and adds the "Last Month" to the textboxes when Run but before any "Save" is done. That's why I took that button out, so there would be no strange lines going to meter.dat by mistake. Your choice if you want it back, just uncomment the code that uses it. Just the button to worry about, the "Open File" code is all there and not commented out. Good luck to you rocca. Hope to see you around the forums. Don't give up on just basic, it really does get easier. One more thing for you to do. Since I do most of my work on a Linux box, and just hate dealing with Windows crap getting in my way, and don't wish to reboot into Windows right now you may need to set the font size bigger or smaller in the code. The code 'file posted by rocca at https://justbasiccom.proboards.com/thread/655/help-program 'editted by xxgeek March 14 2021 [begin] nomainwin WindowWidth = 800 : WindowHeight = 300 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) BackgroundColor$ = "lightgray" ForegroundColor$ = "black " TextboxColor$ = "white"
statictext #main,"Meter Reading Month Night", 15, 75, 225, 20 statictext #main,"This Month", 300, 41, 120, 20 textbox #main.textbox1, 270, 71, 150, 20 statictext #main.st1 "-", 427, 73, 20, 30 statictext #main,"Last Month", 475, 46, 150, 20 textbox #main.textbox2, 440, 71, 150, 20 statictext #main.st2 "=", 601, 77, 20, 20 statictext #main,"Consumed / Month", 620, 46, 150, 20 textbox #main.textbox3, 620, 71, 150, 20 statictext #main,"Meter Reading Month Day", 15, 119, 200, 20 textbox #main.textbox4, 270, 115, 150, 20 statictext #main.st3, "-", 428, 116, 20, 30 textbox #main.textbox5, 440, 115, 150, 20 statictext #main.st4,"=", 601, 121, 20, 30 textbox #main.textbox6, 620, 115, 150, 20 statictext #main,"Meter Reading Gas", 15, 163, 160, 20 textbox #main.textbox7, 270, 160, 150, 20 statictext #main.st5, "-", 428, 162, 20, 20 textbox #main.textbox8, 440, 160, 150, 20 statictext #main.st6,"=", 601, 162, 20, 20 textbox #main.textbox9, 620, 162, 150, 20 statictext #main.st7, "Today : ";date$(), 325, 11, 200, 20
button #main.reset, "Open", [openfile], UL, 150, 220, 85, 35 button #main.fulllog, "Show Log", [fulllog], UL, 40, 220, 95, 35 button #main.button4, "&Close", [buttonClick], UL, 700, 220, 85, 35 button #main.button6, "&Save", [save], UL, 450, 220, 85, 35 button #main.button7, "Print", [print], UL, 575, 220, 85, 35
open "Meter Readings Per Month " for dialog_nf as #main print #main, "trapclose [quit.main]" print #main, "font Arial 8 bold" 'showing that you don't need "print" to print to a handle. It is assumed. #main.st7, "!font Arial 8 bold" 'not sure if the following lines are needed, left them for you to test #main.textbox1 " " #main.textbox2 " " #main.textbox4 " " #main.textbox5 " " #main.textbox7 " " #main.textbox8 " "
'making a dummy file for first Run file$ = DefaultDir$;"\meter.dat" open file$ for append as #1stRunDummy print #1stRunDummy, "" close #1stRunDummy 'reading meter.dat line by line to get stats for the "Last Month" current texboxes - before a '"Save" is done [getdata] open file$ for input as #f x = 0 do x = x + 1 line input #f, item$ if x = 1 then b$ =word$(item$, 7) #main.textbox2, b$ if x = 2 then d$ = word$(item$, 7) #main.textbox5, d$ if x = 3 then f$ = word$(item$, 7) #main.textbox8, f$ loop until eof(#f) <> 0 close #f
#main.textbox2, b$ #main.textbox5, d$ #main.textbox8, f$
[reDo] #main.textbox1 "!contents? a$" #main.textbox2 "!contents? b$" #main.textbox3 val(a$)-val(b$);nv$ #main.textbox3 "!contents? nv" #main.textbox4 "!contents? c$" #main.textbox5 "!contents? d$" #main.textbox6 val(c$)-val(d$);dv$ #main.textbox6 "!contents? dv" #main.textbox7 "!contents? e$" #main.textbox8 "!contents? f$" #main.textbox9 val(e$)-val(f$);gv$ #main.textbox9 "!contents? gv" scan goto [reDo] wait 'saving the stats, but first, gettting the "Last Month" data for textboxes 'before a "Save is made" [save] 'extras - ' add night plus day reading for total electric consumption of current month. 'this one is working, and logging to totals.txt monthTotElec = nv + dv
'These I leave to you wether or not you want to add them. I have already added them ' below to be saved to "fulllog" - totals.txt ' but as they are now the values will come out as 0 in the "fulllog"
'TotalNE2Date = (Total Electric Night Consumption to Date)'add last total night consumption to this month(get from 'meter.dat last month variables) need code to read meter.dat to get values before this months 'stats are saved.
'TotalDE2Date = 'Total Electric Day Consumption to Date) (add last month total day consumption to this month(get meter.dat) 'need code here to read meter.dat to get values before this months stats are saved.
'TotalE2Date = '(Total Electric Consumption [Day] and [Night]) add to this month total(from meter.dat) 'need code here to read meter.dat to get values before you save this months stats.
'TotalGas2Date = (Total Gas Consumption to Date)'add last month gas reading to this month(from meter.dat) 'need code here to read meter.dat to get values before you save this months stats.
filedialog "Save Meter Statistics",DefaultDir$;"\";"*.dat",file$ open file$ for output as #g 'logs made to meter.dat #g, date$();" Electric Night Reading ";a$;" Last Month ";b$;" Consumed This Month ";nv #g, date$();" Electric Day Reading ";c$;" Last Month ";d$;" Consumed This Month ";dv #g, date$();" Gas Meter Reading ";e$;" Last Month ";f$;" Consumed This Month ";gv close #g
'logs made to totals.txt totals$ = "totals.txt" open totals$ for append as #t #t, " " #t, " " #t, date$();" Monthly Readings and Total Consumptions to Date" #t, date$();" Readings and Totals to Date" #t, date$();" Electric Night Reading ";a$;" Last Month ";b$;" Consumed This Month ";nv #t, date$();" Electric Day Reading ";c$;" Last Month ";d$;" Consumed This Month ";dv #t, date$();" Gas Meter Reading ";e$;" Last Month ";f$;" Consumed This Month ";gv
#t, date$();" Total Electric [Day and Night] Consumed This Month ";monthTotElec #t, date$();" Total Electric [Night] Consumed to Date ";TotalNE2Date #t, date$();" Total Electric [Day] Consumed to Date ";TotalDE2Date #t, date$();" Total Electric [Day and Night] Consumed to Date ";TotalE2Date #t, date$();" Total Gas Consumed to Date";TotalGas2Date close #t wait 'I commented the button out for this. Not needed and could cause trouble [openfile] filedialog "Open Meter Standard",currentdir$+".dat",file$ if file$="" then wait 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 wait
[fulllog] run "notepad " ;"totals.txt" wait
[print] notice "I'll leave this part for you to figure out" 'your code can go here to do the print (good luck, don't give up, it get's easier) wait
[quit.main] close #main end
[buttonClick] close #main end
|
|
rocca
New Member
Posts: 6
|
Post by rocca on Mar 16, 2021 16:02:48 GMT
Thank you xxgeek This code works, I only need to adjust after I have a good understanding of what your code does correctly. I will let you know if it works properly. regards
|
|
|
Post by tsh73 on Mar 19, 2021 16:07:44 GMT
Kolin, what you do here called spam Another one and you will be banned for life.
|
|