Jump to content
xisto Community
Sign in to follow this  
iAlter

Programming/c++/vb Hello, do you program? Know anything about programming? Are a programm

Recommended Posts

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

| 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.

Edited by KuBi (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.