On of my "stupiest" questions....

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

  1. Cableguy

    Cableguy Expert Licensed User

    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=VLeg
    Calculos(d,ds,fx,n)
    Msgbox(TS)
    End Sub

    Sub Calculos
    v=
    3600/n
    Msgbox(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. specci48

    specci48 Well-Known Member Licensed User

    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. Cableguy

    Cableguy Expert Licensed User

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

    Thnks Specci...:sign0188:
     
  4. Cableguy

    Cableguy Expert Licensed User

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

    specci48 Well-Known Member Licensed User

    :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. specci48

    specci48 Well-Known Member Licensed User

    ... 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. Cableguy

    Cableguy Expert Licensed User

    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. specci48

    specci48 Well-Known Member Licensed User

    Remove the brackets from the return statement
    Code:
    Return TS
    Edit:
    oops ... missed your edit ... ;)
     
    Last edited: Nov 30, 2007
  9. Cableguy

    Cableguy Expert Licensed User

    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. specci48

    specci48 Well-Known Member Licensed User

    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. Cableguy

    Cableguy Expert Licensed User

    the two intervinient subs are:

    Code:
    Sub Button1_Click
    '---------------------------------------------
    'Calcula a distancia a percorrer em Quadrados
    dx=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 Torneios
    If d>30 Then
    ds=d-
    30
    d=
    30
    Else 
    ds=
    0
    d=d
    End If
    fx=
    "1."&num1.Value
    Format(fx,
    "n1")
    '---------------------------------------------
    n=VLeg
    Calculos(d,ds,fx,n)
    Format (TS,
    "n3")
    Msgbox(ts)
    End Sub

    Sub 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/n
    Msgbox(v)
    Msgbox(d)
    TS=(v*d)+(v*fx*ds)
    Msgbox(ts)
    Return TS
    End Sub
     
  12. specci48

    specci48 Well-Known Member Licensed User

    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. Cableguy

    Cableguy Expert Licensed User

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

    specci48 Well-Known Member Licensed User

    No problem! I have the same difficulties jumping between different programming langugages from time to time... :sign0161:
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice