Question [SOLVED] Button.Click Event inside a function

12aon

New member
Joined
Nov 4, 2010
Messages
3
Programming Experience
Beginner
Hi,

I'm fairly new to programming and VB.NET and am still struggeling with the way things work every now and again. Most thing are easily found on the net, but some aren't.

Background:
I created a function that retrieves information on which checkboxes are checked. It returns an array which the information coupled to the checking of those checkboxes. Those checkboxes and the matching textboxes are dynamically created at runtime in that same function. I'm pausing the application to wait for a button to be pressed. I'm trying to find a way to use btnDone.Click event directly because the code always reloops my function once more recreating the controls.


VB.NET:
    Public Function GetArray(ByVal strDLFolder As String) As Array

 
        If blnDone = False Then
 
            Me.Show()

        ...


        'Create controls here
        
        ...


        Dim intNumber As Integer

        Dim CheckedArray() As String
        'AddHandler btnSubDone.Click, AddressOf btnDoneClicked

 
        intNumber = -1
 
        Do Until (blnDone = True)
            Application.DoEvents()

        Loop
 
        ReDim CheckedArray(intArray)
 
        For i = 0 To intArray

            If ckbSubAdd(i).Checked = True Then
 
                intNumber = intNumber + 1
                CheckedArray(intNumber) = strFullPath(i)

 
 
            End If
        Next
 
        VideoMover.Visible = True

        blnDone = False
 
        Return CheckedArray
 
        Me.Close()
 
    End Function


    Public Sub btnSubDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubDone.Click

        blnDone = True
        Me.Visible = False
 
    End Sub
Right now I'm setting a create a boolean switch when btnSubDone is clicked. What I would like is for something along the lines of:
VB.NET:
        Do Until (btnSubDone.Click = True) 'The code is obviously wrong, It's meant to display what goes on in my mind
            
                Application.DoEvents()

        Loop

Is it possible to use events like this? If not is there a cleaner way for pausing the application to wait for a button click (one that doesn't run the entire function again)? Any help would be appreciated.

Thanks in advance
 
Declare a Boolean variable on the Form's scope and set its state on the click event of the button. Later, on the loop you can check the status of this variable.
VB.NET:
    Dim btnSubDoneClicked As Boolean = False 'Delcare it on Form's scope.
   
    Private Sub btnSubDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubDone.Click
		
		btnSubDoneClicked = True
   
    End Sub
 
Declare a Boolean variable on the Form's scope and set its state on the click event of the button. Later, on the loop you can check the status of this variable.
VB.NET:
    Dim btnSubDoneClicked As Boolean = False 'Delcare it on Form's scope.
   
    Private Sub btnSubDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubDone.Click
		
		btnSubDoneClicked = True
   
    End Sub

Thank you it turned out to be a user problem. I had set a boolean value set at the biginning of the forms class (public property blnDone). I decided to check if the form was visibke as I set it to visible to false when the button was clicked.

As it turns out I called the function twice (I relocated the call earlier and forgot the delete it) which was causing the form to come up a second time.

Thanks for your time, I'll mark the thread n00b.. err I mean solved.

Sent from my HTC HD2 using Tapatalk
 
Back
Top