Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Writing formula to include quote marks in result | Excel Worksheet Functions | |||
All arithmetic functions return Zero as result | Setting up and Configuration of Excel | |||
cell calculation check if result is negative and zero out if not l | Excel Worksheet Functions | |||
How do I use a rounded calculation result in another calculation? | Excel Worksheet Functions | |||
How do I use a rounded calculation result in another calculation? | Excel Worksheet Functions |