Visual Basic Minor Problem

Associate
Joined
21 Sep 2005
Posts
180
Location
Dundee
Hi all,

My son is doing Visual Basic at school. Unfortunately they are using Visual Basic 6 which doesn't seem that up to date. I know PHP but am floundering with this as can't seem to find what I'm looking for although I know what sort of thing I'm looking for.

He's been given the task of creating a form that takes 5 integers and then does some other stuff with it. I'm guessing arrays here. Have been managing to work out some of it. Can get it to take the range of numbers but only ever prints out the last item in the array. Am sure it's something very simple and if someone could point out the error I'd appreciate it.

Thanks in advance.

Code:
Private Sub Form_Activate()

Dim scores(5) As Integer
Dim numbers As Integer


For numbers = 1 To 5
    scores(numbers) = InputBox("enter the scores")
    
    
    
Next numbers

List1.Items.Add scores(numbers)



End Sub
 
Associate
OP
Joined
21 Sep 2005
Posts
180
Location
Dundee
Thanks for the reply. Think there is a variety of ways to declare the array and think the original example is ok. Had already looked at that page when trying to help my son.

The below link shows a variety of methods.

http://www.vb6.us/tutorials/understanding-arrays

We've got the declaration slightly wrong though. Should be as below for a 5 position array. Going to try working with that.

Code:
Dim scores(4) As Integer

Edit - Think the add at the bottom is wrong too as he's trying to print.
 
Last edited:
Associate
OP
Joined
21 Sep 2005
Posts
180
Location
Dundee
Have got it working with 2 loops. Am pretty sure it's not very elegant though but it's a start. Thanks for the help.

Code:
Private Sub Form_Activate()

Dim scores(4) As Integer
Dim numbers As Integer


For numbers = 0 To 4
    scores(numbers) = InputBox("enter the scores")
Next


For numbers = 0 To 4
    Form1.Print scores(numbers)
Next




End Sub
 
Associate
OP
Joined
21 Sep 2005
Posts
180
Location
Dundee
His school does actually have VB10 as well but they were having problems with it on their network so they dropped down to VB6 as it was issue free from a school use perspective. I do wish they were using something more up to date tho but for learning coding basics at their level then I guess it's ok.
 
Back
Top Bottom