2-dimensional array

P

portroe

my 2-dimensional array, is given me the following error message,


'For' loop control variable cannot be of type '1-dimensional array of
String'.

has anybody got a tip on what I have incorrect,

Thanks
 
A

Armin Zingler

portroe said:
my 2-dimensional array, is given me the following error message,


'For' loop control variable cannot be of type '1-dimensional array
of
String'.

has anybody got a tip on what I have incorrect,


Please post Code.
 
H

Herfried K. Wagner [MVP]

* portroe said:
my 2-dimensional array, is given me the following error message,

'For' loop control variable cannot be of type '1-dimensional array
of String'.

has anybody got a tip on what I have incorrect,

You will have to use 2 nested loops to loop though the array.
 
P

portroe

'thanks


'Declaration of variables and arrays as public
Public AmountclubYear(4, 0) As Decimal
Public club(4) As Integer
Public Year() As Integer
Public InputStartingYear As Integer
Public InputFinalYear As Integer
Public x As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'store the name of each club
club(0) = "r54000"
club(1) = "r54001"
club(2) = "r54002"
club(3) = "r54003"
club(4) = "r54004"

'user enters start and final year,

InputStartingYear = InputBox("Please enter the starting year.")
InputFinalYear = InputBox("Please enter the final year.")

'Program to calculate the number of years
x = InputStartingYear - InputFinalYear

'redim
ReDim Year(x)


End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'the user will be prompted by input boxes for cost

For club = 0 To 4
For Year = 0 To x
AmountclubYear(club, Year) = _
CDec(InputBox("Enter the cost incurred for club ",
club, " and year ", Year))
Next Year
Next club
End Sub
End Class
 
A

Armin Zingler

portroe said:
Code:
[/QUOTE]

Please enable Option Strict first. Add the line

Option Strict On

add the top of the source code file, or enabled it in the project
properties. (menu project->properties: general properties->build: Option
Strict On)

After that, fix the obviuos bugs, then I can have a look at it again.
 
C

Chris Dunaway

On Tue, 16 Dec 2003 11:37:22 +0100, portroe wrote:

You need to use simple variables in a for next loop.
Public x As Integer
For club = 0 To 4
For Year = 0 To x
AmountclubYear(club, Year) = _
CDec(InputBox("...")
Next Year
Next club

The problem is that you're using array variables (club and Year) in the for
loop instead of simple variables.

Use something like this instead:

Public c As Integer
Public y As Integer

For c = 0 to 4
For y = 0 to x
AmountclubYear(c,y) = CDec(InputBox(....))
Next
Next
 
A

Armin Zingler

Chris Dunaway said:
You need to use simple variables in a for next loop.

No, not necessarily. This works:

Dim x(0, 0) As Integer
For x(0, 0) = 0 To 15
Debug.WriteLine(x(0, 0))
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top