Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Programming/c++/vb, Hello, do you program? Know anything about programming? Are a programm
iAlter
post Jan 19 2007, 10:40 PM
Post #1


Newbie
*

Group: Members
Posts: 6
Joined: 19-January 07
Member No.: 37,491



Hey, I am learning Visual Basic and it's pretty fun. Are you a programmer? Do you program? Here is some line of code from VB I made for an example:
What you need
QUOTE
| Name
ListBox | List1
TextBox | Text1
TextBox | Text2
Command Button | Command1
Command Button | Command2
Command Button | Command3
Command Button | Command4
-----------
Actual Code:
---
'Start Code
Private Sub Command1_Click()
'This will check if there is anything in Text1 and stop if there isn't, but if there is it will add the text in Text1 to the listbox
If Text1.Text = vbNullString Then
MsgBox "Please enter a value for the string to add!", vbInformation + vbOKOnly, "Error"
Exit Sub
End If
List1.AddItem Text1.Text
End Sub

Private Sub Command2_Click()
'This will remove the item in the listbox, if it is at an index
If List1.ListIndex < 0 Then
Exit Sub
End If

List1.RemoveItem List1.ListIndex
End Sub

Private Sub Command3_Click()
'This will navigate to the item
Dim i As Integer
For i = 0 To List1.ListCount - 1
If Text2.Text = List1.List(i) Then
List1.ListIndex = i
End If
Next
End Sub


Private Sub Command4_Click()
'This will remove the found item
Dim i As Integer
For i = 0 To List1.ListCount - 1
If Text2.Text = List1.List(i) Then
List1.RemoveItem i
End If
Next
End Sub


Private Sub Text1_Click()
'Clears the textbox for the user's conveinance
Text1.Text = vbNullString
End Sub

Private Sub Text2_Click()
Text2.Text = vbNullString
'Clears the textbox for the user's conveinance
End Sub
'End Code

'----------------------


The above code shows you how to loop through a listbox, to find/remove an item, and to check if a textbox has anything in it.


OMG I AM SORRY! THIS IS THE WRONG FORUM!! PLEASE MOVE THIS

Notice from KuBi:
Moved from google chat. Added code tags, credits reduced.


This post has been edited by KuBi: Jan 19 2007, 10:48 PM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 



- Lo-Fi Version Time is now: 26th July 2008 - 04:30 PM