Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Help please!

 
0
  #1
Dec 15th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Help please!

 
0
  #2
Dec 15th, 2008
Hi,

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

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: Help please!

 
0
  #3
Dec 15th, 2008
i dont know how to solve it in vb codes
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: Help please!

 
0
  #4
Dec 15th, 2008
i dont know how to use that in vb codes using loop
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Help please!

 
0
  #5
Dec 15th, 2008
Hi,

Try this :
  1. Dim x As Integer
  2. Dim n As Integer
  3. Dim i As Integer
  4. Dim Tot As Double
  5. x = val(text1.text)
  6. n = val(Text2.text)
  7. If n <=0 Or x <1 Then
  8. MsgBox "Enter Proper Values"
  9. Exit Sub
  10. End If
  11. Tot = 0
  12. For i = 1 To n
  13. Tot = Tot + (x ^ i)
  14. Next
  15. MsgBox Tot

Regards
Veena
Last edited by QVeen72; Dec 15th, 2008 at 8:35 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: Help please!

 
0
  #6
Dec 15th, 2008
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
Last edited by ryan311; Dec 15th, 2008 at 9:33 am. Reason: forgot
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Help please!

 
0
  #7
Dec 16th, 2008
Hi,

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

  1. Dim x As Integer
  2. Dim n As Integer
  3. Dim i As Integer
  4. Dim Tot As Double
  5. x = Val(text1.text)
  6. n = Val(Text2.text)
  7. If n <=0 Or x <1 Then
  8. MsgBox "Enter Proper Values"
  9. Exit Sub
  10. End If
  11. Tot = 0
  12. For i = 1 To n
  13. Tot = Tot + (x ^ i)
  14. Next
  15. For i = 0 To (n +1)
  16. Tot = Tot - (x ^ i)
  17. Next
  18. MsgBox Tot


OR in One statement
  1. Tot = - (x ^ (n+1)) + 1
  2. MsgBox Tot

Regards
Veena
Last edited by QVeen72; Dec 16th, 2008 at 1:36 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: Help please!

 
0
  #8
Dec 16th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: Help please!

 
0
  #9
Dec 16th, 2008
maam veena please? badly needed
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Help please!

 
0
  #10
Dec 16th, 2008
Hi,

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

Regards
Veena
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC