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

Hi,

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

Regards
Veena

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

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

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

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

the answer should -28

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

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?

maam veena please? badly needed :(

Hi,

Try it yourself....
Post the modified code, if there is problem with the code,
we will be glad to help you.

Regards
Veena

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

Change the value of "i " within the loop

where?

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

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.