PC Review


Reply
Thread Tools Rate Thread

Cycle through Variables

 
 
Bythsx-Addagio
Guest
Posts: n/a
 
      9th Sep 2008
Hello,
I am trying to think of a way that I could loop through a range of defined
variables. Perhaps I am approaching this the wrong way so any suggestions
would be greatly appreciated. Basically what I am trying to do is shown
below.

Thanks in advance!
'****
Dim SourceFile As String, SourcePath As String, sFile As String
Dim DestFile As String, DestPath As String, dFile As String
Dim r As Long

SourcePath = "I:\"
DestPath = "C:\"

fname1 = "RS_2626(Z)_1YR.pdf"
fname2 = "RS_2626(Z)_2YR.pdf"
fname3 = "RS_2626(Z)_3YR.pdf"
fname4 = "RS_2626(Z)_4YR.pdf"
fname5 = "RS_4501(Z)_1YR.pdf"
fname6 = "RS_4501(Z)_2YR.pdf"
fname7 = "RS_4501(Z)_3YR.pdf"

'****Loop file names to File Var

For r = 1 To 7 Step 1

sFile = fname & r

'*****Copy File **********
SourceFile = SourcePath & sFile
DestFile = DestPath & sFile

FileCopy SourceFile, DestFile
'****End Copy *********

Next r

 
Reply With Quote
 
 
 
 
Shasur
Guest
Posts: n/a
 
      9th Sep 2008
Hi

You can try using arrays

Dim SourceFile As String, SourcePath As String, sFile As String
Dim DestFile As String, DestPath As String, dFile As String
Dim r As Long
Dim fname(1 To 7) As String

SourcePath = "I:\"
DestPath = "C:\"

fname(1) = "RS_2626(Z)_1YR.pdf"
fname(2) = "RS_2626(Z)_2YR.pdf"
fname(3) = "RS_2626(Z)_3YR.pdf"
fname(4) = "RS_2626(Z)_4YR.pdf"
fname(5) = "RS_4501(Z)_1YR.pdf"
fname(6) = "RS_4501(Z)_2YR.pdf"
fname(7) = "RS_4501(Z)_3YR.pdf"

'****Loop file names to File Var

For r = 1 To 7 Step 1

sFile = fname(r)

'*****Copy File **********
SourceFile = SourcePath & sFile
DestFile = DestPath & sFile

FileCopy SourceFile, DestFile
'****End Copy *********

Next r


Cheers
Shasur
--
http://vbadud.blogspot.com


"Bythsx-Addagio" wrote:

> Hello,
> I am trying to think of a way that I could loop through a range of defined
> variables. Perhaps I am approaching this the wrong way so any suggestions
> would be greatly appreciated. Basically what I am trying to do is shown
> below.
>
> Thanks in advance!
> '****
> Dim SourceFile As String, SourcePath As String, sFile As String
> Dim DestFile As String, DestPath As String, dFile As String
> Dim r As Long
>
> SourcePath = "I:\"
> DestPath = "C:\"
>
> fname1 = "RS_2626(Z)_1YR.pdf"
> fname2 = "RS_2626(Z)_2YR.pdf"
> fname3 = "RS_2626(Z)_3YR.pdf"
> fname4 = "RS_2626(Z)_4YR.pdf"
> fname5 = "RS_4501(Z)_1YR.pdf"
> fname6 = "RS_4501(Z)_2YR.pdf"
> fname7 = "RS_4501(Z)_3YR.pdf"
>
> '****Loop file names to File Var
>
> For r = 1 To 7 Step 1
>
> sFile = fname & r
>
> '*****Copy File **********
> SourceFile = SourcePath & sFile
> DestFile = DestPath & sFile
>
> FileCopy SourceFile, DestFile
> '****End Copy *********
>
> Next r
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make a graph with 2-cycle X 3-cycle log-log graph paper? Charles A. Wilson Microsoft Excel Charting 1 17th Dec 2009 03:03 AM
What has priority: PATH from User variables or system variables? Sabine Elsner Windows XP Help 3 21st Oct 2008 02:42 PM
How do I keep result from 1 iteration cycle to use in next cycle? =?Utf-8?B?c2dsOGFrbQ==?= Microsoft Excel Misc 0 27th Jul 2006 08:28 PM
Re: Class public shared Variables vs. Application Variables in ASP.NET avnrao Microsoft ASP .NET 0 7th May 2004 06:28 AM
User Environment variables overriden by system env variables Bonny Windows XP Setup 0 11th Jul 2003 06:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:19 AM.