| | |
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2008
Posts: 161
Reputation:
Solved Threads: 1
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
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
vb Syntax (Toggle Plain Text)
Dim LastNum As Integer Private Sub Command1_Click() Dim NewNum As Integer Dim I As Integer If Text1.Text = vbNullString Then MsgBox "Enter A Value" Exit Sub End If NewNum = LastNum + Val((Text1.Text) - 1) Text2.Text = vbNullString For I = LastNum To NewNum Text2.Text = Text2.Text & I & " " Next I LastNum = I End Sub Private Sub Form_Load() LastNum = 1 End Sub
•
•
Join Date: Jul 2008
Posts: 161
Reputation:
Solved Threads: 1
comatose can u help me about this i have only 1 textbox and 2 command button
this is my code in command1 button
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
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.
this is my code in command1 button
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command1_Click() Dim x, n n = Val(Text1.Text) For x = 1 To n Print x Next x command1.enabled = false End Sub
1
2
3
this is the code in my 2nd button
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command2_Click() Dim x, n n = Val(Text1.Text) For x = n + 1 To n * 2 Print x Next x End Sub
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
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.
Then, you will have to calculate "NewNum" so you know how far you are supposed to loop until
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)
For I = LastNum To NewNum print I Next I LastNum = I
NewNum = LastNum + Val((Text1.Text) - 1). Furthermore, LastNum needs to be public (or static, but public is easier in this case). 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 ![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: showing record on the report
- Next Thread: Online Examination
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows







thats why it so hard