Author Topic: Calcualte and show results?  (Read 9963 times)

nathan323

  • Newbie
  • *
  • Posts: 3
Calcualte and show results?
« on: March 07, 2011, 02:02:53 AM »
Howdy.

I want to create a wage calculator, that shows buttons for each shift available of the week. Each button when clicked would put the amount the shift is worth into a Total display that adds up when more shifts are clicked. Is this possible/easy?

Thanks Nathan
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 464
  • Here to help you
Re: Calcualte and show results?
« Reply #1 on: March 08, 2011, 09:43:49 AM »
Yes, this is an easy thing to do with HyperNext although there are many options.

Perhaps the easiest way - just use a global variable for each shift and a global procedure to work out the totals.

For one button - shift 1 on Friday :-

Code: [Select]
Global shift1Friday

Put field 1 into shift1Friday

Call CalcTotals

Put totalWages into field 2


The CalcTotals procedure in MainCode section:

Code: [Select]
Global totalWages
Global shift1Friday,shift2Friday,shift3Friday

Put 0 into totalWages

Add shift1Friday to totalWages
Add shift2Friday to totalWages
Add shift3Friday to totalWages
« Last Edit: March 12, 2011, 07:41:56 AM by Malkom »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

nathan323

  • Newbie
  • *
  • Posts: 3
Re: Calcualte and show results?
« Reply #2 on: March 11, 2011, 09:34:43 PM »
Ok thanks for the reply.

Im very new to HyperNext. I created a button, clicked on Script, pasted your first piece of code in. Clicked Run and the editor opened with "^ misplaced error 2" as Last Error, Line was Global shift1Friday.

Then I went on to the next step, pasted your second piece of code into MainCode. Then when clicking Run, I get the same error, but with Line being Global totalWages.

What am I doing wrong?
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 464
  • Here to help you
Re: Calcualte and show results?
« Reply #3 on: March 12, 2011, 07:48:31 AM »
Hi Nathan

Sorry, there was a typing error in my code - the second block - it had the t missing from the Put command

Code: [Select]
Put 0 into totalWages
Its now corrected.


I also typed the code in and it worked (except for my typing error) - perhaps there is a dot at the end of the line or other typo?

if in doubt about a line - put a comment character @ in front of it to prevent the compiler checking it.
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

nathan323

  • Newbie
  • *
  • Posts: 3
Re: Calcualte and show results?
« Reply #4 on: March 19, 2011, 12:59:06 AM »
Ok thanks. I caught the typo before running it anyway. Seems like there might be some steps missing though?

* I create a button - do i have to name the button "shift1Friday"?

* Do i need to create two fields on the card, and name them "field 1" and "field 2"? If so is there any code behind them?

* So in the editor in the MainCode section i click CalcTotals on the left then input the second piece of code there? And the first piece of code goes into the button?

As i said im brand new to this program, or any software programming :)

Thanks, Nathan
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 464
  • Here to help you
Re: Calcualte and show results?
« Reply #5 on: March 26, 2011, 06:26:46 AM »
I'm sorry for the long delay in replying.


Quote from: "nathan323"
* I create a button - do i have to name the button "shift1Friday"?
The button name isn't so important except to clarify which control you are working on when editor is open - without names,  multiple buttons on one card can get very confusing.
The button value of 'Shift1Friday' could help you identify which button is which when your program is running.

I'm not sure about the layout of your program's screen and so the code I gave was just a rough example to help you get started.



Quote from: "nathan323"

* Do i need to create two fields on the card, and name them "field 1" and "field 2"? If so is there any code behind them?
The fields I used are just so can see if your code is producing the correct answers.
Usually when testing an idea I just make a card with a few buttons and fields to see if the code actually works. Then later put it into the actual project.




Quote from: "nathan323"
* So in the editor in the MainCode section i click CalcTotals on the left then input the second piece of code there? And the first piece of code goes into the button?
Yes, thats right. The MainCode section holds procedures that can be called from anywhere within your program. Where as if you placed the CalcTotals procedure inside the 'Shift1Friday' button it could only be called by the 'Shift1Friday' button.


Quote from: "nathan323"
As i said im brand new to this program, or any software programming :)
Thats great - the joys of learning programming - especially when it works - although often more interesting when it doesn't :)
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.