Continuing the theme of alternatives to user types, we can also of course also borrow an existing struct if we can find one which has the fields we need.
Code:
option VBAsupport 1enum MyEnumfirstvalue = 0secondvalue = 1thirdvalue = 2end enumsub testMystructdim mystruct1mystruct1 = new "com.sun.star.chart.TimeIncrement" 'BORROW A TimeIncrement struct which has 3 Any variablessetstructvalue mystruct1, myEnum.secondvalue, thiscomponent 'our own enum value or constant value for field indexmri getstructvalue(mystruct1,myEnum.secondvalue)End Subfunction getStructValue(struct, index as long) as any 'Generic function for any structdim CR,ACRCR =createunoservice("com.sun.star.reflection.CoreReflection")ACR = CR.getType(struct)getStructValue = ACR.fields(index).get(struct)end functionfunction setStructValue(byref struct, index as long,value) 'Generic function for any structDim CR,ACRCR =createunoservice("com.sun.star.reflection.CoreReflection")ACR = CR.getType(struct) ACR.fields(index).set(struct,value)end function
Statistics: Posted by JeJe — Wed Jan 22, 2025 3:46 pm