![]() |
dynamic variables
Hallo,
imagine that a dynamic variable has been specified with the statement: dim feld() as string dim z as integer z shall be the variable to store the size of the dynamic variable. During the runtime of the program the dynamic variable "feld" is adjusted with the statement: redim preserve feld(z) Is there any possibility to transfer this variable to 1) another VBA-Function or VBA-Subroutine? (in C++ those fields are transferred with the help of pointers, is there a similar possibility in VBA?) 2) an external funktion that has been added by "declare" and uses C++ code. (I use MS Visual C++ 6.0). I do not want to use global variables. I apologize for my English and say thank you very any support in advance! Greetings, Christian |
dynamic variables
Christian,
I think you need to look in vba help at CALL, DIM, SUB and FUNCTION keywords.. the idea is you can pass them as arguments to functions of procedures. VBA passes parameters ByReference (ByRef) as default Sub Demo() Dim myarray1() As String Dim myarray2() As String Upsizer myarray1, myarray1, 3 myarray1(0) = "a" myarray1(1) = "b" myarray1(2) = "c" Upsizer myarray1, myarray2, 10 Debug.Print UBound(myarray1), UBound(myarray2) End Sub Sub Upsizer(vaIn, vaOut, incr As Integer) Dim y& vaOut = vaIn On Error Resume Next y = UBound(vaOut) On Error GoTo 0 ReDim Preserve vaOut(y + incr) End Sub HTH keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool "Christian Lehmann" wrote: Hallo, imagine that a dynamic variable has been specified with the statement: dim feld() as string dim z as integer z shall be the variable to store the size of the dynamic variable. During the runtime of the program the dynamic variable "feld" is adjusted with the statement: redim preserve feld(z) Is there any possibility to transfer this variable to 1) another VBA-Function or VBA-Subroutine? (in C++ those fields are transferred with the help of pointers, is there a similar possibility in VBA?) 2) an external funktion that has been added by "declare" and uses C++ code. (I use MS Visual C++ 6.0). I do not want to use global variables. I apologize for my English and say thank you very any support in advance! Greetings, Christian |
dynamic variables
Hi Christian
I beleive that "under the hood" VB/VBA strings work similar to other languages; string variables are pointers and string manipulation generates new strings and altered pointers. But I may be wrong. #1, if I understand your code correctly, passing variables is done like this: Sub test() Dim Feld() As String Dim z As Long For z = 0 To 5 ReDim Preserve Feld(z) 'just filling with nonsense: Feld(z) = String(15, Chr(z + 65)) Next Call Receiver(Feld()) End Sub Sub Receiver(Strings() As String) Dim L As Long For L = LBound(Strings) To UBound(Strings) MsgBox Strings(L), , L Next End Sub Can't assist with #2, sorry. -- HTH. Best wishes Harald Followup to newsgroup only please. "Christian Lehmann" wrote in message ... Hallo, imagine that a dynamic variable has been specified with the statement: dim feld() as string dim z as integer z shall be the variable to store the size of the dynamic variable. During the runtime of the program the dynamic variable "feld" is adjusted with the statement: redim preserve feld(z) Is there any possibility to transfer this variable to 1) another VBA-Function or VBA-Subroutine? (in C++ those fields are transferred with the help of pointers, is there a similar possibility in VBA?) 2) an external funktion that has been added by "declare" and uses C++ code. (I use MS Visual C++ 6.0). I do not want to use global variables. I apologize for my English and say thank you very any support in advance! Greetings, Christian |
dynamic variables - thank you
Hallo,
thank you for the responses. You helped me a lot already! Regards, Christian |
All times are GMT +1. The time now is 10:24 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com