|
-
Jul 5th, 2000, 01:26 AM
#1
Thread Starter
Member
Hi, I have a text box which shows the result of a
calculationcan anyone tell me how to format this text box
to show scientific notation.
And also how do i set the number of decimal places for this
notation.
thanks in advance
MICK
-
Jul 5th, 2000, 01:33 AM
#2
Fanatic Member
Have you tried looking at the property of the textbox DataFormat?
Chemically Formulated As:
Dr. Nitro
-
Jul 5th, 2000, 02:04 AM
#3
Thread Starter
Member
Hi Nitro, thanks for the reply.
Is there a way to change this propery at run time using code
what i want to do is have two option buttons, clicking on
one will make the text box display a number using decimal notation, and clicking on the other will display it in
scientific notation. I want them both to use three decimal places.
thanks again
MICK
-
Jul 5th, 2000, 02:27 AM
#4
Fanatic Member
Hello Bucko!
Try something like this Bucko. Place a textbox on your form and change the DataFormat to whatever. Place the following in the form_load and you should get the hang of it from there.
Code:
MsgBox Text1.DataFormat.Format
Chemically Formulated As:
Dr. Nitro
-
Jul 5th, 2000, 02:39 AM
#5
Lively Member
How about
Text1 = Format(NumberVar, "Scientific")
Roger
-
Jul 5th, 2000, 09:37 AM
#6
If you have VB6, you can set the number of decimals using the Round function.
Code:
'Rounds to 1 decimal place
RetVal = Round(MyNum, 1)
-
Jul 5th, 2000, 11:19 AM
#7
_______
<?>
if not you can round them this way...
'rounding a number to 2 decimal places
Function RoundNumber(lNumber, Optional iDecimalPlaces As Integer = 1)
RoundNumber = Int(lNumber * (10 ^ iDecimalPlaces) + 0.5) / (10 ^ iDecimalPlaces)
End Function
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jul 5th, 2000, 05:58 PM
#8
Here is a small code I slapped together. It will return a String in the form of 1.11 x 10^5. If the number is less than 1 (in decimals) it will return a negative exponent. 1.11 x 10^-5
Code:
Function CSci(Number)
If IsNumeric(Number) Then
If Number >= 1 Then
tmpNum = CStr(Number)
GetPosOfZeros = InStr(1, tmpNum, "0") - 1
NumOfZeros = Right(tmpNum, Len(tmpNum) - GetPosOfZeros)
chkNum = CDbl(NumOfZeros)
If chkNum <> 0 Then
For I = 1 To Len(NumOfZeros)
NumOfZeros = Right(tmpNum, Len(tmpNum) - GetPosOfZeros - I)
chkNum = CDbl(NumOfZeros)
If chkNum = 0 Then Exit For
Next I
End If
nExp = Len(NumOfZeros)
nNum = Left(tmpNum, Len(tmpNum) - nExp)
tmp = CDbl(nNum)
Do While tmp > 10
tmp = tmp / 10
Loop
newnum = CStr(tmp)
AddZeros = Len(Right(newnum, Len(newnum) - 3))
CSci = newnum & " x " & " 10^" & nExp + AddZeros
ElseIf Number < 1 Then
tmpNum = CStr(Number)
tmpNum = Right(tmpNum, Len(tmpNum) - 2)
GetZeroPos = InStrRev(tmpNum, "0")
NumOfZeros = Left(tmpNum, GetZeroPos)
chkNum = CDbl(NumOfZeros)
If chkNum <> 0 Then
For I = 1 To Len(NumOfZeros)
NumOfZeros = Left(tmpNum, Len(tmpNum) - GetZerosPos - I)
chkNum = CDbl(NumOfZeros)
If chkNum = 0 Then Exit For
Next I
End If
nExp = Len(NumOfZeros)
nNum = Right(tmpNum, Len(tmpNum) - NumOfZeros)
tmp = CDbl(nNum)
Do While tmp > 10
tmp = tmp / 10
Loop
newnum = CStr(tmp)
CSci = newnum & " x " & "10^-" & nExp + 2
End If
End If
End Function
The usage is basically like CInt, CLng, CStr etc. Make a Form with a TextBox and place the following code into a CommandButton. It will return and print whatever you wrote in the TextBox in Scientific Notation.
Code:
Private Sub Command1_Click()
RetVal = CSci(Text1)
Print RetVal
End Sub
[Edited by Megatron on 07-05-2000 at 07:16 PM]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|