954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using Arrays with list boxes

Hi all,

New to this site asd VB6 AAAAAAA i'm trying my best.

Anyway here goes need to store names and numbers names in lstbox number in an array. select the name from the lstbox and display the number in a lbl.

here's the code so far can someone please push me in the right direction, as i say new to vb and can't see where i'm going wrong. :eek:


'***force variable declaration
Option Explicit
'***declare global variables
Dim addname As String
Dim numbers(20) As String
Dim newnumber As String
Dim reply As Integer

Private Sub cmdAdd_Click()



If txtEname = "" Or IsNumeric(txtEname) = True Then
reply = MsgBox("Please enter Name", vbOKOnly + vbInformation, "NAME")


Else
If txtTnum.Text = "" Or IsNumeric(txtTnum.Text) = False Then
reply = MsgBox("Please enter number", vbOKOnly + vbInformation, "NUMBER")
Else
'***assign variables
addname = txtEname.Text
lstNames.AddItem addname '***adds name to list box
numbers(lstNames.ListIndex) = txtTnum.Text
lstNames = lstNames + 1
End If
End If
End Sub

Private Sub cmdClear_Click()
lblNum.Caption = ""
End Sub

Private Sub cmdDisplay_Click()

numbers(lstNames.ListIndex) = newnumber

lblNum.Caption = newnumber

End Sub

Private Sub cmdExit_Click()
'***declare local variables
Dim temp As Integer

'*** does the user want to exit program
temp = MsgBox("Are you sure you would like to exit the program", vbYesNo + vbExclamation, _
"QUIT?")
If temp = vbYes Then
End '***if yes quit program
Else '***else do nothing

End If
End Sub


The line i've highlighted is the line it debugs.

thanks in advance

billyb
Newbie Poster
2 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

Hello, and welcome
Try the attached project. Needs a bit of work still, but it basically does what you want.

If you need the data you've entered to still be there when the program is run, you will have to save it in a file. Hope this helps.
w00dy

Attachments NameDemo.zip (1.77KB)
w00dy
Junior Poster in Training
70 posts since Jun 2005
Reputation Points: 11
Solved Threads: 2
 

thanks for the helpw00dy
will give it a go and let you know the outcome

billyb
Newbie Poster
2 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You