Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Constants as arrays?

Hello,


Is there a way to make Constants as Arrays?

Something like:

Public Const Doc(1) As String = "Rules.DOC"
Public Const Doc(2) As String = "Personal.DOC"
Public Const Doc(3) As String = "Reporting.DOC"

etc...


Currently I'm using:

Public Const Doc_01 As String = "Rules.DOC"
Public Const Doc_02 As String = "Personal.DOC"
Public Const Doc_03 As String = "Reporting.DOC"

....but that doesn't allow me to run through the documents in a loop, like a
For-To-Next.


Any suggentions?


TIA,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Constants as arrays?

Charlotte,

You could do something like this

Sub sonic()
Dim WordApp As Object, WordDoc As Object
Set WordApp = CreateObject("Word.Application")
mypath = "C:\"
MyArr = Array("Rules.doc", "Personal.doc", "Reporting.doc")
For x = LBound(MyArr) To UBound(MyArr)
WordApp.documents.Open mypath & MyArr(x)
WordApp.Visible = True
'do things
Next
End Sub


Mike

"Charlotte E" wrote:

Hello,


Is there a way to make Constants as Arrays?

Something like:

Public Const Doc(1) As String = "Rules.DOC"
Public Const Doc(2) As String = "Personal.DOC"
Public Const Doc(3) As String = "Reporting.DOC"

etc...


Currently I'm using:

Public Const Doc_01 As String = "Rules.DOC"
Public Const Doc_02 As String = "Personal.DOC"
Public Const Doc_03 As String = "Reporting.DOC"

....but that doesn't allow me to run through the documents in a loop, like a
For-To-Next.


Any suggentions?


TIA,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Constants as arrays?

Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc"

Sub test()
Dim v
For Each v In Split(cDOCS, "\")
MsgBox v, , "For Each"
Next

' or
Dim i As Long, arr
arr = Split(cDOCS, "\")
For i = 0 To UBound(arr)
MsgBox arr(i), , "For i ="
Next

End Sub

Regards,
Peter T

"Charlotte E" <@ wrote in message
...
Hello,


Is there a way to make Constants as Arrays?

Something like:

Public Const Doc(1) As String = "Rules.DOC"
Public Const Doc(2) As String = "Personal.DOC"
Public Const Doc(3) As String = "Reporting.DOC"

etc...


Currently I'm using:

Public Const Doc_01 As String = "Rules.DOC"
Public Const Doc_02 As String = "Personal.DOC"
Public Const Doc_03 As String = "Reporting.DOC"

...but that doesn't allow me to run through the documents in a loop, like
a For-To-Next.


Any suggentions?


TIA,




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Constants as arrays?

I might misunderstand the meaning of Charlotte's "To make Constants as
Arrays". But I can change elements of the constant array(arr). I wonder
this could be called as a constant array.


Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc"

Sub test()
Dim i As Long, arr
arr = Split(cDOCS, "\")
For i = 0 To UBound(arr)
MsgBox arr(i), , "For i = " & i
Next

For i = 0 To UBound(arr)
arr(i) = Replace(UCase(arr(i)), "R", "A")
Next

For i = 0 To UBound(arr)
MsgBox arr(i), , "After Modifing For i = " & i
Next

End Sub

Keiji

Peter T wrote:
Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc"

Sub test()
Dim v
For Each v In Split(cDOCS, "\")
MsgBox v, , "For Each"
Next

' or
Dim i As Long, arr
arr = Split(cDOCS, "\")
For i = 0 To UBound(arr)
MsgBox arr(i), , "For i ="
Next

End Sub

Regards,
Peter T

"Charlotte E" <@ wrote in message
...
Hello,


Is there a way to make Constants as Arrays?

Something like:

Public Const Doc(1) As String = "Rules.DOC"
Public Const Doc(2) As String = "Personal.DOC"
Public Const Doc(3) As String = "Reporting.DOC"

etc...


Currently I'm using:

Public Const Doc_01 As String = "Rules.DOC"
Public Const Doc_02 As String = "Personal.DOC"
Public Const Doc_03 As String = "Reporting.DOC"

...but that doesn't allow me to run through the documents in a loop, like
a For-To-Next.


Any suggentions?


TIA,




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Constants as arrays?

Constants can only refer to a value, not an array or object. The example I
posted makes a variable array from the constant string using the Split
function with the delimiter "\". After making the variable array from the
fixed constant you can of course change the array as you wish.

Regards,
Peter T


"keiji kounoike" <"kounoike AT mbh.nifty.com" wrote in message
...
I might misunderstand the meaning of Charlotte's "To make Constants as
Arrays". But I can change elements of the constant array(arr). I wonder
this could be called as a constant array.


Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc"

Sub test()
Dim i As Long, arr
arr = Split(cDOCS, "\")
For i = 0 To UBound(arr)
MsgBox arr(i), , "For i = " & i
Next

For i = 0 To UBound(arr)
arr(i) = Replace(UCase(arr(i)), "R", "A")
Next

For i = 0 To UBound(arr)
MsgBox arr(i), , "After Modifing For i = " & i
Next

End Sub

Keiji

Peter T wrote:
Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc"

Sub test()
Dim v
For Each v In Split(cDOCS, "\")
MsgBox v, , "For Each"
Next

' or
Dim i As Long, arr
arr = Split(cDOCS, "\")
For i = 0 To UBound(arr)
MsgBox arr(i), , "For i ="
Next

End Sub

Regards,
Peter T

"Charlotte E" <@ wrote in message
...
Hello,


Is there a way to make Constants as Arrays?

Something like:

Public Const Doc(1) As String = "Rules.DOC"
Public Const Doc(2) As String = "Personal.DOC"
Public Const Doc(3) As String = "Reporting.DOC"

etc...


Currently I'm using:

Public Const Doc_01 As String = "Rules.DOC"
Public Const Doc_02 As String = "Personal.DOC"
Public Const Doc_03 As String = "Reporting.DOC"

...but that doesn't allow me to run through the documents in a loop,
like
a For-To-Next.


Any suggentions?


TIA,








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Constants as arrays?

Oh, yeah...

This is the way to do it - thanks, Peter :-)


Peter T wrote:
Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc"

Sub test()
Dim v
For Each v In Split(cDOCS, "\")
MsgBox v, , "For Each"
Next

' or
Dim i As Long, arr
arr = Split(cDOCS, "\")
For i = 0 To UBound(arr)
MsgBox arr(i), , "For i ="
Next

End Sub

Regards,
Peter T

"Charlotte E" <@ wrote in message
...
Hello,


Is there a way to make Constants as Arrays?

Something like:

Public Const Doc(1) As String = "Rules.DOC"
Public Const Doc(2) As String = "Personal.DOC"
Public Const Doc(3) As String = "Reporting.DOC"

etc...


Currently I'm using:

Public Const Doc_01 As String = "Rules.DOC"
Public Const Doc_02 As String = "Personal.DOC"
Public Const Doc_03 As String = "Reporting.DOC"

...but that doesn't allow me to run through the documents in a loop,
like a For-To-Next.


Any suggentions?


TIA,



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Constants as arrays?

In my thought, if you say a variable is constant, you cannot change it's
value. In some other languages like C, you can make a constant array. In
VBA, it seems to be impossible to make a constant array. then, I wonder
why the poster needs the constants in this case. I think a code like
this would be enough.

Dim arr as Variant

Sub test()
arr = Array("Rules.DOC", "Personal.DOC", "Reporting.DOC")
For i = 0 To UBound(arr)
MsgBox arr(i), , "For i = " & i
Next
End Sub

Keiji

Peter T wrote:
Constants can only refer to a value, not an array or object. The example I
posted makes a variable array from the constant string using the Split
function with the delimiter "\". After making the variable array from the
fixed constant you can of course change the array as you wish.

Regards,
Peter T


"keiji kounoike" <"kounoike AT mbh.nifty.com" wrote in message
...
I might misunderstand the meaning of Charlotte's "To make Constants as
Arrays". But I can change elements of the constant array(arr). I wonder
this could be called as a constant array.


Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc"

Sub test()
Dim i As Long, arr
arr = Split(cDOCS, "\")
For i = 0 To UBound(arr)
MsgBox arr(i), , "For i = " & i
Next

For i = 0 To UBound(arr)
arr(i) = Replace(UCase(arr(i)), "R", "A")
Next

For i = 0 To UBound(arr)
MsgBox arr(i), , "After Modifing For i = " & i
Next

End Sub

Keiji

Peter T wrote:
Const cDOCS As String = "Rules.doc\Personal.doc\Reporting.doc"

Sub test()
Dim v
For Each v In Split(cDOCS, "\")
MsgBox v, , "For Each"
Next

' or
Dim i As Long, arr
arr = Split(cDOCS, "\")
For i = 0 To UBound(arr)
MsgBox arr(i), , "For i ="
Next

End Sub

Regards,
Peter T

"Charlotte E" <@ wrote in message
...
Hello,


Is there a way to make Constants as Arrays?

Something like:

Public Const Doc(1) As String = "Rules.DOC"
Public Const Doc(2) As String = "Personal.DOC"
Public Const Doc(3) As String = "Reporting.DOC"

etc...


Currently I'm using:

Public Const Doc_01 As String = "Rules.DOC"
Public Const Doc_02 As String = "Personal.DOC"
Public Const Doc_03 As String = "Reporting.DOC"

...but that doesn't allow me to run through the documents in a loop,
like
a For-To-Next.


Any suggentions?


TIA,





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wierd names defined as arrays of constants?!? Andy Smith[_2_] Excel Discussion (Misc queries) 1 September 18th 09 10:02 PM
Wierd names defined as arrays of constants?!? Andy Smith[_2_] Excel Discussion (Misc queries) 0 September 18th 09 08:01 PM
Trouble with arrays (transferring values between two arrays) Keith R[_2_] Excel Programming 4 November 14th 07 12:00 AM
Working with ranges in arrays... or an introduction to arrays Glen Excel Programming 5 September 10th 06 08:32 AM
Arrays - declaration, adding values to arrays and calculation Maxi[_2_] Excel Programming 1 August 17th 06 04:13 PM


All times are GMT +1. The time now is 10:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"