473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Looping character or number visual basic 6

12
Hi all,
Sorry im beginer in vb.
I want making programm looping character or number.
Just say i have numbers from 100 to 10000.

just sample:

Private Sub Timer1_Timer()

if check1.value= 1 then
for i = 100 to 10000
text1.text= i
next i
end if

end sub

but this looping not like i wanted,

I want all number until the end will be display on text1.text, not just the last number 10000. We can see what the value on text1.text when looping running.
If value of i = 10000 then repeat again from the begining until check box value=0,

when click check box the looping stop, the result text1 can be = 100 or 500 or 300 or 9000 or etc..

any suggestion or code script else?...
please help..

thanks in advance
Jul 12 '07 #1
20 2791
hariharanmca
1,977 1GB
Hi all,
Sorry im beginer in vb.
I want making programm looping character or number.
Just say i have numbers from 100 to 10000.

just sample:

Private Sub Timer1_Timer()

if check1.value= 1 then
for i = 100 to 10000
text1.text= i
next i
end if

end sub

but this looping not like i wanted,

I want all number until the end will be display on text1.text, not just the last number 10000. We can see what the value on text1.text when looping running.
If value of i = 10000 then repeat again from the begining until check box value=0,

when click check box the looping stop, the result text1 can be = 100 or 500 or 300 or 9000 or etc..

any suggestion or code script else?...
please help..

thanks in advance

So u can use


Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2. text1.text = ""
  3. if check1.value= 1 then
  4. for i = 100 to 10000
  5. text1.text = text1.text & "  " & i
  6. next i
  7. end if
  8.  
  9. end sub
this will help u
Jul 12 '07 #2
Killer42
8,435 Expert 8TB
Actually Ifoel, I think your original code will work, if you put a DoEvents statement inside the loop. This allows Windows to take time out to do other things, like updating the display.

(You might also need to Refresh the form, but I don't think so.)
Jul 12 '07 #3
Ifoel
12
Thanks alot Killer42 and Hariharanmca...........
this very help full
.....
Jul 13 '07 #4
hariharanmca
1,977 1GB
So u can use


Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2. text1.text = ""
  3. if check1.value= 1 then
  4. for i = 100 to 10000
  5. text1.text = text1.text & "  " & i
  6. next i
  7. end if
  8.  
  9. end sub
this will help u


I don't have VB in my system so i cannot test tat so i'm giving hint tatsall....
Jul 13 '07 #5
Ifoel
12
Hi Hariharanmca
thanks for u reply...
My original code has corect, like Killer42 said. I just add DoEvents in loop.
now i get trouble, when i click check box for stop looping, why looping still running. and value of Text1.text always 10000.
i have put code when value check1 box = 0, timer1.enable=false.
why this haven?. how to directly stop looping when timer1 false?
so i can get value on text1.text like i wish..
i mean when looping running and on value text1.text box=500 when i press check1 box to stop looping should be value text1.text=500 not 10000.

any idea or script else?
thanks in advance
Jul 13 '07 #6
hariharanmca
1,977 1GB
Hi Hariharanmca
thanks for u reply...
My original code has corect, like Killer42 said. I just add DoEvents in loop.
now i get trouble, when i click check box for stop looping, why looping still running. and value of Text1.text always 10000.
i have put code when value check1 box = 0, timer1.enable=false.
why this haven?. how to directly stop looping when timer1 false?
so i can get value on text1.text like i wish..
i mean when looping running and on value text1.text box=500 when i press check1 box to stop looping should be value text1.text=500 not 10000.

any idea or script else?
thanks in advance

Can u explain your exact requirement....so tat I can give some other suggestion? Because you cannot stop when timer enabled is false. Because it’s just like another thread
Jul 13 '07 #7
Ifoel
12
Ok thanks Hariharanmca...
I just want make programm like LOTTRE do u know LOTTRE.. ..mmm to defficult to say...cos my english so poor...

I just 1 winning or 1 value in text1.text from looping run, not all number from 100 to 10000 display on text1.tex.

when i click check box value= 1 then looping on, If check1 box = 0 looping off

this sample:

Private Sub Check1_Click()

If Check1.Value = 1 Then
Timer1.Enabled = True
ElseIf check1.value=0 then
Timer1.Enabled = False
End If

End Sub

Private Sub Form_Load()
timer1.interval=10
End sub

Private Sub Timer1_Timer()
For j = 100 To 10000
DoEvents
Text1.Text = j
Next j
End Sub

this code has correct, the problem is, when looping run
and on text1.text=500 shown i click check1 box to stop looping . and i want the winning is number 500, but value of text1.text always shown 10000. cos looping still run event i click check1 box to put value=0. whay this haven Hariharanmca?
do u have sugesstion?
Jul 13 '07 #8
hariharanmca
1,977 1GB
Ok thanks Hariharanmca...
I just want make programm like LOTRE do u know LOTRE.. ..mmm to defficult to say...cos my english so poor...

I just 1 winning or 1 value in text1.text when looping run, not all number from 100 to 10000 display on text1.tex.

when i click check box value= 1 then looping on, If check1 box = 0 stop looping

this sample:

Private Sub Check1_Click()

If Check1.Value = 1 Then
Timer1.Enabled = True
ElseIf check1.value=0 then
Timer1.Enabled = False
End If

End Sub

Private Sub Form_Load()
timer1.interval=10
End sub

Private Sub Timer1_Timer()
For j = 100 To 10000
DoEvents
Text1.Text = j
Next j
End Sub

this code has correct, the problem is, when looping run
and on text1.text=500 shown i click check1 box to stop looping . and i want the winning is number 500, but value of text1.text always shown 10000. cos looping still run event i click check1 box to put value=0. whay this haven Hariharanmca?
do u have sugesstion?



1 Enable the timer to true in Properties
2.Set the timer interval to 10 or 20 for random speed

take the code below





Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.     If Check1.Value = 1 Then
  3.         For j = 100 To 10000
  4.             DoEvents
  5.             Text1.Text = j
  6.         Next j
  7.     End if
  8. End Sub

(No VB in my system. Code not tested)
Jul 13 '07 #9
Killer42
8,435 Expert 8TB
I think perhaps you have misunderstood how the timer works. When the timer fires, it will start running the code in your Timer event procedure. From that point on, the time is irrelevant. It just works through the code until it finishes, or gets kicked out of the routine or whatever. So, in this case your code effectively says "if the check box is checked, then go and do all of this". If you want it to do something different along the way, based on the checkbox value, you have to code it that way.

The secret to all this is to learn to think like a computer. In other words, stupid!

I'm serious - computers are completely stupid. They don't do what you want them to do. They do precisely what they are told to do, one step at a time. Where people always go wrong is in trying to think sensibly about their code. Computers are not sensible - they just follow instructions. To understand what your code will do, you have to follow it statement by statement, without jumping to conclusions and making assumptions.

Your code says to count from 100 to 10,000 so that's what it does. There's nothing in there that says to stop, for any reason.

If you want it to stop when you "turn off" the checkbox, I'd say there are two basic approaches you could take:
  1. Do one step each time the timer control fires, if the checkbox is checked.
  2. Do it all in one go as you have in your original post, but add some code inside the loop to exit if the checkbox is not set. This would be the simpler method to implement, since it's only a small change to your existing code.
Jul 13 '07 #10
Killer42
8,435 Expert 8TB
1 Enable the timer to true in Properties
2.Set the timer interval to 10 or 20 for random speed
take the code below
Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.     If Check1.Value = 1 Then
  3.         For j = 100 To 10000
  4.             DoEvents
  5.             Text1.Text = j
  6.         Next j
  7.     End if
  8. End Sub
This still suffers from the original problem, which is that you are saying "if the checkbox is checked, do everything. Otherwise, do nothing". What you need to do is stop when the checkbox value changes. See my prior post. (Sorry, it took quite a while to type.)
Jul 13 '07 #11
Ifoel
12
Yes Killer42...u r correct..
i have put code like
still not work

Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.     If Check1.Value = 1 Then
  3.         For j = 100 To 10000
  4.             DoEvents
  5.             Text1.Text = j
  6.         Next j
  7.     End if
  8. End Sub
so whould u give me some code Killer42
to stop loop when i checked=0.

thanks in advance
Jul 13 '07 #12
hariharanmca
1,977 1GB
This still suffers from the original problem, which is that you are saying "if the checkbox is checked, do everything. Otherwise, do nothing". What you need to do is stop when the checkbox value changes. See my prior post. (Sorry, it took quite a while to type.)
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim intDisplay as integer
  3.  
  4. Private Sub Timer1_Timer()
  5.     If Check1.Value = 1 Then
  6.         if intDisplay > 10000 then intDisplay = 99
  7.         intDisplay = intDisplay + 1
  8.         Text1.Text = intDisplay
  9.     End if
  10. End Sub
  11.  
  12. Private Sub Check1_Click()
  13.     intDisplay = 100
  14. End Sub
(Not Tested)

i think this will work
Jul 13 '07 #13
hariharanmca
1,977 1GB
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim intDisplay as integer
  3.  
  4. Private Sub Timer1_Timer()
  5.     If Check1.Value = 1 Then
  6.         if intDisplay > 10000 then intDisplay = 99
  7.         intDisplay = intDisplay + 1
  8.  
  9.         Text1.Text = intDisplay
  10.     End if
  11. End Sub
  12.  
  13. Private Sub Check1_Click()
  14.     intDisplay = 100
  15. End Sub
(Not Tested)

i think this will work

my request, i want to know the out put or this code. can any 1 test it and reply

(I don't have VB in my system).
Jul 13 '07 #14
Killer42
8,435 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.     If Check1.Value = 1 Then
  3.         For j = 100 To 10000
  4.             DoEvents         ' You should swap this line...
  5.             Text1.Text = j   ' ...and this line.
  6.         Next j
  7.     End if
  8. End Sub
so whould u give me some code Killer42
to stop loop when i checked=0.
Nope. :)

But I'll tell you how you can do it. First of all, I'd recommend reversing the order of the DoEvents and the Text1.Text = j - but that's unrelated.

Inside your loop, just code "if checkbox is not checked, escape from the loop". I'd prefer you do the translation from English to VB. It's fairly straightforward. Hint, you want to Exit from the For loop.
Jul 13 '07 #15
hariharanmca
1,977 1GB
Nope. :)

