Using Arrays with list boxes

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2005
Posts: 2
Reputation: billyb is an unknown quantity at this point 
Solved Threads: 0
billyb billyb is offline Offline
Newbie Poster

Using Arrays with list boxes

 
0
  #1
Oct 25th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 70
Reputation: w00dy is an unknown quantity at this point 
Solved Threads: 2
w00dy w00dy is offline Offline
Junior Poster in Training

Re: Using Arrays with list boxes

 
0
  #2
Oct 25th, 2005
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, 15 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 2
Reputation: billyb is an unknown quantity at this point 
Solved Threads: 0
billyb billyb is offline Offline
Newbie Poster

Re: Using Arrays with list boxes

 
0
  #3
Oct 26th, 2005
thanks for the helpw00dy
will give it a go and let you know the outcome
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC