Solved

Array of structs

Posted on 2004-04-20
22
2,013 Views
Last Modified: 2008-02-01
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???
0
Comment
Question by:knowlton
  • 11
  • 8
  • 3
22 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 10871362
With ASP.Net you can create hash tables to do this. In ASP classic, you can create your own custom classes, but I don't know that you can iterate through the values the way that you list above.

Fritz the Blank
0
 
LVL 6

Expert Comment

by:Mike_Metro
ID: 10871563
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


0
 
LVL 6

Expert Comment

by:Mike_Metro
ID: 10871579
Sorry Fritz I meant to say ...."as Fritz the Blank stated ASP does not allow .... " didn't mean to plagerize
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 10871676
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("LabelStruct(" & i &")")
next

but it is inefficient....

FtB
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 300 total points
ID: 10871690
Using a multideminsional array would be better:

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"


Now you can iterate through everything easily.

Fritz the Blank
0
 
LVL 5

Author Comment

by:knowlton
ID: 10871692
fritz:

Not sure what you mean (sorry).
0
 
LVL 5

Author Comment

by:knowlton
ID: 10871711
Can I return multi-dimensional arrays back from function calls?

Function FillArray(myArray As Array) As Array
  'Fill the array


  FillArray = myArray
End Function
0
 
LVL 5

Author Comment

by:knowlton
ID: 10871781
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>
0
 
LVL 5

Author Comment

by:knowlton
ID: 10871789
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)
---------------------^
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 10871802
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
0
 
LVL 5

Author Comment

by:knowlton
ID: 10871811
>>Not sure what you mean (sorry).<<


Moot at this point.......ignore it.
0
 
LVL 6

Assisted Solution

by:Mike_Metro
Mike_Metro earned 200 total points
ID: 10871817
Try this:
Dim arrLabel(12,2)
0
 
LVL 5

Author Comment

by:knowlton
ID: 10871835
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>
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 10871849
Oops! Sorry about the syntax error--I slipped into JScript. Mike_Metro has provided the correct syntax above.

Fritz the Blank
0
 
LVL 5

Author Comment

by:knowlton
ID: 10871875
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.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10871882
I guess JavaScript would have the same woes.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 10871953
Knowlton--

Are you using C# with .Net?

Fritz the Blank
0
 
LVL 5

Author Comment

by:knowlton
ID: 10871956
Yes
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 10872194
Another approach may be to use a Hash table....

http://www.w3schools.com/aspnet/aspnet_hashtable.asp

Fritz the Blank
0
 
LVL 5

Author Comment

by:knowlton
ID: 10872215
My account on brinkster.com does not support ASPX (yet)
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 10872314
Ah. Until then...

FtB
0
 
LVL 5

Author Comment

by:knowlton
ID: 10872345
But....thanks for the link!!!!!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Classic ASP - cannot get to correct path 17 73
Highlight a word from some text 16 56
Forcing form refresh - classic ASP 7 66
Javascript to allow login/password authorization 4 45
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question