I have below declaration:
Type routineStruct
man As String * 3
number As String * 5
End Type
Type vbToC
sch As String * 4
routine(0 To 10000) As routineStruct
End Type
vbfun As vbToC
Now we are sending this vbfun As vbToC from VB to C.
Now for above vbToC type , 64K memory limit error is occuring while compiling.
So, we use the dynamic array as like -
Type vbToC
sch As String * 4
routine() As routineStruct
End Type
And then assign value
Redim routine(10000)
For loop = 0 To 10000
.routine(loop).man = value1
.routine(loop).number = value2
Next
My question is above vbToc declaration for dynamic array is right or not? if right then can it be possible to send values from vb to c with this dynamic array and how to receive the value for dynamic array for each structure element?
In VB6 the type you have defined as "routineStruct" is invalid. You would most certainly receive a compile error here. If you are trying to declare "man" and "number" as arrays the syntax is not correct. You would need to use a declaration similar to your "routine" element with an array declaration.
Furthermore, you have declared your type without any access modifier. When you do this it will default to "private." If you were to export the VB6 ActiveX DLL to a type library for use in C++ the type would therefore not be visible and marshaling would not be possible.
The solution would be to adjust your type declaration to include proper VB6 syntax as well as make the type public. Marshaling of native string types become BSTR in C/C++ and you should have no problem here.
Related
I am trying to initialize a derived type using a parameter declaration. When I compile, I get the following error
Element in INTEGER(4) array constructor at (1) is CHARACTER(1).
User defined kinds values ip and dp are found in fasst_global. They are:
integer,parameter:: ip = selected_int_kind(8)
integer,parameter:: dp = selected_real_kind(15,307)
I have tried using 1_ip instead of 1 as the first element and it made no difference. What am I doing wrong?
module fasst_derived_types
use fasst_global
implicit none
type fasst_default_soil
integer(ip):: sid
character(len=2):: ssname
real(dp):: dens,pors,ssemis,ssalb,shc,smin,smax,salpha,svgn
real(dp):: sspheat,sorgan,spsand,spsilt,spclay,spgravel
end type fasst_default_soil
type(fasst_default_soil),parameter:: fasst_soil(1) = fasst_default_soil( &
(/1, 'GW',1.947_dp,0.293_dp, 0.92_dp,0.40_dp,1.1197e-2_dp, &
0.01_dp,0.293_dp,22.6125_dp, 3.45_dp, 820.0_dp, &
0.0_dp, 5.0_dp, 2.0_dp, 2.0_dp,91.0_dp/))
end module fasst_derived_types
You are trying to use two constructors here:
an array constructor;
a structure constructor.
You have the correct syntax for each, but you are using them incorrectly.
The array constructor (/.../) is to construct an array. But you want an array of derived type values (well, one value) rather than an array as the component for a single derived type value. The syntax error comes from attempting to create an array with various different/incompatible types.
So, instead you want
type(fasst_default_soil),parameter:: fasst_soil(1) = (/fasst_default_soil(1_ip,'GW', ...)/)
Or, as you just want a single element array you don't even need to construct that array of derived types.
So I have an class returns array of singles. Problem is that new requrement came up where I need to be able provide these values as a single string, which can be done with Join except Join requres that array is made up of strings not singles.
I guess I could write a new method in my class that provides same array but with values as strings. However I was wondering if I could just convert existing method to accept something like Optional ValType as vbVarType as a parameter and accordingly change the type of values in ouputed array.
Is this doable in a relatively DRY way?? I'd love to avoid code that looks like:
Select Case ValType
Case #something1
#omitted code
Case #something2
#omitted codev
Case #something3
#omitted code
........
UPDATE: I guess what I am looking for is a formula like Cstr() except that I'd like it to work on an Array and have it expect parameeter describing value to convert to.
Can you simply have an array of type Variant rather than Single? The following code seems to work ok:
Dim arrInt() As Variant
ReDim arrInt(0 To 3)
arrInt(0) = 0
arrInt(1) = 1
arrInt(2) = 2
arrInt(3) = 3
Debug.Print Join(arrInt, "#")
I am using an array of objects in my program, and each object has several attributes. I want to be able to extract separate arrays from this array of objects, one array for each attribute.
here is a snippet of the relevant code:
dailyDataMatrix(m,n)=dailyData('',''); %creates an mxn array of dailyData objects
for i=1:m
for j=1:n
dailyDataMatrix(i,j)=dailyData(datainput1, datainput2)%dailyData constructor, sets attributes
end
end
dailyDataMatrix.attribute
But when I try to access a certain attribute as in the code above, say of type string, I get a strange result. Instead of getting an array of strings, I get something else. When I try to print it, rather than printing an array, it prints a series of individual values
ans = 'string1'
ans = 'string2'
...
When I try to call
size(dailyDataMatrix.attribute)
className = class(dailyDataMatrix.attribute)
I get
"error using size: too many input arguments" and
"error using class: The CLASS function must be called from a class constructor."
However, when I write this as
thing=dailyDataMatrix.attribute
className = class(thing)
size(thing)
I get the response
classname = 'double' and size = 1x1.
Why is this not returning an array the same size as dailyDataMatrix? And an aside question is why the two different ways of writing the code above give different results? and how can I get the result that I want?
Thanks,
Paul
You can capture all the outputs using a cell array or using square brackets if the types are same. For regular array when all values are of same type use,
thing=[dailyDataMatrix.attribute];
If the types are different you can use
thing = cell(1,N); % N is the number of elements in dailyDataMatrix
[thing{:}] = dailyDataMatrix.attribute;
ive set up a custom data type
type vector = {a:float;b:float};
and i want to Initialize an array of type vector but containing nothing, just an empty array of length x.
the following
let vecarr = Array.create !max_seq_length {a=0.0;b=0.0}
makes the array init to {a=0;b=0} , and leaving that as blank gives me errors. Is what im trying to do even possible?
You can not have an uninitialized array in OCaml. But look at it this way: you will never have a hard-to-reproduce bug in your program caused by uninitialized values.
If the values you eventually want to place in your array are not available yet, maybe you are creating the array too early? Consider using Array.init to create it at the exact moment the necessary inputs are available, without having to create it earlier and leaving it temporarily uninitialized.
The function Array.init takes in argument a function that it uses to compute the initial value of each cell.
How can you have nothing? When you retrieve an element of the newly-initialized array, you must get something, right? What do you expect to get?
If you want to be able to express the ability of a value to be either invalid or some value of some type, then you could use the option type, whose values are either None, or Some value:
let vecarr : vector option array = Array.create !max_seq_length None
match vecarr.(42) with
None -> doSomething
| Some x -> doSomethingElse
You can initialize and 'a array by using an empty array, i.e., [||]. Executing:
let a = [||];;
evaluates to:
val a : 'a array = [||]
which you can then append to. It has length 0, so you can't set anything, but for academic purposes, this can be helpful.
Consider the following code fragment in VS2010 Beta 1:
let array = Array2D.zeroCreate 1000 500
This produces an error, namely:
error FS0030: Value restriction. The value 'array' has been inferred to have
generic type val array : '_a [,]
Either define 'array' as a simple data term, make it a function with explicit
arguments or, if you do not intend for it to be generic, add a type annotation.
Can I explicitly set the type (in my case a grid of string)?
You can explicitly specify the type like this:
let array : string [,] = Array2D.zeroCreate 1000 500
For further information on the value restriction you might want to take a look at this F#-Wiki page.
You can also use init to create an array though it might be slower.
let array = Array2D.init 1000 500 (fun _ _ -> "")
Zeroing out an array is usually not seen in functional programming. It's much more common to pass an initilization function to init and just create the array with the values you want.
To create a 2-dimensional array containing empty strings:
let array = Array2D.create 1000 500 ""