# Math Help - vb calculation formula problem

1. ## vb calculation formula problem

my problems goes like this:

1. Input the value of T:3
Input the value of S: 6

Then when i click the compute button the formula will compute like this

T^S - [T(T-1)^S] + [T(T-2)^S] = A(answer)

for example if i input T=3 and S=6 the computation will goes like this...

3^6 - [3 (2)^6 ] + [3 (1)^6] =
729 - 192 + 3 = 540

^ = raised to the power

problem: a.) how can i decrement the value of T depending on the values i input
b.) how can i make an alternate conditional statement of the - and + operation.. because the formula will be
using an alternate operation - + - + and so on...

hope someone can help me thank u very much

2. I don't understand your first question, but your second can be solved like this:

Code:

For i = c1 To c2 Step 2
var1 += ....
var1 -= ....
Next i
where i is a looping variable, which you can use in calculating var1. c1 and c2 are constants and var1 is a variable.

Hope this helped.

3. um, PM me and tomorrow I can help you more. I saw this as I was getting ready for bed and I can give you the VB you need.

first: I assume your using the dev environment right? so your making this into a form?

4. I got 541.
I'm just doing this for practice because I need to learn how to do real math. I'm not not educated in reading math formula's and translating it to code, but I know how to write code. I did not understand decrement of T, and what the condition for it is. Anyways, this is just a 10 minute stab at it. Its made for the web, and not windows. For Windows, it's Console.Writeline(A)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

CalculateST(3, 6)

End If

End Sub
Public Function CalculateST(ByVal T As Long, ByVal S As Long) As Long

Dim Success As Boolean = False
Dim ErrorMessage As String = Nothing
Dim Context As HttpContext = HttpContext.Current

Dim Formula As Integer = 0
Dim A As Long = 0

Try
If T > 2 Then Formula = 1

Select Case Formula
Case 1
A = T ^ S - (T * (T - 1) - 1 ^ S) + (T * (T - 2 ^ S))
Case 2
A = T ^ S - (T * (T - 1) - 1 ^ S) + (T * (T - 2 ^ S))
End Select

Success = True

Catch ex As Exception
Success = False
ErrorMessage = ex.Message.ToString

End Try

If Success = True Then
Context.Response.Write(A.ToString)
Else
Context.Response.Write(ErrorMessage)
End If

End Function