473,387 Members | 1,365 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,387 software developers and data experts.

Wait event inside a loop cycle in VB.NET

Hello.

I have this loop started by a button Click event:

Expand|Select|Wrap|Line Numbers
  1.  For i = 0 To AlphabetArray.GetUpperBound(0)
  2.             AlphabetArray.SetValue(letter, i)
  3.             Alphabet.Lettertxtbox.Clear()
  4.         Next i
  5.  
The loop must wait another Click event (preceeded by a user passed value (letter) in a textbox) to continue; actually the loop assigns the same letter to all array length.
It's the first time I develop a user driven software (all the previous were fully automated ones) so I'm having a probably such silly issue but I can't figure it out how to manage the wait.

Thanks in advance,
Luca
Sep 13 '07 #1
9 5635
Shashi Sadasivan
1,435 Expert 1GB
Hello.

I have this loop started by a button Click event:

Expand|Select|Wrap|Line Numbers
  1.  For i = 0 To AlphabetArray.GetUpperBound(0)
  2.             AlphabetArray.SetValue(letter, i)
  3.             Alphabet.Lettertxtbox.Clear()
  4.         Next i
  5.  
The loop must wait another Click event (preceeded by a user passed value (letter) in a textbox) to continue; actually the loop assigns the same letter to all array length.
It's the first time I develop a user driven software (all the previous were fully automated ones) so I'm having a probably such silly issue but I can't figure it out how to manage the wait.

Thanks in advance,
Luca
Expand|Select|Wrap|Line Numbers
  1. bool clicked = false
  2.  
  3. SUB start //the one that handles button clicks
  4. clicked = !clicked
  5. if(clicked == true)
  6. {
  7. For i = 0 To AlphabetArray.GetUpperBound(0)
  8.             AlphabetArray.SetValue(letter, i)
  9.             Alphabet.Lettertxtbox.Clear()
  10.         Next i
  11. }
  12.  
  13. SUB end
  14.  
Sorry abt the miix of Vb and C#, hope you know where i come from.
cheers
Sep 13 '07 #2
Expand|Select|Wrap|Line Numbers
  1. bool clicked = false
  2.  
  3. SUB start //the one that handles button clicks
  4. clicked = !clicked
  5. if(clicked == true)
  6. {
  7. For i = 0 To AlphabetArray.GetUpperBound(0)
  8.             AlphabetArray.SetValue(letter, i)
  9.             Alphabet.Lettertxtbox.Clear()
  10.         Next i
  11. }
  12.  
  13. SUB end
  14.  
Hi.

I rewrote it this way:

In a module: Public clicked as Boolean

Expand|Select|Wrap|Line Numbers
  1. clicked=(Not clicked)
  2.  
  3. If clicked.Equals(clicked) Then
  4. For i = 0 To AlphabetArray.GetUpperBound(0)
  5. AlphabetArray.SetValue(letter, i)
  6. Alphabet.Lettertxtbox.Clear()
  7. Next i
  8. End If
  9.  
But it behaves the same way as before: AddNew button is active only if textbox.text is <> ""; click AddNew button; loop starts and value added via textbox is added to all array length (confirmed using MessageBox to get values of array).
The loop must work this way:
ArrayCreated[...],[...],[...],etc...
AddNew button inactive until textbox text is ""
AddNew button click
Loop starts and set value passed via textbox to array: Array[a],[...],[...], etc...
textbox text cleared
AddNew button inactive until textbox text is ""
loop waits
user types new value in textbox
AddNew button click
loop restarts: new value typed is added to Array[a],[b],[...],etc...
loop waits
user types new value in textbox
AddNew button click
loop restarts: new value typed is added to Array[a],[b],[c],etc...
this until i=Array.GetUpperBound(0)
when i = array.getupperound(0)
AddNew button and textbox inactive
Another button active to proceed

Hope it's clear.
Luca
Sep 13 '07 #3
Plater
7,872 Expert 4TB
Why not have the array created before hand?

