|
-
Oct 10th, 2000, 08:39 AM
#1
Thread Starter
Lively Member
I have a module that is used in several projects. If a certain class is present I want to declare this class inside the module. Is there a way to use the #ifdef to do this?
Code:
#If clsMyClass-Exist
Dim clsMyClass As New clsMyClass
#End If
I will be using that further down in the code as well to use the class if it is available.
-
Oct 10th, 2000, 08:43 AM
#2
transcendental analytic
something like this?
Code:
If not clsMyClass is nothing then
Dim clsMyClass As New clsMyClass
End If
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.
-
Oct 10th, 2000, 10:05 AM
#3
Thread Starter
Lively Member
I was thinking to have it globally inside the class so i dont have to pass it to every function.
Code:
Private MyClass As New clsMyClass
Dont know if one can use normal if else outside a function or sub.
-
Oct 10th, 2000, 11:05 AM
#4
transcendental analytic
No If statements outside functions! Just declarations.
Well now i understand your point, you want to check if a class module is in the project, well no that won't get compiled, sorry 
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.
-
Oct 10th, 2000, 11:35 AM
#5
New Member
By definition, what you want to do is conditional compilation. Therefore, you cannot check against a global variable other than what is stored in the conditional compilation arguments.
What you need to do is put something like blnGoodProject = 1 as a conditional compilation argument. You could then have:
#If blnGoodProject = 1 Then
Set objItme = New clsItem
#End If
Unfortunately, since conditional compilation only allows boolean values (whatever evaluates to true and false), you can't really have a Select Case statement either in your code. Not that there is a #Select Case... statement anyway.
BTW, please do not do this:
#If Not blnGoodProject = 1
Not is a bitwise operator, this will not evaluate properly. Do a blnGoodProject <> 1 instead.
-
Oct 10th, 2000, 11:58 AM
#6
Addicted Member
What is the difference when you place a # sign infront of "IF"?
-
Oct 10th, 2000, 12:08 PM
#7
New Member
Shark,
That means it's conditional compilation. If the #If statement does not evaluate to true, whatever code is in there will not be compiled either in debug mode or to the compiled component.
Therefore, you can make a reference to a class that does not exist in the project, as long as the IF...Then statement does not evaluate.
-
Oct 10th, 2000, 12:45 PM
#8
Addicted Member
Thanx for the definition.
Can you give me an example of both "If" and "#If"? I like to know when to use which?
Thanks
[Edited by Shark on 10-10-2000 at 02:06 PM]
-
Oct 11th, 2000, 05:48 AM
#9
Thread Starter
Lively Member
Here is an example
Code:
Private Const SWpresent = 1 '1=true 0=false
#If SWpresent = 0 Then
Private Const MyNumb = 1000
#Else
Private Const MyNumb = 99
#End If
Sub Test()
MsgBox MyNumb
End Sub
I actually get the inverse of what the If-line says.
Output here is 1000. If i change "SWpresent = 0" to "SWpresent = 1" i get 99. Weird.
-
Oct 11th, 2000, 12:57 PM
#10
Addicted Member
Thanks Thomas, that make sense. So when you place a "#" sign infront of an If, you can use it outside of a procedure?
-
Oct 11th, 2000, 05:57 PM
#11
Thread Starter
Lively Member
Yes you can in a way do this. But it tells the compiler what to compile and what not to compile. Normally I would get an error if I declared a class that did not exist. With the #if #else I can tell it only to declare it if it exist. In my case I just declare a Constant saying if I have the class or not. Without the #if #else, you would get an error when pressing F5 to run, before the execution actually begin. The compiler would say "That class does not exist" and wont run the program.
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
|