Wait event inside a loop cycle in VB.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nightfarer
    New Member
    • Sep 2007
    • 11

    Wait event inside a loop cycle in VB.NET

    Hello.

    I have this loop started by a button Click event:

    Code:
     For i = 0 To AlphabetArray.GetUpperBound(0)
                AlphabetArray.SetValue(letter, i)
                Alphabet.Lettertxtbox.Clear()
            Next i
    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
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Originally posted by Nightfarer
    Hello.

    I have this loop started by a button Click event:

    Code:
     For i = 0 To AlphabetArray.GetUpperBound(0)
                AlphabetArray.SetValue(letter, i)
                Alphabet.Lettertxtbox.Clear()
            Next i
    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
    Code:
    bool clicked = false
    
    SUB start //the one that handles button clicks
    clicked = !clicked
    if(clicked == true)
    {
    For i = 0 To AlphabetArray.GetUpperBound(0)
                AlphabetArray.SetValue(letter, i)
                Alphabet.Lettertxtbox.Clear()
            Next i
    }
    
    SUB end
    Sorry abt the miix of Vb and C#, hope you know where i come from.
    cheers

    Comment

    • Nightfarer
      New Member
      • Sep 2007
      • 11

      #3
      Originally posted by Shashi Sadasivan
      Code:
      bool clicked = false
      
      SUB start //the one that handles button clicks
      clicked = !clicked
      if(clicked == true)
      {
      For i = 0 To AlphabetArray.GetUpperBound(0)
                  AlphabetArray.SetValue(letter, i)
                  Alphabet.Lettertxtbox.Clear()
              Next i
      }
      
      SUB end
      Hi.

      I rewrote it this way:

      In a module: Public clicked as Boolean

      Code:
      clicked=(Not clicked)
      
      If clicked.Equals(clicked) Then
      For i = 0 To AlphabetArray.GetUpperBound(0)
      AlphabetArray.SetValue(letter, i)
      Alphabet.Lettertxtbox.Clear()
      Next i
      End If
      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.GetUppe rBound(0)
      when i = array.getuppero und(0)
      AddNew button and textbox inactive
      Another button active to proceed

      Hope it's clear.
      Luca

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        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.
        Code:
        char myarray[]=new char[26];
        int myaptr=0;
        Then when the textbox contains text, allow a button click.
        On button click:
        Code:
        myarray[myaptr]=(whatever the character value is);
        myaptr++;
        You will of course want to make sure they don't go over the bounds of the array (in my example: 26)

        Comment

        • Nightfarer
          New Member
          • Sep 2007
          • 11

          #5
          Originally posted by Plater
          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).

          Comment

          • Shashi Sadasivan
            Recognized Expert Top Contributor
            • Aug 2007
            • 1435

            #6
            typo

            i come from a very c# 'ish background but this part of VB i can definitely understand (which you converted)
            Code:
            If clicked.Equals(clicked) Then
            wont this always evaluate to true? :)

            cheers

            Comment

            • Nightfarer
              New Member
              • Sep 2007
              • 11

              #7
              Originally posted by Shashi Sadasivan
              i come from a very c# 'ish background but this part of VB i can definitely understand (which you converted)
              Code:
              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.

              Comment

              • Nightfarer
                New Member
                • Sep 2007
                • 11

                #8
                Originally posted by Nightfarer
                but changing it still doesn't solve my silly issue.
                Finally done, now it fully works as expected.

                Comment

                • Shashi Sadasivan
                  Recognized Expert Top Contributor
                  • Aug 2007
                  • 1435

                  #9
                  I hope it wasnt a silly error... :D
                  Cheers

                  Comment

                  • Nightfarer
                    New Member
                    • Sep 2007
                    • 11

                    #10
                    Originally posted by Shashi Sadasivan
                    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.

                    Comment

                    Working...