Solved

MS-Word Visual Basic Array ?

Posted on 2000-03-13
14
176 Views
Last Modified: 2013-11-25
Keep this in mind as you read:  I do not have the full version of visual basic; I'm working with the MS-Word version.  

My question is this:  How can I bring an array's information from one form to another?  I've tried to declare it under DELCARATIONS but it still won't come through.

Here is a bit of the code I'm trying.

For fn = 1 To frmFatherNumberBar.scrlFatherNumber.Value
Selection.InsertAfter fathername(fn) + ";"
Next fn

frmfathernumberbar is a seperate form from the one I'm on, and scrlfathernumber.value is a scroll bar.
I need the current form to pull "fathername(1)", etc.. from the form frmFatherNumberBar.

Any ideas how to do this?

-rick detroit
0
Comment
Question by:saksafon2
14 Comments
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2613071
Are you sure the syntax is correct:

Selection.InsertAfter fathername(fn) + ";"

It might be:

Selection.InsertAfter fathername(fn) ";"

without the "+" operator.  I'll have to tinker with it a little bit and see.

Wes
0
 

Author Comment

by:saksafon2
ID: 2613089
I've used the + ";" syntax a few times.  For this example we could even leave the + ";" out.
The problem it's having is just getting the array over.  Meh!  It's frustrating.

lol
rick
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2613287
First, when you declare fathername(), make it a PUBLIC variable, e.g.:

PUBLIC fathername() as String

Then, when you reference the variable, make sure that you reference the form as well:

Selection.InsertAfter frmFatherNumberBar.fathername(fn) + ";"

That should do it.
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2613293
If you put a stop on this line:

For fn = 1 To frmFatherNumberBar.scrlFatherNumber.Value

(click on te gray bar to the left of this line of code) then the code will stop before it executes that line.  When it does, hit ctrl+G and the immediate window will pop up.  When it does, paste this in and hit return:

? frmFatherNumberBar.scrlFatherNumber.Value

The value in your scroll bar should pop up.  If it doesn't, then we need to start somewhere else.

Wes
0
 

Author Comment

by:saksafon2
ID: 2613390
Meh!  

Bhess1, the idea is perfect and it's exactly what I'm looking for except the computer is giving me two different errors:

First, when I "PUBLIC" the variable in general declerations, it states that "Constants, fixed-length strings, arrays, and DECLARE statements not allowed as public members of object modules".

I placed the declerations actually in the code and it compiled, but when I got to the 2nd form that needs to call it, it states that it still can't find the array from the other form.  Any ideas?

rick
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2613411
Can you move this code into a general module and get it out of the form module?  Then you can use all those neat words like constant, public, etc.

You might have to add some syntax to take care of object references(like your form and document) but I think that would be the best way.

Wes
0
 

Author Comment

by:saksafon2
ID: 2613417
How do I do that and how would I be able to call it up from the form?

rick
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:wesleystewart
ID: 2613454
Absolutely.

From the Word IDE, click >>Insert>>Module and a new module window will pop up.  You can create a new subprocedure by typing Sub MyProc() and hitting Enter.

Then your code will go in MyProc.  Use a button on your form or another event (form close, etc) and call MyProc from within the event.

How are you calling the code now?  It shouldn't be much different.

Wes
0
 
LVL 15

Expert Comment

by:cquinn
ID: 2613458
Refer to the array (which I assume is declared in frmfathernumberbar) using the explicit reference as below:
 
frmFatherNumberbar.fathername(fn)


P.S.

Use the ampersand (&) to concatenate strings - if you concatenate with the plus sign (+) and any of the things you are concatenating is null, the whole string ends up as null!

0
 

Author Comment

by:saksafon2
ID: 2613547
It says "PUBLIC" is an invalid attribute inside a sub-procedure.
I made one and copied the info in and it says it doesn't want to work.

Go fig.  MEH!

rick
0
 

Author Comment

by:saksafon2
ID: 2613552
Adjusted points to 60
0
 
LVL 4

Accepted Solution

by:
wesleystewart earned 60 total points
ID: 2613621
public is invalid in a subprocedure.  It goes in the declarations section at the top of the module, NOT inside the procedure.

This makes it available to the whole project.

Wes
0
 

Author Comment

by:saksafon2
ID: 2613700
The module idea was great.  I placed both sets of procedures that need the variables in a seperate module with different procedures and it's going to call up and work fine.  Thanks for the help again.
Your savin' my life here.

-rick, detroit
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2613735
I'm happy to help.  If you're going to be doing a lot of programming in Word, I suggest the following two books:

http://www.oreilly.com/catalog/writewordmacro/
http://www.oreilly.com/catalog/pwomodel/noframes.html

If you get them from Amazon I think they are about $20 each.  I don't work for O'Reilly or anything like that, I just think their books are the best no-nonsense reference texts on the market.  They manage to get as much good stuff into 500 or 600 pages as Sybex and the others get into 1200 to 1500 pages.

VBA, as it is implemented in Word, is the exact same language engine (VBA332.dll) found in VB, so programming in word is a great step towards progarmming in VB.

Wes
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
using Access 8 59
maro to copy and paste from one worksheet to another based on a condition 11 48
clicking a shape in a frame array vb6 3 40
Problem to open text file 11 73
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now