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")

If txtTnum.Text = "" Or IsNumeric(txtTnum.Text) = False Then
reply = MsgBox("Please enter number", vbOKOnly + vbInformation, "NUMBER")
'***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, _
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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.