  # On of my "stupiest" questions....

Discussion in 'Questions (Windows Mobile)' started by Cableguy, Nov 30, 2007.

1. Hi all,

I'm trying to come up with a simple calcutation tool for an on-line game called travian...
I'm trying to automatiza the calculation of the time nned to travel from point a to b at a given speed...
For the ones not fammyliarized with the game,,, The units have diferents seepds, measured in squares per hour...

So, since I don't want to repeat the same code over and over, I thought about creating a calculation sub and pass the parameters...
But they are not being passed...
I just can't fugure out...

Code:
`.....n=VLegCalculos(d,ds,fx,n)Msgbox(TS)End SubSub Calculosv=3600/nMsgbox(v)TS=(v*d)+((v*fx)*ds)Format(TS,"n2")Return(TS)End Sub`
Any thoughts?

I'm also trying to convert seconds to the time format (HH:MM:SS), any one have done that yet?

2. Hi Cableguy,

since we have local variables, you have to define the parameters in the called sub again:

Sub Calculos(d,ds,fx,n)
...
End Sub

Cheers
specci48

PS: There is no stupid question, there are only stupid answers...

3. I knew I was forgetting something....dahm....

Thnks Specci...:sign0188:

4. Ok, so calculations now occur but the TS var is not returned to the calling sub....Any thoughts????

5. :signOops: ... I forgot to answer to your second question.

If you want to convert seconds to HH:MM:SS you can do something like this.

Code:
`TimeFormat("HH:mm:ss")Label1.Text = Time(seconds * cTicksPerSecond)`
This works for 0 =< seconds < 86400 since 86400 seconds equals 00:00:00 again.

specci48

6. ... since we have local variables, you have to assign the returning value to a variable...

TS = Calculos(d,ds,fx,n)

Last edited: Nov 30, 2007
7. That doesn't work since TS is tne result of a mathematical expression....
Still in the help file it reads:
So the code SHOULD work but it gives an "input in the wrong format" kind of error...

Solved:the paramters returned do not need to be inside brackets.....

Last edited: Nov 30, 2007
8. Remove the brackets from the return statement
Code:
`Return TS`
Edit:
oops ... missed your edit ... Last edited: Nov 30, 2007
9. Ok, back to the same stupid question:

I have in one sub....

TS= some mathematical operation
MsgBox(TS) ' Does show the result from the previous line...
Return TS ' Nothing is passed to the calling sub, WHY????

10. Can you post how the code looks like at the monent?

Edit: Have you implemented post #6 in your calling sub?

Last edited: Dec 1, 2007
11. the two intervinient subs are:

Code:
`Sub Button1_Click'---------------------------------------------'Calcula a distancia a percorrer em Quadradosdx=Abs(textbox1.Text-textbox3.Text)dy=Abs(textbox2.Text-textbox4.Text)d=Sqrt((dx*dx)+(dy*dy))'---------------------------------------------'---------------------------------------------'Se a distancia for maior que 30 quadrados'Faz o calculo incluindo a praça de TorneiosIf d>30 Thends=d-30d=30Else ds=0d=dEnd Iffx="1."&num1.ValueFormat(fx,"n1")'---------------------------------------------n=VLegCalculos(d,ds,fx,n)Format (TS,"n3")Msgbox(ts)End SubSub Calculos(d,ds,fx,n)'---------------------------------------------'Calcula As velocidades individuais das Tropas'---------------------------------------------'1Hora=3600segundos'vel(seg)=3600/n(quadrados por tipo de unidade)'Tempo=(vel x d)+((vel x fx)x ds)v=3600/nMsgbox(v)Msgbox(d)TS=(v*d)+(v*fx*ds)Msgbox(ts)Return TSEnd Sub`

12. Please implement post #6:
Code:
`TS = Calculos(d,ds,fx,n)`
in the calling sub!

Here again, the resuilt of the called sub must be stored into the/a local variable of the calling sub...

specci48

13. Thanks again Specci...been a while since I coded something...So I'm a bit rusted....

14. No problem! I have the same difficulties jumping between different programming langugages from time to time... :sign0161: