Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default dynamic variables - thank you

Hallo,

thank you for the responses. You helped me a lot already!

Regards,
Christian


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Lookup Question with multiple dynamic variables Robin Excel Worksheet Functions 14 June 12th 08 09:40 PM
Add up a Dynamic Range with 2 Variables John Excel Worksheet Functions 2 January 15th 05 05:03 PM
Add up a Dynamic Range with 2 Variables John Excel Worksheet Functions 1 January 15th 05 02:23 PM
Add up a Dynamic Range with 2 Variables John Excel Worksheet Functions 0 January 15th 05 02:00 PM


All times are GMT +1. The time now is 04:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"