But I'll tell you how you can do it. First of all, I'd recommend reversing the order of the DoEvents and the Text1.Text = j - but that's unrelated.

Inside your loop, just code "if checkbox is not checked, escape from the loop". I'd prefer you do the translation from English to VB. It's fairly straightforward. Hint, you want to Exit from the For loop.

Expand|Select|Wrap|Line Numbers
  1. Dim intDisplay as integer
  2.  
  3. Private Sub Timer1_Timer()
  4.     If Check1.Value = 1 Then
  5.         if intDisplay > 10000 then intDisplay = 99
  6.         intDisplay = intDisplay + 1
  7.         Text1.Text = intDisplay
  8.     End if
  9. End Sub
  10.  
  11. Private Sub Check1_Click()
  12.     intDisplay = 100
  13. End Sub
how about this code
Jul 13 '07 #16
Killer42
8,435 Expert 8TB
how about this code
Yes, that looks like the other option I mentioned. Incrementing each time the timer event fires. For this you would want a pretty small timer interval.
Jul 13 '07 #17
hariharanmca
1,977 1GB
Yes, that looks like the other option I mentioned. Incrementing each time the timer event fires. For this you would want a pretty small timer interval.
Yha, Whatever I mention above for properties.

is that code working fine?
Jul 13 '07 #18
Killer42
8,435 Expert 8TB
I haven't had a chance to try it. But it looks alright.
Jul 13 '07 #19
Ifoel
12
sorry hariharanmca..
not work
when looping run the resul text1.text =1
just it... and stop and looping not run again even check1 value =1
Jul 13 '07 #20
hariharanmca
1,977 1GB
sorry hariharanmca..
not work
when looping run the resul text1.text =1
just it... and stop and looping not run again even check1 value =1
Expand|Select|Wrap|Line Numbers
  1. Dim intDisplay as integer
  2.  
  3. Private Sub Timer1_Timer()
  4.     If Check1.Value = 1 Then
  5.         if intDisplay > 10000 then intDisplay = 99
  6.         intDisplay = intDisplay + 1
  7.         Text1.Text = intDisplay
  8.     End if
  9. End Sub
  10.  
  11. Private Sub Check1_Click()
  12.     intDisplay = 100
  13. End Sub

Try this qode
Jul 13 '07 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ={ Advocated }= | last post by:
Hi there, im in need to use a loop, im not sure exactly how to do it :S ######################## /* * File: Payroll.c * Program to calculate the wage of a user */ #include <stdio.h> int...
0
by: Dr. Zharkov | last post by:
To see character of Microsoft Agent in Visual Basic .NET 2003, we create the project: File, New, Project, Visual Basic Project, Windows Application. In Form1 we place two controls: Button and...
0
by: Dr. Zharkov | last post by:
To see character of Microsoft Agent in Visual Basic .NET 2003, we create the project: File, New, Project, Visual Basic Project, Windows Application. In Form1 we place two controls: Button and...
1
by: Dr. Zharkov | last post by:
Hello. In project on Visual Basic .NET 2003 (File, New, Project, Visual Basic Project, Windows Application) after occurrence of Genie of Microsoft Agent and pressing of key Scroll Lock below Genie...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
1
by: Demonicpagan | last post by:
I have this form where I am trying to place items from checked boxes into a text box. An image of what this form looks like is at http://www.stelth2000inc.com/images/screen.png Here is some...
4
by: XpatienceX | last post by:
Hi, Can someone help me with this assignment, I am confused of what is needed to be done here. I am suposed to design a program that models a worm's behavior in the following scenario: A...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
12
by: =?Utf-8?B?TWFyaw==?= | last post by:
I modified a C# application from Bob Powell that moves graphics primitives around on the screen into a Vb.NET 2005 application. I want to modify this application so along with moving regular...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.