I have a question about what is recommended to do and to avoid when writing macros with StarBasic.
I think that one very convenient thing to do, is to create "structs" (as they are called in C/C++), such as this one mentioned in another thread a while ago: Type PersonType FirstName As String LastName As String End Type Let's say that we created a rather complex struct with hundreds of variables and other structs, like this: Type PersonType FirstName As String LastName As String Status As MyStruct . . . End Type Type MyStruct Test1 As Integer Test2 As Double Blah As MyOtherStruct . . . End Type Type MyOtherStruct . . . End Type . . . (The dots means "and so on"…) So, now we want to do stuff. We will create a function that needs, say two string variables. The function is only going to be used for this project, so we don't need to make it general. So here are two options that I could think of: 1: Sub Main Dim A As MyStruct Sim B As Integer A.FirstName="Johnny" A.LastName="Andersson" . . . B=MyFunction(A.FirstName, A.LastName) . . . End Sub Function MyFunction(A As String, B As String) As Integer Dim C As Integer . . . 'A and B are used to calculate C in some way, how is not important, it's just an example. . . . MyFunction=C End Function 2: Sub Main Dim A As MyStruct Sim B As Integer A.FirstName="Johnny" A.LastName="Andersson" . . . B=MyFunction(A) . . . End Sub Function MyFunction(A As MyStruct) As Integer Dim C As Integer . . . 'A.FirstName and A.LastName are used to calculate C in some way. No other variables of A are used. . . . MyFunction=C End Function One of the advantages with option 2, is that I don't need to include a lot of parameters when I call the function. In this example it was not that big difference, but sometimes I need maybe 5 or 10 parameters. On the other hand, and this is my question: Isn't option 2 more time consuming? I am not sure how this works, but if the whole structure is copied every time the function is called, I guess it will run slower. So how does it work? Are all the variables copied to the function or is that handled by a reference or something like that? Should option 2 be avoided for extremely complex structures? Or should option 1 be avoided? Can you see more (and better) options for this kind of "problem"? A bonus question: Is there anything like the C++ "class" in StarBasic? I think VB use classes too… It feels like objects works like classes. They have their own methods to handle their own variables, just like C++ classes, but can I create my own? Johnny Andersson
