Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Pass Textbox value to Listbox using for loop in vb.net
Here Textbox value will store on some array variable
Am using:
For i=0 to val(textbox1.text)
 'here val(textbox1.text) denote no.of values can pass to listbox
-
-
-
-
next i

pls send me correct code...
Posted
Updated 7-Dec-11 0:03am
v2
Comments
Sergey Alexandrovich Kryukov 7-Dec-11 10:25am    
The question makes no sense as it is not explained what should be the result of it. And why.
--SA
hari301 7-Dec-11 11:25am    
Add entries from textbox to listbox.

1 solution

VB
Dim i As Integer
For i = 1 To TextBox1.Text
    ListBox1.Items.Add(CType(i, String))
Next
 
Share this answer
 
Comments
hari301 7-Dec-11 12:28pm    
Public Class exam
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n As String = txt_theory.Text 'get i/p from user for no.of times
Dim temp As String = txt_theoryent.Text 'get data from user
Dim i As Integer
For i = 1 To n
lst_theory.Items.Add(CType(temp, String))
Next i
End Sub

This is my code. For loop was not working. pls correct it.
I am using 2 textbox, 1 listbox, 1 button.
for eg:
Textbox1 = Enter the no.of subjects
Textbox2 = Enter 1 subject & Add to listbox by press button.
repeat this subject entry upto textbox1 value..
Hernan K. Cabrera 7-Dec-11 12:39pm    
Hi hari301,

Im just curious.

Why do you have to create a for-loop? You only have 1 textbox for the subject and when you press the button there's only 1 value in that textbox.
hari301 7-Dec-11 12:43pm    
That Textbox is common. Use single textbox with multiple entry to add item in listbox. Tats y using for loop.

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