storing values in arrays fom inputbox?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 14
Reputation: asif786 is an unknown quantity at this point 
Solved Threads: 0
asif786 asif786 is offline Offline
Newbie Poster

storing values in arrays fom inputbox?

 
0
  #1
Feb 5th, 2009
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.

  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: storing values in arrays fom inputbox?

 
1
  #2
Feb 5th, 2009
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: storing values in arrays fom inputbox?

 
0
  #3
Feb 6th, 2009
Why not storing them in a List(Of String)?

  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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 147
Reputation: samir_ibrahim is on a distinguished road 
Solved Threads: 16
samir_ibrahim's Avatar
samir_ibrahim samir_ibrahim is offline Offline
Junior Poster

Re: storing values in arrays fom inputbox?

 
0
  #4
Feb 6th, 2009
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?
  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)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC