SCOPE Question
Say you have Module1, Form1, and ClassModuleA & ClassModuleB. I have instantiated Form1 from within Module1. I have instantiated ClassModuleA & ClassModuleB from within Form1.I need to be able to read/write ClassModuleA's variables from within ClassModuleb. How do I do this? Do I need to instantiate the 2 classes from Module1 instead of Form1?Is there a better way?Thanks for any input!John
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Out Of Scope?
I am trying to launch a public sub routine I wrote in master vba project that gets loaded from Personal.xls. I am doing so from the AutoOpen event of a separate file with it's own vbaProjects.
When I try to run the AutoOpen event to test my public subroutine I get "Compile Error: Sub or Function not defined."
Is there some form of global address to the sub routine I can give to the call?
~T
VB Scope
I wonder that could VB support scope like Pascal ? That means there are sub procedures in a procedure.
Thanks very much
Scope
are variables declared as "public" visible to all froms in a project??
or is there a type def with broader scope?
Scope
i need to make a variable accessed by all forms in an mdi application. i have declared an integer as public, im able to change it value n read that value again in one button click .. but in the other form i cant !
how should i do it
Scope?
Is there anyway to extend the scope of a form to include a couple of modules in VB5?
Basically, I want to take some routines out of a form and throw them in a module without changing anything.
Well, Ideally, I'd just like to block my code together a bit more so that related routines are gathered together...
Any Ideas,
Dim A
Scope Rules
Edit by Moderator: Please use the [vb][/vb] vb tags when posting your code.
i have the following program that always confuse me.
Code:
' Fig. 6.15
' Scoping example
Option Explicit ' General declaration
Dim x As Integer ' Module variable in general declaration
Private Sub cmdGo_Click()
Dim x As Integer ' Local variable
x = 6
Print "Local x is " & x & " on entering cmdGo_click()"
Print
' Call procedures
Call One
Call Two
Call Three
' Call procedures again
Call One
Call Two
Call Three
Print "Local x is " & x & " on exiting cmdGo_click()"
cmdGo.Enabled = False
End Sub
Private Sub One()
Dim x As Integer
x = 26
Print "Local x is " & x & " on entering One"
x = x + 1
Print "Local x is " & x & " on exiting One"
Print
End Sub
Private Sub Two()
Static x As Integer
' Initialize local static x to 60
' the first time into the procedure
If x = 0 Then
x = 60
End If
Print "Local static x is " & x & " on entering Two"
x = x + 1
Print "Local static x is " & x & " on exiting Two"
Print
End Sub
Private Sub Three()
Print "Module x is " & x & " on entering Three"
x = x + 5
Print "Module x is " & x & " on exiting Three"
Print
End Sub
the result should be:
Local x is 6 on entering cmdGo_click()
Local x is 26 on entering One
Local x is 27 on entering One
Local static x is 0 on entering Two
Local static x is 61 on entering Two
Module x is 0 on entering Three
Module x is 5 on entering Three
Local x is 26 on entering One
Local x is 27 on entering One
Local static x is 61 on entering Two
Local static x is 62 on entering Two
Module x is 5 on entering Three
Module x is 10 on entering Three
for module Three, why the value will act like static.....the second time it run,...it get the value of 5 from the previous running procedures? i thought it should be not stored the previous value into memory? only static will store and retrieve the previous value from memory.....
thanks
Question About Var Scope
From an earlier post I had some questions:
http://www.xtremevbtalk.com/showthread.php?t=160482
I have a problem with setting a var in one sub and then trying to use it in another sub. Specifically when I set a word app like (Set oWord = CreateObject("Word.Application")) in a sub - but lets say I have another sub that adds a footer to every page? It needs to reference oWord but im not sure how to do that without re-setting it and launching another word app?
Also does anyone know how to split table cells in Word using a range instead of a selection?
Variable Scope
This may be a quick easy answer so maybe you can help me.
Is it possible to reference a public variable declared at the module level of a form from a report control???
More specific:
From a report (one of the controls, a text box, contains code that calls a function to return a value for the report ... the parameter for that function is the "report_date" variable (a public variable declared at the module level of a form ... This form has a button/OnClick on it to trigger the report)
I've tried, it doesn't work (a box pops up which ask for the value of that variable I tried to refer to in the report)
Maybe that answers my question??? Help?
Class Scope
Here's my problem:
I have two classes "AThing" and "AThingGroup" (yes, inventive names)
AThingGroup makes things very easy when it comes to doing certain things, so I don't want to remove it. The problem is that since "AThing" is a class module, and it's declared as array within AThingGroup, it can't be public.
Is there anyway to access AThing via AThingGroup? Or do I need to write a function called "Get*******" for every attribute I need?
Scope Problem
I have a Form. It has a "public Criterio as string" in declarations
When i pass this variable to a function like
ChangeStr(Criterio)
then, when it returns, it's not changed! why?!!
UDT Scope Problem?
I've got this program I'm making to read the contents of a string containing a chemical equation and putting the information into a UDT. The code worked fine, but I added a sub (I had been doing all my code in one button click event up until now) and I can't access any of the information I put into the UDT from the new sub(cmdKnownWeight_Click).
Could someone tell me how can I get to this information from different subs? Is there a better way of doing this in the first place?
My code's here:
http://ken_t115.home.att.net/code.txt
Thanks
Scope Question
i've only been doing VB for a short while and have a question on scope. the IT mngr and i were discussing an upcoming project. i had some sample code that i was testing some ideas on and had it like this:
Code:
Option Explicit
Private Sub cmdSetText_Click()
Dim strTextToSet As String
Dim strFileName As String
strTextToSet = txtTextToSet.Text
strFileName = txtFileName.Text
'rest of code went here
End Sub
he began to tell me that i didn't need to pull the text from the text box "txtTextToSet" to the string variable that i could just use the text box itself because one could possibly end up having 2 variables of the same name with the different data floating around. but i had the understanding that since i declared the variables within the sub routine, they weren't available outside of that sub routine. now i know that one would need to make sure that 2 variables weren't named the same within different levels of the program, say at the form global and form level. but i hadn't ever seen just using the text box itself as the variable rather than setting it as i have. does that make sense? any thoughts?
Scope Of Variables
can anyone help me with these questions
reasons for variables being able to have scope?
when variables should be declared at a higher level than procedure level?
The consequences of declaring variables at an inappropriate level?
thanks
Variable Scope?
I am making a form for visual basic. The text boxes in it need to retain their value after the form is unloaded just like in Microsoft Word... like for page setup and everything... things are retained even after the form is unloaded. How do I retain the values which I enter in the text boxes ?
Scope Issues
Ok. So I'm trying to create a Public Type that all of my classes can use, but then none of my classes can accept that type as input into a sub, nor output them from a function. I get the message "Only public user defined types defined in public object..." yada yada. I've been tinkering with putting the Type inside the Class that needs it currently, which works fine, except that then I have to make it private and no other class can use it.
Is there any way to create a type usable by all of my classes for input as an argument in subs and output types for functions?
Scope Question
Hi all,
I am using the following code in an application I am writing:
Code:
Private Sub ButtonSlideshow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSlideshow.Click
Dim f As Form1
f = Me.Owner
OleDbCommand1.Connection = f.OleDbConnection1
OleDbCommand1.Parameters("@PlaceID").Value = TextBoxIdentifier.Text
Dim i As Integer = 0
Dim captionarray(500) As String
Dim patharray(500) As String
Dim mydr1 As System.Data.OleDb.OleDbDataReader
Try
mydr1 = OleDbCommand1.ExecuteReader(CommandBehavior.Default)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
While mydr1.Read()
patharray(i) = CType(mydr1.Item("Path"), String)
captionarray(i) = CType(mydr1.Item("Caption"), String)
MessageBox.Show(patharray(i) & " : " & captionarray(i))
i = i + 1
End While
mydr1.Close()
End Try
PictureBoxSlide.Image = Image.FromFile(patharray(0))
LabelCaption.Text = captionarray(0)
ButtonNext.Enabled = True
End Sub
Private Sub ButtonNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNext.Click
End Sub
Private Sub ButtonPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPrevious.Click
End Sub
I want to use the patharray and captionarray arrays in the two subs at the bottom. How do I do this?
Thanks in advance
Stephen
Sub Of Class Scope ?
i have 2 class.
and i have a sub in one of them.
and i want access to this sub only from the secound class.
so, what is the scope of this sub ?
thanks,
Scope And Design
I've written a log class that open, close and write to a text file.
How should I declare and use my log object if I want to use the Writelog method in all the classes in my project.
Is this a good Idea. It seems not right since all my classes will become dependant on the log object to work.
I'm not sure I'm pretty clear, but any help would be appreciated.
Variable Scope?!
I have a settings file that I read when my program starts up, and I would like to read each setting into a variable that stays in memory throughout the liftime of the program, not just the form or module. Now the code I have to read the settings file is in its own module. So do I just declare each variable public and static within that module?! If so do they have to be within a procedure or function? Or should I give them their own module? I have read the tutorial there is on here about scope, and although it was very helpful, it hasn't quite answered this question of mine.
Any help much appreciated.
Variable Scope
I have this:
Module_1
{
Subrutine one {
Dim var1
Call other_sub
}Other_sub
{
Msgbox (var1) <---
}
}
How Do I need to to declare the variable (var1) in order I can use the variable in the other_sub procedure?
I don’t want a use the public.
I has thinking that if I declared the variable inside of the subroutine one I could use this in other procedures, but not.
Thanks for your help,
How To Comment A Scope?
As we know , we can use ' to comment a statment .
Can anyone tell me how to comment a scope in VB??
thanks
Scope Of Variables
I made an OCX. In that OCX I declare my variables public in a module because I use them in several procedures all over my project.
No problem so far.
Now I place my ocx on a form twice! The variables of the two (same) ocx are mixing!
I believe the scope of a public variable is not only the whole project but also the outside world
How can I solve this problem??
ADO Scope Problem
I made myself a simple example. I wanted to make a recordset available all over my project.
I have this in a module:
Global connConnection As New ADODB.Connection
Global rsRecordset As New ADODB.Recordset
Then in a Public sub in the same module I do all the connection/source stuff, and calls the sub from my form.
If I in form load on my form has Form.Label1.Caption = rsRecordset.Fields("name").Value I get runtime error 91 (Variable not defined)
If I write the same ( Form1.Label1.Caption = rsLager.Fields("Tegningsnummer").Value ) in the module, it works fine and label1.caption is my name So all the connection/source works, but the scoping sucks.
I fear this is very basic, but search and google didnt help me much.
Thx in advance guys
Variable Scope
I thought I knew enough about this but maybe not :
I have a Boolean variable declared at form level. When that form is loaded the variable is False (because I Dim it but don't explicitly give it a value). As the form sets up all of its controls the variable is then set to True in code.
If the user then unloads the form and then reloads it, the variable has kept its value of True from the previous incarnation of the form.
I know I can override this by setting its value to False in Form.Load but I'm curious about why the variable retains its value - I thought all form variables get destroyed when the form is unloaded.
Scope Question
I have a form that displays a report option at the end of execution that basically gives the user a report of all the was preformed. In this report it has a few ListViews and everything is displayed correctly if the user chooses to view the report at the end of current execution.
However, I also want the user to be able to view this report again if need be. So I added an option in the main form to view "Most Recent Report" which inturn would display the same report as if it were just executed, however all the ListViews are empty when its displayed this way.
I guess my question is after you view the ListView once is that data destroyed? Or Am I out of the scope of the data after I close that ViewReport form?
Thanks
Variable Scope
if i've a variable declared in one form but i want to use it in another form in the same project, is it possible to do so...if so how, do i declare it as public or what??
Compiler And Scope
Does anyone know how the compiler handles scope in regard to Modules and Classes?
For example:
If you have module or class that has Public variables, Public structures (UDT's), and Public Functions as well as a number of Private variables, structures and functions, does the entire module remain open (i.e. Publics on heap, Privates on separate module stack) while the application is loaded OR is the
compiler smart enough to unload the Privates, and possibly publics, and if so when?
Stated another way, if there is one public in a module/class does the entire module/class remain in memory (both heap and module stack) throughout the entire application?
If available, a link or source to the technical reference would be appreciated.
Thanks
David
Variable Scope
I have 3 forms:
QuoteForm - Form containing a TreeView
ItemForm - Form containing a DataGrid for Drag and Drop
ProcessForm - Form containing a DataGrid for Drag and Drop
The problem is that QuoteForm stores variables like "txtDragValue" that is given to it from the other two forms. Here is the Drop functions used in the QuoteForm:
Code:
'Dropping Functions
'------------------
Private Sub tvPS_DragOver(Source As Control, x As Single, y As Single, State As Integer)
If dragging = True Then
' Set DropHighlight to the mouse's coordinates.
Set tvPS.DropHighlight = tvPS.HitTest(x, y)
End If
End Sub
Private Sub tvPS_DragDrop(Source As Control, x As Single, y As Single)
Dim NewTreeItem As Node
txtDragValue = ItemForm.txtDragValue
txtNewNode = tvPS.DropHighlight.Key
txtNewNodeText = tvPS.DropHighlight.Text
txtParentNode2 = tvPS.Nodes(tvPS.Nodes.Count).Text
On Error GoTo DupError
If txtDragValue = txtNewNodeText Then
MsgBox ("You can't have a part with that same part in it!"), vbOKOnly + vbCritical, "Same Parent Item"
Else
If Not (tvPS.DropHighlight Is Nothing) Then 'Checks to see if the node being created is in a valid place (Another node is highlighted)
Set NewTreeItem = tvPS.Nodes.Add((txtNewNode), tvwChild, txtNewNode & "_" & txtDragValue, Left(txtDragValue, InStr(1, txtDragValue, "_") - 1))
NewNode = Left(txtDragValue, InStr(1, txtDragValue, "_") - 1)
NewNodeKey = NewTreeItem.Key
'Call Check_New_Node(NewNode, NewNodeKey)
'MsgBox (txtNewNode & " - " & txtDragValue)
Set tvPS.DropHighlight = Nothing
Set txtNewNode = Nothing
Set txtDragValue = Nothing
Set txtParentNode2 = Nothing
NewTreeItem.EnsureVisible
NewTreeItem.Selected = True
End If
End If
Call Assign_Icons 'Assigns Icons so that the new treeview is correct
Exit Sub
DupError:
If Err.Number = 35602 Then
MsgBox ("You can't have duplicate items in an assembly!"), vbOKOnly + vbCritical, "Duplicate Items"
Resume Next
Else
Exit Sub
End If
End Sub
The problem is that txtDragValue is assigned during this:
Code:
Private Sub DataGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
txtDragValue = DataGrid1.Text & "_MAT" 'Gets the value of the row highlighted and being drug
End Sub
Private Sub DataGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then 'Begins the dragging process
DataGrid1.DragIcon = QuoteForm.ImageList1.ListImages(6).Picture
DataGrid1.Drag vbBeginDrag
IMTextBox.Text = DataGrid1.Text
QuoteForm.dragging = True
QuoteForm.Show
End If
txtDragValue = DataGrid1.Text & "_MAT"
End Sub
and txtDragValue is saved on the quoteform even when the ItemForm has closed. I need to be able to have the code above and this:
Code:
'Drag and Drop Functions
'-----------------------
Private Sub DataGrid2_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
txtDragValue = DataGrid2.Text & "_PRO" 'Gets the value of the row highlighted and being drug
End Sub
Private Sub DataGrid2_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then 'Begins the dragging process
DataGrid2.DragIcon = QuoteForm.ImageList1.ListImages(6).Picture
DataGrid2.Drag vbBeginDrag
PROTextBox.Text = DataGrid2.Text
QuoteForm.dragging = True
QuoteForm.Show
End If
txtDragValue = DataGrid2.Text & "_PRO"
End Sub
coexist. Right now, when I close the ItemForm and open the ProcessForm and try to drag an item from the ProcessForm, it trys to add a new node to the tree with the value last used from the ItemForm. Can you help? Thanks, Jeremy
Scope Problem
I have a module with the following type declared in it:
VB Code:
Public Type AnimationFrameType translateX(1 To 256) As Single translateY(1 To 256) As Single translateZ(1 To 256) As Single RotateX(1 To 256) As Single RotateY(1 To 256) As Single RotateZ(1 To 256) As Single scaleX(1 To 256) As Single scaleY(1 To 256) As Single scaleZ(1 To 256) As Single calllist As LongEnd Type
A class has this code:
VB Code:
Public Function GetFrame(num As Long) As AnimationFrameTypeGetFrame = Frames(num)End Function
However, when I try to compile the project I get this error:
"Compile Error: Only public user defined types defined inpublic object modules can be used as parameters or return types for public procedure of class modules or as fields of public user defined types"
Any suggestions?
Scope Of VB Code: HELP !
Hello: Just looking for some comments where I should get started. I was looking to write a small application that:
1) Stays running as a taskbar project (until closed by user).
2) Just keeps looking in a directory until a file exists. (that is easy part --- I think).
I am really worried about the system tray issue. Is it different programming for Nt, 2000 or Pro to run the same application.
Any comments where I should start would be appreciated.
Thanks
rjohnst
Object Var Out Of Scope Before Set To Nothing
In the following Excel VBA function, is there a problem with resources not being released due to not setting sht to Nothing before leaving the function? I never before considered For Each implicitly doing a Set.
Code:
Public Function bSheetExists(sSheet As String) As Boolean
Dim sht As Worksheet
'Determine If the indicated worksheet exists.
For Each sht In Worksheets
If sht.Name = sSheet Then
bSheetExists = True
Exit Function
End If
Next sht
bSheetExists = False
End Function
Thanks,
mort
Scope Of An Array
I have an array that i want to have global scope across all forms in my project... WHere so i declare it so that all the forms in my project will have scope...
I declared it in the General - Declarations area on my main form... but that does not work...
Is this possible , if so where do i declare it ?
Thx..
Scope Of Arguments
Greetings,
I wish to know if I have two functions or subroutines which are declared as Public in the same form or module and they contain arguments of same name, will they interfere with each other?
For example,
Public Function FindExtremeDate(MyDatabase As String, AggFcn As String) As Variant
Public Sub DataIEWizard(MyDataFile As String, MyDatabase As String, Optional MyIEType As String = "Import")
Will the argument "MyDatabase" shared in both subs or they will not, safe to use.
How about private?
Variable Scope
I want to declare a variable which will be alive every form in project. Please help me.
Thank u.
Scope Of Variables
I have a program that creates an array of filenames, and I'm wishing to make this array available to another form which I load up from the first form. (i.e. I think I'm trying to make the array global, how?)
I've tried defining this array in the general delecarations section of the first form.
Do I have to instead define it in a class module?
Many thanks.
Form Scope
Okay, I have a class that I need to have able to change the properties of objects that reside on my main form. Is there any way for other forms or classes to acess objects that are on this form?
I am trying to acess an mscomm and two text boxes.
but when I compile it gives me a varible not declaired error. I am fearfull that this indicates that I cannot have control over those objects.
can someone please help me?
Scope Of Variables
Prior to saying rtfm, here's the stuff I'm encountering:
I have a module that is loaded first thing when a database opens; inside of it is a variable I declare.
I've tried declaring it in the following two ways:
Dim strVar as string
Public strVar as string
that's neither here nor there; what happens after that is that I wish to call it in a different module (one attached to a form) but it won't compile. Tells me undefined variable!
I don't understand; I've set it up as a public variable in the first module that should be loaded into memory.
Any ideas?
Another quirky thing I've been wondering about it this:
I have a form based on a query. The query relies on a function.
I call the function in the form's Open event, but the form still comes up blank, unless I close it and reopen it.
I worked around it by creating a splash form that calls the data, opens the main form, then closes itself, but I feel like this is a sloppy way to work it.
Any ideas?
Variable Scope
Hello,
I am declaring a variable as follows
private x as integer
or
dim x as integer
in the module level after option explicit in the form.
Even after the form is unloaded that variable retains
it value when I come back to the same form.
I am not preserving the value as static or as public somewhere.
Within a procedure the variables get reinitialized.
It doesnt happen at module level.
Is there a way to reinitialize module level variables
or I have to manually reinitialize like x = 0 for each
variable.
Thank you
Anand Jayaraj
Parameter Out Of Scope
Hi,
I'm trying to send a large decimal number from my application to database using stored procedures. My number has at least 4 digits to the left and up to 2 digits to the right (1111.11). It is type double in my application and type money in the database. When I assign this number to a parameter(stored procedure) I get the exception "parameter out of scope". Do I need to use another data type in my application or in my database or both?...what data type would I use?
Variable Scope
I have
Dim Jenables(10) As Long
in the General Declarations section of a form.
If, say, element 7 gets set by the form code, and I unload the form and then reload it, the element is still set on form load.
I thought that was the point with form variables, they turned up with the form.
The form is really unloading, as in not in the forms collection.
http://www.accuflight.com
http://www.lettersdirect.co.uk
http://www.ourhouseinportugal.co.uk/
Variable Is Out Of Scope?
Before I tell you my problem, here is some background.
I have a Microsoft POS program and you can write COM add-ins for it in VB 6. In my VB project I have a class module and it contains a function called:
Public Function Process(session As Object) As Boolean
As you can see it has a reference to the 'session' object. This code is triggered in the POS when an item UPC is scanned. In this function there is some code that, if certain conditions are satisifed, a userform is opened on screen.
Now, in my project in the form module for this userform, there is a Form_Load event subroutine. When the form loads, there is code in this sub that is supposed to open a recordset, using the active ADO connection that was established when the POS program was started. The line of code that does this is:
Global glbRecSet as ADODB.Recordset
Set glbRecSet = Session.Database.OpenRecordset(glbsqlstr, True)
As near as I can tell, this recordset object is declared and set correctly. When I debug my code, it errors out on the above 'Set' line of code. I get a run-time error 91, saying that my glbRecSet variable is not properly set. Like I said I'm sure that the syntax for this line is correct.
However, what I'm wondering is, could it be erroring out because my session object (that I have referenced in my class module, see above) is out of scope on my form code? How do I pass a reference to my session object as part of my Form_Load subroutine? Could this be the cause of my run-time error, and if so how do I remedy this?
Thank you,
Kevin
Scope Of An Array
How to ensure the scope of an array outside the procedure it is used ?
Variable Scope???
Okay everyone! From what I understand in Visual Basic 6, there are 3 types of variables: private, public, and static. What is the difference of these, and also, what is the precise definition of "scope"? Thanks!
Variable Scope...
I'm sure this is a 'no-brainer' for most of you out there but...
How can I assign a value to a variable in one form and use that variable in a 2nd form?
I tried...
Public Status as String
Status = "One"
...but when I check Statue in the 2nd Form I get a Null.
Thanks in advance.
Database Scope
i wondered about the scope of my database:
should i define it in each form, each procedure, or even in the module as public.
i want to refer to the computer performance, and the safety of the database.
I'll be glad to have some opinions in this subject.
Scope Of Variable
I have declared some form level varaibles. I just wanted to know the scope of those variables.
Like.
Dim altitude(MAX) As Double
Dim airspeed(MAX) As Double
Can I say like when form goes out of scope, the memory allocated to the arrays goes out of scope. i.e memory given to the variables are given back to the system.
Regards
Nagesh
Question Regarding Scope
I have 2 classes . . . Class1 & Class2
I declare
Dim MyClass1 As New Class1
in MainForm. No Problems. Can access member variables. Responding to an event of MainForm, I instantiate MyClass2 As New Class2. But I cannot access variables of Class1 from within Class2 (compile error).
Anyone with suggestions?
Thanks.
John
Bookmark Scope Question (?)
warning: newbie alert ;)
i have an assignment that requires visual basic. i managed to learn the very basics, but there are problems i just can't solve/understand. perhaps not a problem for pros. i hope :) so the problem goes:
basically what i need to do is to iterate through _all_ the bookmarks and replace their text with something. i use an external program with com handling (should be no problem). i made the script, but there is one quirk and one issue i have found no solution to.
1. i could not just open the template and use GoTo to go to the next bookmark, it does not move the cursor and returns an error flag through the com handler. i can GoTo a line, or a bookmark when i define the exact name, but the relative GoTo does not seem to work. i have read the help and found out that when using bookmarks in GoTo, the name should be given - but there's no sign if the relative bookmark GoTo can or cannot be used. (of course i cannot provide a name to the "next" bookmark, since i don't know which one is next.)
2. so, i made the script based on another (i guess slower, but that's all right) approach. i use the bookmarks container, and iterate from the 1st to the (count)th. (btw, a tiny feature question: is there a way to get the bookmarks in the order as they are in the document? i know different containers return them in different order, but is that all i can use?) _but_ there's a bookmark which this script does not find, but it's inside the container! it's
- inside a drawn object ("text box")
- but appears in the bookmarks container (and the bookmarks list in word too)
- the script gives an error when addressing that (i use Select to make a selection from the bookmark)
- surprisingly, the bookmarks dialog "go to" button dims (!) when selecting this bookmark while the cursor is outside that control.
what's all that? is this control outside the activedocument scope? how can i "really" :) iterate through all bookmarks (even in tables, forms, header-footer, comments, drawn objects etc.)?
i'm quite new to vba, so if that's a very basic thing here, please just point to a part of the doc to examine more carefully. some basic code samples would be really welcome 'thou :) ie. how to tell a "valid" (?) bookmark from a non-goto-able ;) one, etc. etc. :)
a truckload of thanks in advance! :)
edit: typo, and one thing i forgot to mention: i use word 2000, but the solution should definitely work under office xp, and an office 97-compatibility would be nice too. hope that's not too much :)
Keeping Variables In Scope
I have an Excel VBA macro I call using a toolbar button.
The button is tied to a subroutene (GetDataIn) in a module (modDataSetup) . The module is in my ExcelMacros spreadsheet.
At the very begining of modDataSetup all variables needed later are declared as Public following the Option Explict Statement.
GetDataIn sets values of certain variables representing columns that are needed later on. At the end of GetDataIn a form (frmGetData) is displayed using the show command.
The problem I am having is prior to displaying frmGetData all needed variables have their assigned values (as seen in the locals dialogue); however, once I show frmGetData the variables not longer are usable.
My question is how can I set variables up in a module subroutene and then use them in later form code? I realize I can assign values to a label or a textbox but that is not what I want to do.
By way of example what I want to do is set a value for "A" in modSetupData
i.e A= something
then show frmGetData and be able to use the value of A set up in modSetupData.
I thought Public A as String '(or whatever) at the begining of modSetupData would allow A to also be used in frmGetData but the variable doesnt seem to exist after frmGetData is shown.
If this isnt clear I will post actual code tomorow when I get back to my code computer.
|