Hi everybody,

I've got a module I wrote a while ago, and I had an idea to rewrite a
portion of my code to make it more portable. Trouble is, now that I sit down
to actually do it, I realise that it may be a bit trickier than I first
thought.

My original code is called by another portion of my code, which has run a
lot of initialisation settings for the module. This is run just before
calling a form, so that I can assign values to the form buttons. (Eg
Button1.Label = TrayLabels(1))

Sub AssignTrays()
'Add new printers here
Select Case Printername
Case "PSA075"
TrayLabels = Array("Blank", "Blank", "Blank", "A3")
Case "PSA073"
TrayLabels = Array("Blank", "A3", "SG", "CG")
Case "PSA032"
TrayLabels = Array("Blank", "SG", "CG", "A3")
Case "PSA071"
TrayLabels = Array("Blank", "SG", "CG", "NR")
End Select
End Sub

The code works fine and I've had no issues. However, a drawback to this
style was noted yesterday when we got a new printer, with new tray
assignments. Instead of being able to quickly change the labels, I had to
wait until everybody had gone home and deploy a new version, just to change 1
label. That's when the idea of using an Ini file to get printer names and
tray names occurred to me.

What I'd like to do is create an Ini file which contains
A) Get a list of available printers for a site.
B) A list of what trays are available for these printers.

E.g.
[AvailPrinters]
PSA071
PSA073
PSA075
PSA032

[PSA071]
Blank
SG
CG
NR

The main problem is, I don't know how to read multiple values with
System.PrivateProfileStrings, only a single value. Does anybody have any idea
how I might set about trying to code this?

Thanks in advance,

Bob

Re: System.PrivateProfileString to populate array? by Doug

Doug
Tue Apr 01 23:35:48 PDT 2008

I gather that what has prompted you to do this is the issue that you ran
into while trying to modify your code while other people had documents open
to which was attached the template that contains the code.

That issue can be avoided if you follow the procedure for distribution of
templates in the article "Distributing macros to other users" at:

http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Beeawwb" <Beeawwb@discussions.microsoft.com> wrote in message
news:19A1E243-8C80-439F-95F3-39314F0A0632@microsoft.com...
> Hi everybody,
>
> I've got a module I wrote a while ago, and I had an idea to rewrite a
> portion of my code to make it more portable. Trouble is, now that I sit
> down
> to actually do it, I realise that it may be a bit trickier than I first
> thought.
>
> My original code is called by another portion of my code, which has run a
> lot of initialisation settings for the module. This is run just before
> calling a form, so that I can assign values to the form buttons. (Eg
> Button1.Label = TrayLabels(1))
>
> Sub AssignTrays()
> 'Add new printers here
> Select Case Printername
> Case "PSA075"
> TrayLabels = Array("Blank", "Blank", "Blank", "A3")
> Case "PSA073"
> TrayLabels = Array("Blank", "A3", "SG", "CG")
> Case "PSA032"
> TrayLabels = Array("Blank", "SG", "CG", "A3")
> Case "PSA071"
> TrayLabels = Array("Blank", "SG", "CG", "NR")
> End Select
> End Sub
>
> The code works fine and I've had no issues. However, a drawback to this
> style was noted yesterday when we got a new printer, with new tray
> assignments. Instead of being able to quickly change the labels, I had to
> wait until everybody had gone home and deploy a new version, just to
> change 1
> label. That's when the idea of using an Ini file to get printer names and
> tray names occurred to me.
>
> What I'd like to do is create an Ini file which contains
> A) Get a list of available printers for a site.
> B) A list of what trays are available for these printers.
>
> E.g.
> [AvailPrinters]
> PSA071
> PSA073
> PSA075
> PSA032
>
> [PSA071]
> Blank
> SG
> CG
> NR
>
> The main problem is, I don't know how to read multiple values with
> System.PrivateProfileStrings, only a single value. Does anybody have any
> idea
> how I might set about trying to code this?
>
> Thanks in advance,
>
> Bob



Re: System.PrivateProfileString to populate array? by Jonathan

Jonathan
Wed Apr 02 00:38:27 PDT 2008


"Beeawwb" <Beeawwb@discussions.microsoft.com> wrote in message
news:19A1E243-8C80-439F-95F3-39314F0A0632@microsoft.com...
> Hi everybody,
>
> I've got a module I wrote a while ago, and I had an idea to rewrite a
> portion of my code to make it more portable. Trouble is, now that I sit
> down
> to actually do it, I realise that it may be a bit trickier than I first
> thought.
>
> My original code is called by another portion of my code, which has run a
> lot of initialisation settings for the module. This is run just before
> calling a form, so that I can assign values to the form buttons. (Eg
> Button1.Label = TrayLabels(1))
>
> Sub AssignTrays()
> 'Add new printers here
> Select Case Printername
> Case "PSA075"
> TrayLabels = Array("Blank", "Blank", "Blank", "A3")
> Case "PSA073"
> TrayLabels = Array("Blank", "A3", "SG", "CG")
> Case "PSA032"
> TrayLabels = Array("Blank", "SG", "CG", "A3")
> Case "PSA071"
> TrayLabels = Array("Blank", "SG", "CG", "NR")
> End Select
> End Sub
>
> The code works fine and I've had no issues. However, a drawback to this
> style was noted yesterday when we got a new printer, with new tray
> assignments. Instead of being able to quickly change the labels, I had to
> wait until everybody had gone home and deploy a new version, just to
> change 1
> label. That's when the idea of using an Ini file to get printer names and
> tray names occurred to me.
>
> What I'd like to do is create an Ini file which contains
> A) Get a list of available printers for a site.

This article will help

Getting names of available printers
http://www.word.mvps.org/FAQs/MacrosVBA/AvailablePrinters.htm


> B) A list of what trays are available for these printers.

And this article will help for that

Controlling the Printer from Word VBA
Part 1: Using VBA to Select the Paper Tray
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=101

>
> E.g.
> [AvailPrinters]
> PSA071
> PSA073
> PSA075
> PSA032
>
> [PSA071]
> Blank
> SG
> CG
> NR
>
> The main problem is, I don't know how to read multiple values with
> System.PrivateProfileStrings, only a single value. Does anybody have any
> idea
> how I might set about trying to code this?

Instead of using System.PrivateProfileString, use Karl Peterson's class
module for INI files.
http://vb.mvps.org/samples/project.asp?id=kpIni


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup