Solved

MS-Word Visual Basic Array ?

Posted on 2000-03-13
14
182 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

829 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