DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   Please Help! (http://www.daniweb.com/forums/thread162563.html)

ryan311 Dec 16th, 2008 10:33 am
Please Help!
 
can anyone change this for next statement to do while statement?

Dim x, n, i As Integer
Dim Tot As Double
x = Val(Text1.Text)
n = Val(Text2.Text)
If n <= 1 Or x < 0 Then
MsgBox "Enter Proper Values", vbCritical
Exit Sub
End If
Tot = 0
For i = 1 To n
Tot = Tot + (x ^ i)
Next

Label1.Caption = Tot

aktharshaik Dec 16th, 2008 10:39 am
Re: Please Help!
 
    Dim x, n, i As Integer
    Dim Tot As Double

    x = Val(Text1.Text)
    n = Val(Text2.Text)
    If n <= 1 Or x <= 0 Then
        MsgBox "Enter Proper Values", vbCritical
        Exit Sub
    End If

    Tot = 0
    i = 1
    Do While i <=  n
        Tot = Tot + (x ^ i)
        i = i + 1
    Loop


All times are GMT -4. The time now is 4:24 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC