Author Topic: Maths operations  (Read 1489 times)

tools-n-stuff

  • Newbie
  • *
  • Posts: 38
    • View Profile
Maths operations
« on: October 27, 2010, 03:30:05 PM »
Ok i so maths wasn't my best subject way back in the ol'shool days  :lol:

On reading the guide i have to say the Maths Ops section is really like a foreign language.
Its maybe straight forward to you (i hope), but i need pointers again.

Heres the set up.

This is to be based on real time.

I have two fields, one where i want the user to be able to add seconds. On hitting the update button i need those 60 seconds to be added to the second field, updating that field and its existing count, which needs to display in Hours (H), minutes (M) and seconds (S)  (read only). At the same time if a particular page is deleted i need the maths to decount from the total time.

Or have i got the wrong idea about maths ops?
Should a user create a new blank page for a fresh entry would it be possible for the total time results to be transfered to the new blank page automatically?
I know what i would like to happen but really don't know if its possible let alone how to do it.  :roll:
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 287
    • View Profile
Re: Maths operations
« Reply #1 on: October 27, 2010, 07:38:12 PM »
Quote from: "tools-n-stuff"
Ok i so maths wasn't my best subject way back in the ol'shool days  :lol:

On reading the guide i have to say the Maths Ops section is really like a foreign language.
Its maybe straight forward to you (i hope), but i need pointers again.

Heres the set up.

This is to be based on real time.

I have two fields, one where i want the user to be able to add seconds. On hitting the update button i need those 60 seconds to be added to the second field, updating that field and its existing count, which needs to display in Hours (H), minutes (M) and seconds (S)  (read only). At the same time if a particular page is deleted i need the maths to decount from the total time.

Or have i got the wrong idea about maths ops?
Should a user create a new blank page for a fresh entry would it be possible for the total time results to be transfered to the new blank page automatically?
I know what i would like to happen but really don't know if its possible let alone how to do it.  :roll:

When working with time and dates in HyperNext its often best to convert the value into total seconds - then add your value to it - then convert back to the required time/date format


Here is a simple script - its a bit messy.
It assumes field 1 holds the time to be added - in seconds
and field 2 holds the time in format 7 15 32 - representing 7h 15m 32s - the separators are spaces

Code: [Select]
local delta,time,hours,minutes,seconds,temp

Put field 1 into delta

@ --- Convert time into seconds ---
Put field 2 into time

Put NthChunkFN(time,' ',1) into hours
Multiply hours by 3600

Put NthChunkFN(time,' ',2) into minutes
Multiply minutes by 60

Put NthChunkFN(time,' ',3) into seconds

Add hours to seconds
Add minutes to seconds


@ --- make new time ---
Add delta to seconds

@ --- Convert new time back to hours etc ---
Put DivFN(seconds,3600) into hours
Put hours into temp
Multiply temp by 3600
Subtract temp from seconds

Put DivFN(seconds,60) into minutes
Put minutes into temp
Multiply temp by 60
Subtract temp from seconds

Put hours into field 2
Append ' ' onto field 2
Append minutes onto field 2
Append ' ' onto field 2
Append seconds onto field 2


If you need to decount from the total time then its probably easiest just to store field 2 in a global variable and then do the above calculation. This way you have the original time backed up.
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

tools-n-stuff

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Maths operations
« Reply #2 on: October 28, 2010, 09:42:01 AM »
Thanks for that Malkom,
I spent the best part yesterday evening trying to get it to work, which eventually i did. This morning i i have tried to get the info to pass to the next new page created but i can't see where i'm going wrong. It keeps creating a blank form ready for data entry and won't calculate the total times from the previous forms.

You wrote about the decount and that i should store field 2. Could you please elaborate, because i'm a little lost again.

Saying that, i thought that maybe the info wasn't being passed because it can't store the info correctly so i decided to look at the data options and the other threads.

I will be adding a new post in that section after this.
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 287
    • View Profile
Re: Maths operations
« Reply #3 on: October 28, 2010, 09:01:49 PM »
Quote from: "tools-n-stuff"
Thanks for that Malkom,
I spent the best part yesterday evening trying to get it to work, which eventually i did. This morning i i have tried to get the info to pass to the next new page created but i can't see where i'm going wrong. It keeps creating a blank form ready for data entry and won't calculate the total times from the previous forms.

You wrote about the decount and that i should store field 2. Could you please elaborate, because i'm a little lost again.

Saying that, i thought that maybe the info wasn't being passed because it can't store the info correctly so i decided to look at the data options and the other threads.

I will be adding a new post in that section after this.

I often use global variables as their data can be shared anywhere inside your HyperNext program.

Basically in your first card:-

Code: [Select]
Global timeData

Put field 2 into timeData



then in the second card script, button or any other place where you need to use that data do

Code: [Select]
Global timeData