Create array of correct size.
Create a pointer to the first index of the array.
i.e.
Expand|Select|Wrap|Line Numbers
  1. char myarray[]=new char[26];
  2. int myaptr=0;
  3.  
Then when the textbox contains text, allow a button click.
On button click:
Expand|Select|Wrap|Line Numbers
  1. myarray[myaptr]=(whatever the character value is);
  2. myaptr++;
  3.  
You will of course want to make sure they don't go over the bounds of the array (in my example: 26)
Sep 13 '07 #4
Why not have the array created before hand?
Hi, I simplified the loop just to let understand; the array in created when this form loads and has not a fixed size but the size is passed by the user (the software does and handles more than this - it's just the only thing I never figured out up-to-now).

Anyway I'm still stuck at the wait handle inside loop.
It's the first time I develop a user-driven software so there are things I never used before (like this waiting-event-passed-by-user loop).
Sep 13 '07 #5
Shashi Sadasivan
1,435 Expert 1GB
i come from a very c# 'ish background but this part of VB i can definitely understand (which you converted)
Expand|Select|Wrap|Line Numbers
  1. If clicked.Equals(clicked) Then
wont this always evaluate to true? :)

cheers
Sep 13 '07 #6
i come from a very c# 'ish background but this part of VB i can definitely understand (which you converted)
Expand|Select|Wrap|Line Numbers
  1. If clicked.Equals(clicked) Then
wont this always evaluate to true? :)

cheers
Hi.

But it refers to

if( clicked == true). The == operator is equals... anyway you're right, I made in mistake rewriting from C# to VB on that line (I caught it later because in the meantime I added other functionalities and rewrote other functions and subroutines), but changing it still doesn't solve my silly issue.
Sep 14 '07 #7
but changing it still doesn't solve my silly issue.
Finally done, now it fully works as expected.
Sep 14 '07 #8
Shashi Sadasivan
1,435 Expert 1GB
I hope it wasnt a silly error... :D
Cheers
Sep 14 '07 #9
I hope it wasnt a silly error... :D
Cheers
Not so much silly (I rewrote some routines but not the loop itself), but I meant silly because it should be normal for developers to handle the user input while I never had the need because of other type of software I always developed.
Sep 14 '07 #10

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

Similar topics

2
by: Aggelos | last post by:
Hi Guys!!! Thanks in advance for any kind of help about this problem. The problem: Acces Database One Table 'Orders' and second 'OrderItems' I want to export in txt file using FSO and...
5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
5
by: Waleed AlRashoud | last post by:
Hi, I hope u can help me I asked this question before but I didn't explain it very well. Let say I hvae a thread 'A', creates object 'O', and start thread 'B' to do some work on 'O', OK? I...
1
by: Ravi | last post by:
Hi, I have a radio button list and a dropdownlist inside a repeater control. Want to hide or display the dropdownlist based on selection in radiobuttonlist. I can add the...
4
by: Bishop | last post by:
I can't get my button event to fire inside a table. the button outside of the table works. Both make a postback. Any help appreciated. My code below. (Add button to page)
3
nirmalsingh
by: nirmalsingh | last post by:
hai all, i have added a dropdownlist control inside a datagridview by datagridview.controls.add method, now i want fire the event of dropdownlist, but when i try it, event of datagridview is firing....
4
by: raylopez99 | last post by:
See comment below. This is a simple problem but I'm a little rusty. How to break out of a event loop (here _Paint)? I've tried if/else, case, etc but not quite what I want--I keep getting the JIT...
4
by: xend | last post by:
Hi. I want to add an event handler inside a function that will be used has an object constructor. The event handler to be added is an "method" of the object. if i do this: function...
2
by: andrux | last post by:
Hi, I'm having a hard time by trying and decipher this one. I tried googling around but couldn't come up with an answer (may be I just don't know the proper search terms) I wrote a custom...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.