Array or User defined type error..

pr2-eugin

Super Moderator
Local time
Today, 15:02
Joined
Nov 30, 2011
Messages
8,494
Hello folks.. I have defined an array, however have declared as variant.. as such..

Dim sBox

sBox=Array(&H63, &H7C, &H77, &H7B, &HF2)

i am trying to pass this array(sBox) to another function which is defined as such:

Function expandKey(ByRef simpleKey(), ByRef box(), ByRef rcon())

but i am getting an error in the line i am trying to pass..

expandedKey = expandKey(aesKey, sBox, RC)

It says Type error: Array or User defined type expected. i tried ReDim of sBox, and also while passing used parentheses.. does not work any ideas?? :(
 
Hello folks.. I have defined an array, however have declared as variant.. as such..



i am trying to pass this array(sBox) to another function which is defined as such:



but i am getting an error in the line i am trying to pass..

expandedKey = expandKey(aesKey, sBox, RC)

It says Type error: Array or User defined type expected. i tried ReDim of sBox, and also while passing used parentheses.. does not work any ideas?? :(

Your function defined the parameter for sBox as a variant array (), but your variable is not declared as an array, just a regular variant. remove the parantheses from your function definition and it should work.
 
Thanks DJkarl.. but i really did not get it.. i am sorry for being trouble.. i am really new to this and i need all the help i could get..
 
Thanks DJkarl.. but i really did not get it.. i am sorry for being trouble.. i am really new to this and i need all the help i could get..

Code:
Function expandKey(ByRef simpleKey(), [COLOR=red]ByRef box(),[/COLOR] ByRef rcon())


change the code in red to

Code:
ByRef box
 
Thanks DJkarl.. it worked.. i really appreciate your help.. i have a question.. will it be a difference if i am changing the declaration as Variant Array?? as

Dim sBox()

sBox=Array(&H63, &H7C, &H77, &H7B, &HF2)

and still call by my old definition?
Function expandKey(ByRef simpleKey(), ByRef box(), ByRef rcon())

will it cause any problem or it is just the same??
 
If you change your declaration to an array you should be able to call the original function.
 
the thing is, passing an array may help you write functions, but i don't think arrays can be passed by value anyway (only by reference) - so if it becomes an issue, you can just declare the array globally, and refer to it in that way.

the point of passing byval is that a temporary copy of the structure is created. As I say, i don't think you can do that with an array.
 
Thanks DJkarl.. it worked.. i really appreciate your help.. i have a question.. will it be a difference if i am changing the declaration as Variant Array?? as

Dim sBox()

sBox=Array(&H63, &H7C, &H77, &H7B, &HF2)

and still call by my old definition?
Function expandKey(ByRef simpleKey(), ByRef box(), ByRef rcon())

will it cause any problem or it is just the same??
You should get into the habit of explicitly declaring your variables (i.e. Dim sBox() As Variant) and you should also be using Variants as last resort. You're obviously passing a value of type Number, so declare your it as a Long AND declare it as an array.

Dim sBox() As Long

... ByRef iBox() As Long ...

Box, on it's own, is a reserved keyword in Access/VBA.
 

Users who are viewing this thread

Back
Top Bottom