Меню

Loop without do ошибка vba

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

Community's user avatar

asked Dec 9, 2013 at 16:58

Felix Castor's user avatar

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 Student's user avatar

Gary’s StudentGary’s Student

94.9k9 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

Makah's user avatar

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's user avatar

slavoo

5,64864 gold badges36 silver badges39 bronze badges

answered Sep 21, 2017 at 5:11

user8646115's user avatar

zzoommmmmm

0 / 0 / 0

Регистрация: 13.12.2011

Сообщений: 6

1

13.12.2011, 17:58. Показов 6754. Ответов 3

Метки нет (Все метки)


Найти первый отрицательный член последовательности cos(ctg(n)) для n изменяющегося следующим образом: n = 1, 2, 3, … .

Visual Basic
1
2
3
4
5
6
7
8
9
10
11
12
13
Sub Tim()
Dim n As Integer
Dim Y As Integer
n = 1
Do
    Y = Cos(1 / Tan(n))
    If Y < 0 Then
    Debug.Print "n="; n, "Y="; Y: GoTo M
    Else
    n = n + 1
Loop While Y >= 0
M:     End If
End Sub

Помогите исправить код, пишет ошибку «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(&quot;serial&quot;)…

В строке все буквы «а» заменить буквой «б» и наоборот, если они есть
В строке все буквы &quot;а&quot; заменить буквой &quot;б&quot; и наоборот, если они есть

Составьте программу, выясняющую, есть ли в слове Х хотя бы одна из букв «о» или «а»
1. Составьте программу, выясняющую, есть ли в слове Х хотя бы одна из букв &quot;о&quot; или &quot;а&quot;.
2….

Выясните, есть ли в слове X хотя бы одна из букв «к» или «м»
Выясните, есть ли в слове X хотя бы одна из букв &quot;к&quot; или &quot;м&quot;.

3

es geht mir gut

11264 / 4746 / 1183

Регистрация: 27.07.2011

Сообщений: 11,437

13.12.2011, 18:20

2

11 и 12 строку поменяй местами, у меня был точно такой же случай.
А в 8 поставь не Go To M, а Exit Do



1



Alex77755

11464 / 3757 / 675

Регистрация: 13.02.2009

Сообщений: 11,097

13.12.2011, 18:25

3

Цитата
Сообщение от SoftIce.net
Посмотреть сообщение

11 и 12 строку поменяй местами, у меня был точно такой же случай.
А в 8 поставь не Go To M, а Exit Do

Вообще убери. Уже есть условие

Visual Basic
1
While Y >= 0



1



0 / 0 / 0

Регистрация: 13.12.2011

Сообщений: 6

13.12.2011, 18:25

 [ТС]

4

Цитата
Сообщение от SoftIce.net
Посмотреть сообщение

11 и 12 строку поменяй местами, у меня был точно такой же случай.
А в 8 поставь не Go To M, а Exit Do

Спасибо, помогло)



0



IT_Exp

Эксперт

87844 / 49110 / 22898

Регистрация: 17.06.2006

Сообщений: 92,604

13.12.2011, 18:25

Помогаю со студенческими работами здесь

Выясните, есть ли в слове Х хотя бы одна из букв «о» или «а»
№1) Выясните, есть ли в слове Х хотя бы одна из букв &quot;о&quot; или &quot;а&quot;.

Дана строка, состоящая из слов, разделенных пробелом. Определить количество слов, в которых есть хотя бы одна буква «а», или «А»
Дана строка, состоящая из слов, разделенных пробелом. Определить количество слов, в которых есть…

Непонятная ошибка » For loop control variable must have ordinal type»
unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,…

Патерн «прототип» не работает, выдаёт ошибку «недопустимый вызов нестатической ф-ции», где я в коде ошибка?
Вот мой код…

#include &lt;iostream&gt;
#include &lt;Windows.h&gt;
#include &lt;vector&gt;
#define vrom…

Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:

4

  • Remove From My Forums
  • Question

  • I keep getting a compile error using a Do…Loop or While…Wend saying «Loop without a Do» or «Wend without a while.» Is there a limit as to how many statements you can have in the loop or something?  I am at a complete loss!  Here is what I have:

    Sub CreateTask()
    r = 9
    sysdate = Date
    While Cells(r, 40).Value <> «»
        processor = Cells(r, 40).Value
        CheckExclude
        ‘— Search column ‘AN’ for user input—
        If processor <> «» Then
           GetBorrowerInfo
            LastCall = Cells(r, 11).Value
            If Cells(r, 7).Value > sysdate + 40 Then
                If LastCall >= 5 Then
                   CreateTaskItem
                End If
            Else
                If LastCall >= 3 Then
                   CreateTaskItem
            End If
        End If
        r = r + 1
        borrower = «»
        loannumber = «»
        LastCall = «»
        MLSEmail = «»
    Wend
    End Sub

Answers

  • I think that it is just an «End If» that you are missing.

    Here, I have marked the missing End If with ——->:

        If processor <> «» Then
           GetBorrowerInfo
            LastCall = Cells(r, 11).Value
            If Cells(r, 7).Value > sysdate + 40 Then
                If LastCall >= 5 Then
                   CreateTaskItem
                End If
            Else
                If LastCall >= 3 Then
                   CreateTaskItem

    ——-> End If
            End If
        End If

  1. Mar 8th, 2011, 03:27 PM


    #1

    tribeorange is offline

    Thread Starter


    New Member


    Resolved [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


  2. 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


  3. Mar 8th, 2011, 04:08 PM


    #3

    tribeorange is offline

    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?


  4. 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.


  5. Mar 8th, 2011, 04:14 PM


    #5

    tribeorange is offline

    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


  6. 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.


  7. Mar 8th, 2011, 04:48 PM


    #7

    tribeorange is offline

    Thread Starter


    New Member


    Re: Compile Error:Loop Without Do


  8. 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


0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Look it rains ошибка
  • Localhost выдает ошибку 404