|
-
Aug 9th, 2000, 07:33 AM
#1
Thread Starter
Frenzied Member
Hi all.
Does anyone know if you can use pointers to functions in VB? Or anything similar?
What I want ideally is to have a UDT containing a variable which somehow can be used to call the correct function relevant to the other variables in the type. Does that make sense?
What I really want is something like:
Code:
dim map(1 to 10) as ReportType
call setMap 'a function to setup the array map()
'a bit like a constructor I guess
for x = 1 to 10
map(x).function 'would be map[x]->function in C I think
next x
Maybe I can do something fancy using a class instead of a type. I've never really done OOP in VB so I don't know.
Since I'm on the subject, does anyone know if you can use any pointers in VB?
Harry.
"From one thing, know ten thousand things."
-
Aug 9th, 2000, 07:47 AM
#2
transcendental analytic
Yep, you would have to go for classmodules instead:
Add a classmodule
add your properties there as you add public variables or properties to a form.
make your methods
Function yourfunction
blabla
End function
to instance your class you use new keyword
Dim map(1 to 10) as new classname
or
dim map(1 to 10) as classname
..
set map(1) = new classname
set map(2) = new classname
..
To call the function could do the following
for x = 1 to 10
map(x).yourfunction
next x
[Edited by kedaman on 08-09-2000 at 08:49 AM]
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 9th, 2000, 07:56 AM
#3
Addicted Member
VB passes arrays by ref, (pointer to first element), so a generic function could populate the array for you.
You can also use the AddressOf keyword in VB. I'm not sure but I think it allows you to pass Function Pointers. Have a look at Help, I'm off to read up on it now. If no-one else posts I will respond further.
-
Aug 9th, 2000, 08:02 AM
#4
Addicted Member
oops, just read up Help on Function Pointers...and...
Seems I was looking at passing pointers to DLL's
Quote from MSDN:
"Basic to Basic" function pointers are not supported. Pointers to Visual Basic functions cannot be passed within Visual Basic itself. Currently, only pointers from Visual Basic to a DLL function are supported.
-
Aug 9th, 2000, 08:09 AM
#5
Thread Starter
Frenzied Member
kedaman, the thing is I want to be able to call the function through a variable, not the function's name. Or something else that works is fine.
I want
map(1).function
and
map(2).function
to call different functions, deending on the data contained in map(1) and map(2).
Thanks for your help Steven, can you think of any way to get around this?
I should also mention that I'm using Excel VBA here, not actual VB. Not by choice, it's just all they've given me to work with.
Harry.
"From one thing, know ten thousand things."
-
Aug 9th, 2000, 08:16 AM
#6
Addicted Member
I can only suggest using a CASE-SELECT construct to determine the function to call based on the value contained in map(x).
-
Aug 9th, 2000, 08:27 AM
#7
transcendental analytic
Each object can have different data, so you could make your functions to behave according to the data
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 9th, 2000, 08:28 AM
#8
Addicted Member
-
Aug 9th, 2000, 08:33 AM
#9
transcendental analytic
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 9th, 2000, 09:11 AM
#10
Thread Starter
Frenzied Member
Hmm, yes I suppose that's as close as I'm going to get.
Thanks a lot guys, you've given me some ideas and I'll go try them out now
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|