|
-
Sep 15th, 2000, 07:41 AM
#1
Thread Starter
Addicted Member
I know this is a simple question....
If you declare a public variable in the declarations section you can access it throught the program. Is there any way that you can declare a variable for use in just one particular module?
Cheers for any help
Steve
-
Sep 15th, 2000, 07:44 AM
#2
Sure! Declare the variable in the General Declaration section as Private.
Code:
Private iCanOnlyBeUsedInThisModule As Integer
Public iCanBeUsedEverywhereInTheProgram As Integer
Good luck!
-
Sep 15th, 2000, 07:48 AM
#3
Thread Starter
Addicted Member
Joacim
Yeah, that's what I thought too...
The only reason I asked was because I have just used this technique in a program that I am writing at the moment and it doesn't seem to work !!!
At least now I know that something else is the cause !!!!
Cheers Joacim
Steve
-
Sep 15th, 2000, 07:57 AM
#4
Junior Member
Re: Joacim
hello,
what was wrong about your declaration? I'm just wondering...
Best wishes,
Syl
-
Sep 15th, 2000, 08:04 AM
#5
Thread Starter
Addicted Member
My problem (Programming ones) !!
I think it is to do with the fact that I am passing a string to a procedure within the module that my private variable is located and technically not naming it within the procedure (If that makes sense).
Something like
Module 1
Call Myprocedure(Mystring)
Module 2
Private Mystringhere as string
Sub Myprocedure(Mystringhere)
msgbox Mystringhere
end sub
Any body else have any input with this...
steve
-
Sep 15th, 2000, 08:28 AM
#6
Junior Member
Re: My problem (Programming ones) !!
you are partly right.
When U have a module scope variable Mystringhere and than U declare
Sub Myprocedure(Mystringhere)
msgbox Mystringhere
End sub
the msgbox doesn't affect the module variable, but the local one. I want to say that in module 2 U have two different variables with the same name. As far as I know all calls to the variable's name in the procedure call the local variable.
But I think that's not the reason of your problem.
Your Myprocedure procedure is private for the module (I guess private is by default, but I'm not sure) and that's why it's invisible in another module.
When U declare
PUBLIC Sub Myprocedure(Mystringhere)
msgbox Mystringhere
End sub
should it work properly (I hope).
Not only variables can be public or private.
-
Sep 15th, 2000, 08:47 AM
#7
transcendental analytic
Procedures are public by default, Syl
If Myprocedure appears as a function property or public variable in a standard module otherwere it's possible that that one is called instead, in that case you should call it by modulename.procedurename ...
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.
-
Sep 15th, 2000, 08:52 AM
#8
Junior Member
thanks for correcting me. I always use
public sub...
or private sub...
and couldn't remember the default
-
Sep 15th, 2000, 08:54 AM
#9
transcendental analytic
Now i forgot the problem sorry,
Private Mystringhere as string
Sub Myprocedure(Mystringhere)
msgbox Mystringhere
end sub
The Mystringhere argument in the procedure is procedure scope but the private Mystringhere is modulescope, hope you don't interfere these anyhow, because you shouldn't.
If you want to change the value of mystringhere, the one with modulescope you pass a different named argument, or you use modulename.mystringhere to access the modulescope variable because the procedure scope will be the default variable to access. Hope i got your point here
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.
-
Sep 15th, 2000, 09:05 AM
#10
Thread Starter
Addicted Member
Problem fixed
Thanks for all this,
Basically the variable passed as the argument into the Myprocedure, forget this I will paste the real code.....
Public Sub Create_Monthreport()
Dim Mysheets As Byte, i As Byte, Default_Sheets As Byte
'Create workbook with required number of sheets and correct names
With Application
Default_Sheets = .SheetsInNewWorkbook
.DisplayAlerts = False
.SheetsInNewWorkbook = 1
End With
Workbooks.Add
MonthReport = ActiveWorkbook.Name
With Workbooks(MonthReport)
ActiveSheet.Name = "MAIN"
Call Print_Settings(0)
For i = 1 To 15
.Sheets.Add After:=Sheets(.Sheets.Count)
.ActiveSheet.Name = Workbooks(Template_File).Sheets(i + 2).Name
Call Print_Settings(i)
Next i
End With
With Application
.DisplayAlerts = True
.SheetsInNewWorkbook = Default_Sheets
End With
Call Copypaste_report
End Sub
the Template_File variable is a publicly defined variable in another module which I can access no problem. What I was originally trying to do (And looking back have no idea why !!!) was pass this public variable to the create_monthreport procedure. My problem was that I also wanted to use this variable within the same module as the Create_monthreport (but obviously in another procedure), I thought that declaring the passed argument as private would allow me to do this..... and that is how my discussion started..... What I have done now is to just use the public defined variable and not pass any arguments.
God knows why I didn't do this originally (Mind block or something !!!)
Cheers all anyway
Steve
P.S. How do I put the code in so it is formatted like in VB (Is is Code tags or something)
-
Sep 15th, 2000, 09:17 AM
#11
transcendental analytic
[code]
You type the code here
[/code]
note i used bold [ so that it doesn't interpret them as code tags like this:
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.
-
Sep 15th, 2000, 09:26 AM
#12
Thread Starter
Addicted Member
Cheers
Thanks for that,
Steve
lets test it
Code:
Dim Mycode is now formatted as string
and the bold technique....
[code]
Cool....
-
Sep 15th, 2000, 01:02 PM
#13
I wish I understood the code thing...
Code:
Public Function Fun(S as string) as string
Fun=StrRev(S)
End Function
Do I understand the smilies yet ?
And what about the bold thing?
underlined and italic
OK, I'm learning... Gimme another minute....
A url: www.limburg.demon.nl
and another type of url: My Homepage
Bullet lists:
- <-Cool a bullet
- <-.... and another one!
Numbered lists
[list=1][*] First Item[*] Second Item[/list=1]
And Another list:
[list=A][*] I'm gettin' the hang o'it![*] Yeah![/list=A]
Now for the big show: A Quote:
P.S. How do I put the code in so it is formatted like in VB (Is is Code tags or something)
OK, learned them all... Only the [img] tag doesn't work... bummer....
Sorry for disturbing your posts.... But I'm soooooo happy now....
-
Sep 15th, 2000, 10:17 PM
#14
There are two ways to declare variables. 'Private' is for a module only. 'Public' is for the whole 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
|