943,871 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1463
  • VB.NET RSS
Feb 5th, 2009
0

storing values in arrays fom inputbox?

Expand Post »
i have declared an array which i want to populate with names, as they are entered into an input box.It does not seem to work i have tried many other methods with the array but to no success.

VB.NET Syntax (Toggle Plain Text)
  1. Dim namearray() As String
  2. Dim i As Integer
  3.  
  4. name = InputBox("Enter the candidates name:", "candidatename", "", 500, 500)
  5.  
  6. name = namearray(i)
  7. i = i + 1

thanks a lot.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asif786 is offline Offline
19 posts
since Dec 2008
Feb 5th, 2009
1

Re: storing values in arrays fom inputbox?

VB.NET Syntax (Toggle Plain Text)
  1. Dim namearray() As String
  2. Dim NewName As String
  3. Dim i As Integer
  4.  
  5. i = 0
  6. NewName = InputBox("Enter the candidates name:", "candidatename", "", 500, 500)
  7. Do Until String.IsNullOrEmpty(NewName)
  8. ReDim Preserve namearray(i)
  9. namearray(i) = NewName
  10. i += 1
  11. NewName = InputBox("Enter the candidates name:", "candidatename", "", 500, 500)
  12. Loop
Loops until you enter an empty name.
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Feb 6th, 2009
0

Re: storing values in arrays fom inputbox?

Why not storing them in a List(Of String)?

VB.NET Syntax (Toggle Plain Text)
  1. Dim listOfNames As New List(Of String)
  2.  
  3. Private Sub Button1_Click(ByVal sender As System.Object, _
  4. ByVal e As System.EventArgs) Handles Button1.Click
  5.  
  6. Dim newName As String = ""
  7. newName = InputBox("Enter the candidates name:", _
  8. "candidatename", "", 500, 500)
  9. If Not String.IsNullOrEmpty(newName) Then
  10. listOfNames.Add(newName)
  11. End If
  12. BindListbox()
  13. End Sub
  14.  
  15. Private Sub BindListbox()
  16. Me.ListBox1.Items.Clear()
  17. Try
  18. Me.ListBox1.Items.AddRange(listOfNames.ToArray)
  19. Catch ex As Exception
  20. MessageBox.Show(ex.Message)
  21. End Try
  22. End Sub
Last edited by 4advanced; Feb 6th, 2009 at 3:40 am. Reason: typo
Reputation Points: 33
Solved Threads: 10
Junior Poster in Training
4advanced is offline Offline
67 posts
since Nov 2008
Feb 6th, 2009
0

Re: storing values in arrays fom inputbox?

As per the logic of execution your code, if you want to fill the array in let say button_1 click and then use the array in another sub, you have to declare the array in the form declaration not in the same sub. or else you will be able to use that Array?
vb.net Syntax (Toggle Plain Text)
  1. ' Form1 Declaration
  2. Dim aCandidate(0) As String
  3.  
  4. ' sub Button6_Click
  5. Dim I As Integer
  6. I = UBound(aCandidate, 1) + 1
  7. ReDim Preserve aCandidate(I)
  8. aCandidate(I) = InputBox("Enter the candidates name:", "candidatename", "", 500, 500)
Reputation Points: 69
Solved Threads: 19
Junior Poster
samir_ibrahim is offline Offline
155 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: DateTime field - How do I assign a time other than current?
Next Thread in VB.NET Forum Timeline: Reterieve data from mdb and display in listbox





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC