## ryan311 -7

can i anyone know how to solve a summation problem? in visual basic?
using do while? or do until?

here's my code

x = val(text1.text)
n = val(Text2.text)
c = text3.text

for example if the input of
x is 3 &
n is 2

therefor solving of that is like this

= 3^1 + 3^2
= 3 + 9
= 12

how can i came up this answer? and what if the value in text2.text or n is 3 so

= 3^1 + 3^2 + 3^3
= 3 + 9 27
= 39

and n shoulde be n>=1
and x>0

## QVeen72 104

Hi,

You can write using any of the LOOP Structures,
so what is the problem..?

Regards
Veena

## ryan311 -7

i dont know how to solve it in vb codes :(

## ryan311 -7

i dont know how to use that in vb codes using loop

## QVeen72 104

Hi,

Try this :

``````Dim x As Integer
Dim n As Integer
Dim i As Integer
Dim Tot As Double
x = val(text1.text)
n = val(Text2.text)
If n <=0 Or x <1 Then
MsgBox "Enter Proper Values"
Exit Sub
End If
Tot = 0
For i = 1 To n
Tot = Tot + (x ^ i)
Next
MsgBox Tot``````

Regards
Veena

## ryan311 -7

thnx problem solve, last question how can i solve this?

N N+1
Xi - Xj
I = 1 j = I - 1

for example i input
in my text1.text value of 3
and text2.text value of 2

3 raised to 1 + 3 raised to 2 minu(-) 3 raised to zero + 3 raised to 1 + 3 raised to 2 + 3 raised to 3

## QVeen72 104

Hi,

Once you know the Logic, you can try playing around with the code.. But any way, here is the code:

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

OR in One statement

``````Tot = - (x ^ (n+1)) + 1
MsgBox Tot``````

Regards
Veena

## ryan311 -7

i have problem can you convert your code using do while or do until because our professor said we only use DO LOOP huhuhu please?

## QVeen72 104

Hi,

Try it yourself....
Post the modified code, if there is problem with the code,

Regards
Veena

## ryan311 -7

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
Do While i = 1 - n
Tot = Tot + (x ^ i)
Loop

Label1.Caption = Tot

the asnwer is 0 huhuhu

## QVeen72 104

Change the value of "i " within the loop

where?

## aktharshaik 16

``````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``````

## ryan311 -7

wow great thank you so much sir! how about this sir i want to convert it into do while

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

## aktharshaik 16

``````Dim x As Integer
Dim n As Integer
Dim i As Integer
Dim Tot As Double

x = Val(text1.text)
n = Val(Text2.text)
If n <=0 Or x <1 Then
MsgBox "Enter Proper Values"
Exit Sub
End If

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