Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Superscripts in MS Access

Status
Not open for further replies.

dbadmin

Programmer
Jan 3, 2003
147
US
Hi Gurus,

Is it possible to store a data like x to the power of 2 (x raised to 2) in MS Access? If yes, how?

dbadmin
 
Can you explain further? Obviously you don't just want to store two values, X and 2.

ChaZ



"When religion and politics ride in the same cart...the whirlwind follows."
Frank Herbert
 
I'm not sure how one might do that. Values stored in a database typically represent a specific value and not a computation (as 'x squared' or 'x to the tenth power' implies).

You could store a string ("25^3" or something like that) to represent 25 cubed - as an example. A function could be written to interpret this string and convert it to the calculated value at some point in time.

Code:
Function xPower(x As String)
' returns exponential value y raised to z power
' x has to be a string in format of number ^ number (4^2)
' y represents base number
' z represents exponent
    Dim y As Double, z As Integer, i As Integer
    i = InStr(1, x, "^", 1)
    If i = 0 Then Exit Function
    If IsNumeric(Left(x, i - 1)) Then
        y = Left(x, i - 1)
    Else
        Exit Function
    End If
    If IsNumeric(Right(x, Len(x) - i)) Then
        z = Right(x, Len(x) - i)
    Else
        Exit Function
    End If
    xPower = y
    If z = 0 Then
        xPower = 1
        Exit Function
    End If
    For i = 2 To z
        xPower = xPower * y
    Next
End Function

Or something like that.
 
...or you could just do
xpower = Eval(x)
--Jim
 
Sometimes old age catches up with you and you just can't remember everything. How embarassing.
 
...I've been caught doing the same type of thing myself, and I'm getting to that point where the 'old age' thing is fitting to well.
--Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top