Tom Knowlton
asked on
Array of structs
I know you can use Arrays in VBScript, but can you do an array of structs?
Something like:
Type LabelType
message As String
active As Boolean
End Type
Dim LabelStruct(30) As LabelType
Response.Write LabelStruct(1).message
Response.Write LabelStruct(2).message
Response.Write LabelStruct(2).active
Response.Write LabelStruct(3).message
etc???
Something like:
Type LabelType
message As String
active As Boolean
End Type
Dim LabelStruct(30) As LabelType
Response.Write LabelStruct(1).message
Response.Write LabelStruct(2).message
Response.Write LabelStruct(2).active
Response.Write LabelStruct(3).message
etc???
ASP does not allow the Type statement or explicit data types. You have to create a class.
Class LabelType
Public message
Public active
End Class
Set oType = new LabelType
oType.Message = "Hello"
oType.Active = true
Set LabelStruct(1) = oType
etc.
Response.Write LabelStruct(1).message
Response.Write LabelStruct(2).message
Response.Write LabelStruct(2).active
Response.Write LabelStruct(3).message
Class LabelType
Public message
Public active
End Class
Set oType = new LabelType
oType.Message = "Hello"
oType.Active = true
Set LabelStruct(1) = oType
etc.
Response.Write LabelStruct(1).message
Response.Write LabelStruct(2).message
Response.Write LabelStruct(2).active
Response.Write LabelStruct(3).message
Sorry Fritz I meant to say ...."as Fritz the Blank stated ASP does not allow .... " didn't mean to plagerize
To build on what Mike_Metro has said (and continuing with my idea of using a custom class):
If you do this:
Class LabelType
Public message
Public active
End Class
Set oType = new LabelType
oType.Message = "Hello"
oType.Active = true
Set LabelStruct(1) = oType
etc.
you will still need to create a new instance of the class for each Message/Active pair. If you follow a consistent naming convention, however, you can iterate through like this:
for i=0 to 10
response.write(eval("Label Struct(" & i &")")
next
but it is inefficient....
FtB
If you do this:
Class LabelType
Public message
Public active
End Class
Set oType = new LabelType
oType.Message = "Hello"
oType.Active = true
Set LabelStruct(1) = oType
etc.
you will still need to create a new instance of the class for each Message/Active pair. If you follow a consistent naming convention, however, you can iterate through like this:
for i=0 to 10
response.write(eval("Label
next
but it is inefficient....
FtB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
fritz:
Not sure what you mean (sorry).
Not sure what you mean (sorry).
ASKER
Can I return multi-dimensional arrays back from function calls?
Function FillArray(myArray As Array) As Array
'Fill the array
FillArray = myArray
End Function
Function FillArray(myArray As Array) As Array
'Fill the array
FillArray = myArray
End Function
ASKER
http://www.knowltonfamily.com/robotz_te/tom_test.asp
Is not working.
Here is the source code for this page:
<%
arrLabel = new Array(12,2)
arrLabel(0,0)="This is the first message"
arrLabel(0,1)="Active"
arrLabel(1,0)="This is the second message"
arrLabel(1,1)="Inactive"
arrLabel(2,0)="This is the third message"
arrLabel(2,1)="Active"
Response.Write arrLabel(0,0)
Response.Write arrLabel(0,1)
Response.Write arrLabel(1,0)
Response.Write arrLabel(1,1)
Response.Write arrLabel(2,0)
Response.Write arrLabel(2,1)
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
Is not working.
Here is the source code for this page:
<%
arrLabel = new Array(12,2)
arrLabel(0,0)="This is the first message"
arrLabel(0,1)="Active"
arrLabel(1,0)="This is the second message"
arrLabel(1,1)="Inactive"
arrLabel(2,0)="This is the third message"
arrLabel(2,1)="Active"
Response.Write arrLabel(0,0)
Response.Write arrLabel(0,1)
Response.Write arrLabel(1,0)
Response.Write arrLabel(1,1)
Response.Write arrLabel(2,0)
Response.Write arrLabel(2,1)
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
ASKER
I get this message:
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/robotz_te/tom_test.asp, line 2
arrLabel = new Array(12,2)
---------------------^
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/robotz_te/tom_test.asp, line 2
arrLabel = new Array(12,2)
---------------------^
I haven't tried that. so I can't say for certain. However, you can always declare the array outside of the function and manipulate it with a subroutine. Alternatively, and again I haven't tried this, you can pass the array as an object to your funciton:
Function FillArray(By Ref myArray)
About this:
>>Not sure what you mean (sorry).<<
Is there something that I can clarify?
FtB
Function FillArray(By Ref myArray)
About this:
>>Not sure what you mean (sorry).<<
Is there something that I can clarify?
FtB
ASKER
>>Not sure what you mean (sorry).<<
Moot at this point.......ignore it.
Moot at this point.......ignore it.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did the trick!!!!
~~~~~~~~~~~~~~~~~~~~~~~~
Sample code for those who follow:
~~~~~~~~~~~~~~~~~~~~~~~~
<%
Dim arrLabel(12,2)
arrLabel(0,0)="This is the first message"
arrLabel(0,1)="Active"
arrLabel(1,0)="This is the second message"
arrLabel(1,1)="Inactive"
arrLabel(2,0)="This is the third message"
arrLabel(2,1)="Active"
Response.Write arrLabel(0,0)
Response.Write arrLabel(0,1)
Response.Write arrLabel(1,0)
Response.Write arrLabel(1,1)
Response.Write arrLabel(2,0)
Response.Write arrLabel(2,1)
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~
Sample code for those who follow:
~~~~~~~~~~~~~~~~~~~~~~~~
<%
Dim arrLabel(12,2)
arrLabel(0,0)="This is the first message"
arrLabel(0,1)="Active"
arrLabel(1,0)="This is the second message"
arrLabel(1,1)="Inactive"
arrLabel(2,0)="This is the third message"
arrLabel(2,1)="Active"
Response.Write arrLabel(0,0)
Response.Write arrLabel(0,1)
Response.Write arrLabel(1,0)
Response.Write arrLabel(1,1)
Response.Write arrLabel(2,0)
Response.Write arrLabel(2,1)
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
Oops! Sorry about the syntax error--I slipped into JScript. Mike_Metro has provided the correct syntax above.
Fritz the Blank
Fritz the Blank
ASKER
fritz: I figured you knew the correct syntax.
Try going from VB to C++ or C#. Lots o' fun:
= vs ==
ending everything with ;
Drives me crazy.
Try going from VB to C++ or C#. Lots o' fun:
= vs ==
ending everything with ;
Drives me crazy.
ASKER
I guess JavaScript would have the same woes.
Knowlton--
Are you using C# with .Net?
Fritz the Blank
Are you using C# with .Net?
Fritz the Blank
ASKER
Yes
Another approach may be to use a Hash table....
http://www.w3schools.com/aspnet/aspnet_hashtable.asp
Fritz the Blank
http://www.w3schools.com/aspnet/aspnet_hashtable.asp
Fritz the Blank
ASKER
My account on brinkster.com does not support ASPX (yet)
Ah. Until then...
FtB
FtB
ASKER
But....thanks for the link!!!!!
Fritz the Blank