944,184 Members | Top Members by Rank

Ad:
Oct 25th, 2005
0

Using Arrays with list boxes

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
billyb is offline Offline
2 posts
since Oct 2005
Oct 25th, 2005
0

Re: Using Arrays with list boxes

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
Attached Files
File Type: zip NameDemo.zip (1.8 KB, 45 views)
Reputation Points: 11
Solved Threads: 2
Junior Poster in Training
w00dy is offline Offline
70 posts
since Jun 2005
Oct 26th, 2005
0

Re: Using Arrays with list boxes

thanks for the helpw00dy
will give it a go and let you know the outcome
Reputation Points: 10
Solved Threads: 0
Newbie Poster
billyb is offline Offline
2 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Help Needed
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: random selection with drag and drop label function( help needed!! )





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC