LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Writing the result of arithmetic calculation in a cell

Variables a & h are acting like text and not numbers because a+h is
concatenating, not adding. It has to do with the Dim statement for those
variables:
Dim a, b, h, k, l As Double

Each variable must be given a type or Excel assumes type variant. Therefore
a, b, h, and k are variants, only l is Double. You cannot make a list of
variables a type with only one As Double. ie:
Dim a As Double, b As Double, h As Double,....etc.

Once you have the variables Dimmed correctly, it should work as expected.
The variable will now use the Value of InputBox instead of the Text. Text is
the default result of Inputbox, so a Variant variable would be assigned a
text.
I also notice that the variable i is not declared at all, so it also is type
Variant. I suggest the use of Option Explicit to help avoid errors with
variables.
Dim i As Long

Mike F
"Merike" wrote in message
...
Here it comes:

Sub Algandmed()
Dim a, b, h, k, l As Double
Dim tekst1, tekst2 As String
a = InputBox("Algandmete sisestamine:... Anna muutuja x
algväärtus")
b = InputBox("Algandmete sisestamine:... Anna muutuja x suurim
võimalik väärtus")
h = InputBox("Algandmete sisestamine:... Anna samm h, millega x
muutub")

tekst1 = "Sellise x-i algväärtuse korral ei ole" & Chr(13) &
"funktsioon määratud!"
k = Atn(a) * Sin(5 * a)
l = a
Cells(2, "C") = "x1="
Cells(2, "D") = a
Cells(2, "E") = "y1="
If k <= 0 Or l < 0 Then
Cells(2, "F") = "väärtus puudub"
MsgBox (tekst1)
Else
Cells(2, "F") = Log(Atn(a) * Sin(5 * a)) / Log(Cells(3, "L")) +
Sqr(3 * a ^ 3)
End If

i = 1
Do While a < b
i = i + 1
Cells(i + 1, "C") = "x" & i & "="
a = a + h
Cells(i + 1, "D") = a
Cells(i + 1, "E") = "y" & i & "="
k = Atn(a) * Sin(5 * a)
l = a
tekst2 = "x väärtuse: " & Cells(i + 1, "D") & " korral ei ole
funktsioon määratud!"
If k <= 0 Or l < 0 Then
Cells(i + 1, "F") = "väärtus puudub"
MsgBox (tekst2)
Else
Cells(i + 1, "F") = Log(Atn(a) * Sin(5 * a)) / Log(Cells(3,
"L")) + Sqr(3 * a ^ 3)
End If
Loop

End Sub


--
You can't know everything about everything.


"Mike Fogleman" kirjutas:

I am not getting that result with Excel 2000. I am getting 2, as you wish
to
get. Could you post your entire sub so we could see it?
"Merike" wrote in message
...
In my macro a=1 and h=1
And when I put
Cells(i + 1, "D") = a+h
then it writes 11 in the cell?

But it should write 2. I'm using 2000 version.
--
You can't know everything about everything.






 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing formula to include quote marks in result Valerie Excel Worksheet Functions 4 February 18th 09 10:01 PM
All arithmetic functions return Zero as result Khoshravan Setting up and Configuration of Excel 9 June 26th 06 03:24 AM
cell calculation check if result is negative and zero out if not l Rich Excel Worksheet Functions 2 January 16th 06 08:31 PM
How do I use a rounded calculation result in another calculation? vnsrod2000 Excel Worksheet Functions 1 January 26th 05 10:11 PM
How do I use a rounded calculation result in another calculation? vnsrod2000 Excel Worksheet Functions 1 January 26th 05 09:36 PM


All times are GMT +1. The time now is 10:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"