Выдает ошибку «Loop without Do» хотя Do есть |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
I’m trying to implement a simple Newton’s method iterative solver using Excel VB (I have never used VB.)
I keep getting the error loop without a Do
and I can’t figure out what I’m doing wrong here.
I’m trying to find the roots of the function z^3 - z^2 - (B^2 + B - A)z - A*B
called the compressibility factor.
My source MSN
Function zCalculation(ByVal temp As Double, ByVal press As Double) As Double
Dim tempCr As Double
Dim pressCr As Double
Dim A As Double
Dim B As Double
tempCr = temp / 238.5
pressCr = press / 547.424092
A = pressCr / tempCr
A = A / (9 * (2 ^ (1 / 3) - 1))
B = pressCr / tempCr
B = B * (2 ^ (1 / 3) - 1) / 3
Dim zNot As Double
Dim counter As Integer
counter = 0
zNot = 1#
Do
counter = counter + 1
zNot = zNot - (zNot ^ 3 - zNot ^ 2 - (B ^ 2 + B - A) * zNot - A * B) / (3 * zNot ^ 2 - 2 * zNot - (B ^ 2 + B - A))
If counter > 1000 Then
Exit Do
Loop Until eval(zNot, A, B) < 0.000001
zCalculation = zNot
End Function
break
Function eval(ByVal z As Double, ByVal A As Double, ByVal B As Double) As Double
eval = z ^ 3 - z ^ 2 - (B ^ 2 + B - A) * z - A * B
End Function
asked Dec 9, 2013 at 16:58
Felix CastorFelix Castor
1,5691 gold badge17 silver badges38 bronze badges
You need an:
End If
in your code.
answered Dec 9, 2013 at 17:04
Gary’s StudentGary’s Student
95k9 gold badges58 silver badges97 bronze badges
2
You can try:
Function zCalculation(ByVal temp As Double, ByVal press As Double) As Double
Dim tempCr As Double
Dim pressCr As Double
Dim A As Double
Dim B As Double
tempCr = temp / 238.5
pressCr = press / 0.546789
A = pressCr / tempCr
A = A / (9 * (2 ^ (1 / 3) - 1))
B = pressCr / tempCr
B = B * (2 ^ (1 / 3) - 1) / 3
Dim zNot As Double
Dim counter As Integer
counter = 0
zNot = 1#
Do
counter = counter + 1
zNot = zNot - (zNot ^ 3 + zNot ^ 2 - (B ^ 2 + B - A) * zNot - A * B) / (3 * zNot ^ 2 + 2 * zNot - (B ^ 2 + B - A))
If counter > 1000 Then
Exit Do
End if ' <--- Here
Loop Until eval(zNot, A, B) < 0.000001
zCalculation = zNot
End Function
answered Dec 9, 2013 at 17:06
1
Sub datacalculationsandformat()
Dim row As Integer
row = 2
Do While Cells(row, 2) <> ""
Cells(row, 3).Value = Cells(row, 2).Value * 0.3
Cells(row, 4).Value = Cells(row, 2) * 0.1
Cells(row, 5).Value = Cells(row, 2).Value + Cells(row, 3).Value + Cells(row, 4).Value
If Cells(row, 5).Value >= 8000 Then
Worksheets("Sheet1").Cells(row, 5).Font.Bold = True
row = row + 1
Loop
slavoo
5,64864 gold badges36 silver badges39 bronze badges
answered Sep 21, 2017 at 5:11
zzoommmmmm 0 / 0 / 0 Регистрация: 13.12.2011 Сообщений: 6 |
||||
1 |
||||
13.12.2011, 17:58. Показов 6779. Ответов 3 Метки нет (Все метки)
Найти первый отрицательный член последовательности cos(ctg(n)) для n изменяющегося следующим образом: n = 1, 2, 3, … .
Помогите исправить код, пишет ошибку «Loop without Do». Заранее спасибо!)
__________________
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
13.12.2011, 17:58 |
Ответы с готовыми решениями: Почему в коде указано, что » кнопка 1 » и » кнопка 2 » добавлены в центр, а они добавляются «по умолчанию»? import java.awt.*; import javax.swing.*; @SuppressWarnings("serial")…
3 |
es geht mir gut 11264 / 4746 / 1183 Регистрация: 27.07.2011 Сообщений: 11,437 |
|
13.12.2011, 18:20 |
2 |
11 и 12 строку поменяй местами, у меня был точно такой же случай.
1 |
Alex77755 11464 / 3757 / 675 Регистрация: 13.02.2009 Сообщений: 11,098 |
||||
13.12.2011, 18:25 |
3 |
|||
11 и 12 строку поменяй местами, у меня был точно такой же случай. Вообще убери. Уже есть условие
1 |
0 / 0 / 0 Регистрация: 13.12.2011 Сообщений: 6 |
|
13.12.2011, 18:25 [ТС] |
4 |
11 и 12 строку поменяй местами, у меня был точно такой же случай. Спасибо, помогло)
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
13.12.2011, 18:25 |
Помогаю со студенческими работами здесь
Непонятная ошибка » For loop control variable must have ordinal type» interface uses Патерн «прототип» не работает, выдаёт ошибку «недопустимый вызов нестатической ф-ции», где я в коде ошибка? #include <iostream> Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 4 |
-
Mar 8th, 2011, 03:27 PM
#1
Thread Starter
New Member
[RESOLVED] Compile Error:Loop Without Do
I get a compile error saying,
Loop Without do. I really have no idea what that means. I’d appreciate any help i could get.Code:
' ok? If ((WeekdayName(Weekday(LoanExpiryDate - 1)) = "Saturday") Or (WeekdayName(Weekday(LoanExpiryDate - 1)) = "Sunday") Or (libraryopendate = False)) Then ' no good! either the date we're trying is in a weekend or its when the library is open, add one onto the date and try again LoanExpiryDate = LoanExpiryDate + 1 Else dateok = True End If Loop End Sub
-
Mar 8th, 2011, 03:36 PM
#2
Re: Compile Error:Loop Without Do
Welcome to VBForums.
You need a Do to go along with the loop. I’m not sure where you want it to be but this would compile:
Code:
Do If ((WeekdayName(Weekday(LoanExpiryDate - 1)) = "Saturday") Or (WeekdayName(Weekday(LoanExpiryDate - 1)) = "Sunday") Or (libraryopendate = False)) Then ' no good! either the date we're trying is in a weekend or its when the library is open, add one onto the date and try again LoanExpiryDate = LoanExpiryDate + 1 Else dateok = True End If Loop
-
Mar 8th, 2011, 04:08 PM
#3
Thread Starter
New Member
Re: Compile Error:Loop Without Do
Thank you very much for the reply. is there anyway to PM you on here? perhaps by email? MSN?
-
Mar 8th, 2011, 04:10 PM
#4
Re: Compile Error:Loop Without Do
Beware that it will land you into an endless loop.. ultimately crashing your program.
For it to work successfully, you need to provide some exit condition from the loop
e.g.Code:
'Method 1 Do While (condition) ... Loop 'Method 2 Do ... Loop While (condition) 'Method 3 Do ... If (some condition) Then Exit Do ... Loop
There are more ways, but one of these three should suffice.
-
Mar 8th, 2011, 04:14 PM
#5
Thread Starter
New Member
Re: Compile Error:Loop Without Do
Thanks for the reply Pradeep. Really appreciate it. Check your PM when you get a chance
-
Mar 8th, 2011, 04:32 PM
#6
Re: Compile Error:Loop Without Do
Sorry I don’t answer coding questions via PM. It defeats the purpose of this forum.
Please post your question here and I’ll help you in whatever way I can.
-
Mar 8th, 2011, 04:48 PM
#7
Thread Starter
New Member
Re: Compile Error:Loop Without Do
-
Mar 8th, 2011, 05:04 PM
#8
Re: Compile Error:Loop Without Do
Is this what you’re trying to do?
Code:
Do Until dateok = True ' ok? If ((WeekdayName(Weekday(LoanExpiryDate - 1)) = "Saturday") Or (WeekdayName(Weekday(LoanExpiryDate - 1)) = "Sunday") Or (libraryopendate = False)) Then ' no good! either the date we're trying is in a weekend or its when the library is open, add one onto the date and try again LoanExpiryDate = LoanExpiryDate + 1 Else dateok = True End If Loop