?
Solved

MS-Word Visual Basic Array ?

Posted on 2000-03-13
14
Medium Priority
?
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Brendt Hess
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 240 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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