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

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

 
0
  #1
Jan 5th, 2009
hi can anyone help me? because i dont know how to use for next loop i want to make a sample program in vb i have 1 textbox

if i inputted value of 3 in text1.text

it will come up in this answer

1
2
3

then if i click my command button next the next answer should this

4
5
6

next

7
8
9

how can i came up this answeR? using for next loop?

thanks god bless
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: help

 
0
  #2
Jan 5th, 2009
  1. Dim LastNum As Integer
  2.  
  3. Private Sub Command1_Click()
  4. Dim NewNum As Integer
  5. Dim I As Integer
  6.  
  7. If Text1.Text = vbNullString Then
  8. MsgBox "Enter A Value"
  9. Exit Sub
  10. End If
  11.  
  12. NewNum = LastNum + Val((Text1.Text) - 1)
  13.  
  14. Text2.Text = vbNullString
  15. For I = LastNum To NewNum
  16. Text2.Text = Text2.Text & I & " "
  17. Next I
  18.  
  19. LastNum = I
  20.  
  21. End Sub
  22.  
  23. Private Sub Form_Load()
  24. LastNum = 1
  25. End Sub
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

 
0
  #3
Jan 5th, 2009
ahm only 1 textbox sir and if the number reach in 100 it will stop
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: help

 
0
  #4
Jan 5th, 2009
I'm certain that with what you have been provided, you can make the necessary modifications for it to fit your needs. Secondly, how are you meant to show the numbers, if not for a second textbox? A Label?
Last edited by Comatose; Jan 5th, 2009 at 8:52 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

 
0
  #5
Jan 5th, 2009
comatose can u help me about this i have only 1 textbox and 2 command button

this is my code in command1 button
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. Dim x, n
  3. n = Val(Text1.Text)
  4. For x = 1 To n
  5. Print x
  6. Next x
  7. command1.enabled = false
  8. End Sub
the output of my command1 is for example i inputted a value of 3 in my textbox the output should come w/ this

1
2
3

this is the code in my 2nd button
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command2_Click()
  2. Dim x, n
  3. n = Val(Text1.Text)
  4. For x = n + 1 To n * 2
  5. Print x
  6. Next x
  7. End Sub
the output of this is

4
5
6

if i click once again in my 2nd command button the answer is still 456 i want is like this if i click once again my second command button the answer should like this

7
8
9

if i click again

10
11
12

until he reach in 100.
Last edited by Ancient Dragon; Jan 5th, 2009 at 3:23 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: help

 
0
  #6
Jan 5th, 2009
If you check the code I posted, you'll notice that I keep track of the LastNum (Last number) that X had been. You are not doing this. For x = n + 1 To n * 2 If n is always 3, x will always be from 3 to 6. Try it.. replace n with the number in the textbox. The for loop will always produce the same result. You need to somehow keep track of the last number that X was.... sort of like:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. For I = LastNum To NewNum
  2. print I
  3. Next I
  4.  
  5. LastNum = I
Then, you will have to calculate "NewNum" so you know how far you are supposed to loop until NewNum = LastNum + Val((Text1.Text) - 1). Furthermore, LastNum needs to be public (or static, but public is easier in this case).
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

 
0
  #7
Jan 5th, 2009
because the requirements is only 1 textbox thats why it so hard
if i inputted 5 in textbox the output should like this

1
2
3
4
5

then if i click once again it should be like this

6
7
8
9
10

so on. .
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: help

 
0
  #8
Jan 5th, 2009
That is what my initial post does. How about removing the second textbox, and changing it from text2.text = text2.text & i & " " to something like print i
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

 
0
  #9
Jan 5th, 2009
ive tried your code making a 2 texboxt but it still wrong for example in the text1 value = 5

1
2
3
4
5

then if i click once again the answer in the text2 should

6
7
8
9
10

but in your code is still

1
2
3
4
5
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: help

 
0
  #10
Jan 5th, 2009
Then you put Dim LastNum as Integer in the wrong spot Brosive.
Attached Files
File Type: zip FigureIt.zip (1.4 KB, 2 views)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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