@ put data into a field
Put timeData into field 1

@ show data as when debugging
Message timeData

So if you need to share data across your program Global variables are very helpful

If your data is only to be used within one script then use Local variables
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

tools-n-stuff

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Maths operations
« Reply #4 on: November 03, 2010, 02:14:02 PM »
Hi Back again,
Been away for a while, real life work!!
And to be honest, i took a brief look at the world of python and ide's and gui's!

OK then, with the time away and coming back to HN this morning i've spent hours trying to figure things out and i seriously think i'm digging a deeper hole.

With the different bits of code and different things i am trying to do i no longer know where to place anything.

It never seems to work quite how i expect. If the end user hits the update more than once on any given address/contact page then it will just add the results together and print them on that contact page. ie: contact 2 has 1 minute on his time field. If i hit the update button again while on this contacts page then the GlobalTime total will go up by a  minute. And on and on everytime the update button is pushed.

When a user hits the new button to create a new contact entry, the globalTime is not getting transfered to the new contact page.

Sorry but i am at a total loss. I just don't know what code to place or where.

BTW the tim/maths script works fine
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 287
    • View Profile
Re: Maths operations
« Reply #5 on: November 03, 2010, 10:32:02 PM »
Quote from: "tools-n-stuff"
Hi Back again,
Been away for a while, real life work!!
And to be honest, i took a brief look at the world of python and ide's and gui's!

Nice to have you back and there yes there are some really wonderful and cool programming languages and IDEs out there



Quote from: "tools-n-stuff"
OK then, with the time away and coming back to HN this morning i've spent hours trying to figure things out and i seriously think i'm digging a deeper hole.

When we get stuck its often best to step back and try to figure it out - with programming - debug messages either give what we expect or give a suprise. Its tedious putting them in but if we are looking in the right place then they will pinpoint where something is going wrong.



Quote from: "tools-n-stuff"
With the different bits of code and different things i am trying to do i no longer know where to place anything.

It never seems to work quite how i expect. If the end user hits the update more than once on any given address/contact page then it will just add the results together and print them on that contact page. ie: contact 2 has 1 minute on his time field. If i hit the update button again while on this contacts page then the GlobalTime total will go up by a  minute. And on and on everytime the update button is pushed.

When a user hits the new button to create a new contact entry, the globalTime is not getting transfered to the new contact page.

Sorry but i am at a total loss. I just don't know what code to place or where.

I'm not sure if you have tried pen and paper approach - where you draw block diagrams of how your application should work and then adding the major components with global variables for sharing data.

Sorry to repeat - but it sounds like you need some debug messages to ensure the right results are happening at each step.

Have you ensured that with each contact or new contact their data is initialized(or zeroed) and isn't carrying anything over from a previous contact.
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

tools-n-stuff

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Maths operations
« Reply #6 on: November 04, 2010, 03:03:38 PM »
I have gone over the guide and the pdf files onsite and can't see any reference to debugging anywhere. I have googled debug in hypernext and still can't find any info.
As mentioned in another thread, debug for me is <debug> at the top of the page and go.

And don't appologise for repeating yourself, but please explain how to go about debugging.

LOL, the pen and paper approach? I guess i could draw a few squares on paper and join them up with lines but it would do me no good at all. I wouldn't know why i am doing what i am doing and for what purpose.

I got so close to getting this done, there is the more solid external data save to setup, get this count thing working and thats it. (except the final graphics).
I am sure for someone who knows how to program that this whole project should have been finished the day they started.
I think i am going to give up. I can't follow your guides, and i don't get half of what you are saying.
I have spent too much time on trying to get this to work and the lack of tutorials and info on the net doesn't help.

I understand that you have a life and can't devote yourself to this (me, my project) fulltime.
I'll give it another 48 hours and if i can't find the info i need to get it working then, im sorry but i will remove HN. I have given it my full attention and i am not asking you to do the job for me, but your explanations don't actually explain anything or help me learn. And spending days on what should be a simple maths problem, just isn't right.

The only thing i can think of is that you (time allowing and the mood to help) take a look at the project and see what the hell i am doing wrong. At least that way i will see what you have done and have a reference to learn by.
Damn it shouldn't be this complicated to do maths and store the info.
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 287
    • View Profile
Re: Maths operations
« Reply #7 on: November 04, 2010, 07:01:11 PM »
Thank you for the feedback here - its just dawned on me that nowhere on our website or documentation is there any info on debugging. I'll have to write something and put it up.

By debugging - i just mean placing commands in your program to indicate the value of some variables or indicate that the program has reached certain points.

The version of HyperNext available to the public doesn't have a debugger so users have to place the commands themselves.

I usually use the Messagecommand to see if the program has reached a certain point because it presents a dialog box to the user with some text and pauses the program:-

Code: [Select]
Global gVar,
Local x,value

Message 'Test Point 1'

@display contents of gVar
Message gVar

@ Display contents of field 1
Put field 1 into x
Message x

@ Display array cell value
Put ArrayValueFN('books',5,7) into value
Message value

Message 'Test finished'



Another way is to use the Put command to place the value of variables into some fields. This way your program doesn't pause while waiting for you to close the Message dialog box.

Code: [Select]
@ Display the elements of a list
@ and wait 5 seconds before showing the next one
Global gList
Local n,count

@ find how many lines in the list
Put LinesFN(gList) into count
Message count

if (count>0) then
  @ Display the lines in a list
  For n=1 to count
     Put n into field 1
     Put line n of gList into field 2
     Wait(1,5000)
  EndFor
EndIf

I hope this makes some sense.

Don't give up because you are certainly making progress and programming does get easier although there is always something new to learn. Once you understand the basics of programming, variables, flow control, data structures then you will be able to concentrate on designing your program and have some fun.
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

tools-n-stuff

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Maths operations
« Reply #8 on: November 04, 2010, 07:55:48 PM »
So this means theres another version, not open to the public? sounds interesting.
Or is this the next version you are talking about?
If so is it going to be a commercial version.

Obviously new to programming i could use info on this, even though youv'e said you can't say much. Maybe an estimated release date/month or year, if commercial how much! And as much info you can give about the changes. Appetites need wetting after-all.
I mean am i trying to learn something here that won't be of any use in the new version? Gulp!

As for giving up! I don't want to, but its getting so frustrating.
You are giving me code and only a few lines at a time, its not like my requests require 100's of lines of code that i would have to wade through, and its that whats doing my nut in. It should be easy to follow and understand.
When i learnt the 3D language, i understood the logic instantly and after 2 weeks i had gone through a comprehensive tutorial and could build fully interactive 3D environments, with all the possible options included. With programming, there is something missing, which is preventing me from getting to grasps with the principal. The way things are setup! Variables, commands, on which page and how and why? Why and how info gets passed from one "card" to another.

As for debugging, its getting more complex by the minute.
I really don't think you realise at what point i am finding this hard to get. My only fear is actually getting bored before i advance, which will obviously take the fun away from the whole experience.
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 287
    • View Profile
Re: Maths operations
« Reply #9 on: November 05, 2010, 02:59:24 PM »
Quote from: "tools-n-stuff"
So this means theres another version, not open to the public? sounds interesting.
Or is this the next version you are talking about?
If so is it going to be a commercial version.

Obviously new to programming i could use info on this, even though youv'e said you can't say much. Maybe an estimated release date/month or year, if commercial how much! And as much info you can give about the changes. Appetites need wetting after-all.
I mean am i trying to learn something here that won't be of any use in the new version? Gulp!

There are actually a few version, branches of HyperNext as its cross-platform.
V4 when it arrives will be commercial/shareware and will run everything that v3.x does.
V3.83 does have a few irritating bugs and perhaps I'll update that to 3.84 before releasing V4 - I'll see how it goes.

The debugger just isn't fit for use by programing novices so its always disabled for public releases.
By the way, its not a magical tool for fixing things as it mainly shows whats going on inside HyperNext and its very user-unfriendly.

I'm sorry for not giving specific release dates but a lots happening here and I really don't know myself.
 




Quote from: "tools-n-stuff"
As for giving up! I don't want to, but its getting so frustrating.
You are giving me code and only a few lines at a time, its not like my requests require 100's of lines of code that i would have to wade through, and its that whats doing my nut in. It should be easy to follow and understand.
When i learnt the 3D language, i understood the logic instantly and after 2 weeks i had gone through a comprehensive tutorial and could build fully interactive 3D environments, with all the possible options included. With programming, there is something missing, which is preventing me from getting to grasps with the principal. The way things are setup! Variables, commands, on which page and how and why? Why and how info gets passed from one "card" to another.

As for debugging, its getting more complex by the minute.
I really don't think you realise at what point i am finding this hard to get. My only fear is actually getting bored before i advance, which will obviously take the fun away from the whole experience.

There is a lot of depth to programming but some programs can be very simple - it just depends on your aims. Once you understand the basics then programming suddenly becomes much easier.

Its better to get a good grasp of how cards, variables etc work before you move on - it will make it much more fun and save you lots of time debugging.
After finishing the QuickStart tutorials you would be in a good position to evaluate your current program. Then it would all be much clearer to you.

The thing that stops most programmers from getting bored is that they have a goal and proceed to it in a number of steps - once they complete a step its a small victory and they can tick it off and move on to the next one. In the end they have a working program. We are lucky because we get to work on the whole program ourselves but there are lots of professional programmer who only ever get to work on a module.

Perhaps you can make a list of functions needed in your program - then tick them off as you do them.
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

 

anything