Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi i have an application with lot of textboxes to be filled with data from user.My goal for now is to make a dynamic array and with one function to check the inputed data.If the inputed data wont pass some logical "If" (like in date text box the inputed year will be 1867) will be stored in my dynamic array.My question is how to populate the dynamic array in my function with my application variables and how the return statement will be in my application?


VB
With
  objTest.testCode = FrmHeader.txtEOPtestCode.Text 'That's my input
  'In my function
  if objTest.testCode > 100 then
       getvalue into my dynamic array.


Also the main reason for this is to finally call my function before my

VB
Dim objStreamWriter As New StreamWriter (My.Settings.PathToShared & "\Test\Test - Saved.xml")

to get the inputed data before saving in my xml.
Posted
Updated 10-Feb-15 23:01pm
v4

Hi,

Use below Code.

VB
Private Function ValidateControls() As ArrayList
        Dim arrControls As New ArrayList

        'Looping throgh the Controls 
        For Each Cntrl As Control In Me.Controls
            'Here We get all type of controls So we need to isolate 
            'Textbox controls only
            If TypeOf Cntrl Is TextBox Then
                'Check your validation
                ' For example value blank then add into arraylist 
                If Cntrl.Text = "" Then
                    arrControls.Add(Cntrl)
                End If
            End If
        Next
        Return arrControls
    End Function


Let me know for any query. Hope this is helpful for you.

Thanks.!
 
Share this answer
 
Comments
Member 10059109 11-Feb-15 6:29am    
that's perfect my friend only one more question for the returned arraylist.
I have an Streamwriter to store all the data from the text boxes in an xml document
"Dim objStreamWriter As New StreamWriter(My.Settings.PathToShared & "\Arrival\Arrival - Saved.xml")"
i wnt to call my function before the Streamwriter to kick in.So if i am understood correct the only thing i need to do is to call the function before streamwriter like
checkdata= ValidateControls() ?
Hiren Lad 11-Feb-15 6:47am    
Hi.

Please correct me if am going wrong.
You want to make XML file from multiple textboxes?
And Validated Textbox value should be added in XML ? Am i right ?

If i am right then, you need to added all successfully validated textboxes in Arraylist, Call the function first and As we know our function return ArrayList, So you can loop through the returned ArrayList and make XML.

Thanks.
Member 10059109 11-Feb-15 7:11am    
Hi at that state of my app i just wnt to validate all the textboxes with some logical criteria and store the wrong ones in my arraylist that' all.As of my streamreader my only question is that i need to simple call my function like this
checkdata= ValidateControls() before my Dim objStreamWriter As New StreamWriter(My.Settings.PathToShared & "\Arrival\Arrival - Saved.xml")" to store the textboxes in my list correct?
Hiren Lad 11-Feb-15 7:21am    
Ok. You can call the function before declaration of stream reader.

Member 10059109 11-Feb-15 7:28am    
Thank you so much you helped me a lot ,have a nice day good sir!
Use List instead of Array. Much simpler and efficient.
https://msdn.microsoft.com/en-us/library/6sh2ey19%28v=vs.110%29.aspx[^]

Good luck!
 
Share this answer
 
Comments
Member 10059109 11-Feb-15 4:56am    
I wont have any capacity problems with the list correct?
E.F. Nijboer 11-Feb-15 7:07am    
Don't worry about that. Also, ArrayList is untyped and list is more safe and also reccommended. You can use a list in all kinds of situations with all kind of types without the need to convert them back. Much easier and type safe.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900