Thread View: comp.lang.basic.visual.misc
6 messages
6 total messages
Started by lex comber
Thu, 03 Jun 1999 00:00
passing a variable into a file path
Author: lex comber
Date: Thu, 03 Jun 1999 00:00
Date: Thu, 03 Jun 1999 00:00
47 lines
1991 bytes
1991 bytes
This is a multi-part message in MIME format.
--------------BA065179D94536DDEBB8C524
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Apologies for the cross postings...
A simple bit of advice for a novice needed:
I have a list of files "0.dat" to "255.dat"
I am trying to pass a variable into a string to open a series of files
and am getting stuck on the line
(For i = 0 To 255)
Workbooks.OpenText FileName:="I:\ncms\squares\" + i + ".dat",
Origin:= _
xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=...
(...etc..
Next i )
Any suggestions gratefully received
Lex Comber
--------------BA065179D94536DDEBB8C524
Content-Type: text/x-vcard; charset=us-ascii;
name="l.comber.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for lex comber
Content-Disposition: attachment;
filename="l.comber.vcf"
begin:vcard
n:Comber;Lex
tel;fax:+44 (0)1224 311556
tel;work:+44 (0)1224 318611
x-mozilla-html:FALSE
url:http://www.mluri.sari.ac.uk/
org:Macaulay Land Use Research Institute;Land Use Science
version:2.1
email;internet:l.comber@mluri.sari.ac.uk
adr;quoted-printable:;;Craigiebuckler,=0D=0A;Aberdeen,;;AB15 8QH;
fn:Lex Comber
end:vcard
--------------BA065179D94536DDEBB8C524--
Re: passing a variable into a file path
Author: Fedor Solodovnik
Date: Thu, 03 Jun 1999 00:00
Date: Thu, 03 Jun 1999 00:00
32 lines
1587 bytes
1587 bytes
"I:\ncms\squares\" & str(i) & ".dat" lex comber wrote: > > Apologies for the cross postings... > > A simple bit of advice for a novice needed: > > I have a list of files "0.dat" to "255.dat" > I am trying to pass a variable into a string to open a series of files > and am getting stuck on the line > > (For i = 0 To 255) > Workbooks.OpenText FileName:="I:\ncms\squares\" + i + ".dat", > Origin:= _ > xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=... > (...etc.. > Next i ) > > Any suggestions gratefully received > > Lex Comber > > ------------------------------------------------------------------------ > > Name: l.comber.vcf > l.comber.vcf Type: VCard (text/x-vcard) > Encoding: 7bit > Description: Card for lex comber -- Mailto:fsolodov@ntmail.desy.de
Re: passing a variable into a file path
Author: Eelco Mulder
Date: Thu, 03 Jun 1999 00:00
Date: Thu, 03 Jun 1999 00:00
8 lines
999 bytes
999 bytes
Workbooks.OpenText FileName:="I:\ncms\squares\" + i + ".dat" is so wrong because VB uses a '&' to glue things, you have to use Workbooks.OpenText FileName:="I:\ncms\squares\" & i & ".dat" Eelco Mulder EMulder at Ravelin.NL
Re: passing a variable into a file path
Author: Steven Barham [Ethno]
Date: Thu, 03 Jun 1999 00:00
Date: Thu, 03 Jun 1999 00:00
12 lines
1112 bytes
1112 bytes
You need to convert the integer variable i into a string variable (letters)
use the str function to do this -
str("123456") returns a string, "123456"
also, you should use & to fasten strings together technically, to avoid
confusion when using Variant data types.
Good luck
Steve
Re: passing a variable into a file path
Author: Karl Thomas
Date: Fri, 04 Jun 1999 00:00
Date: Fri, 04 Jun 1999 00:00
32 lines
1279 bytes
1279 bytes
Eelco Mulder wrote in message <7j5oo7$imc$1@zonnetje.NL.net>... >Workbooks.OpenText FileName:="I:\ncms\squares\" + i + ".dat" > >is so wrong because VB uses a '&' to glue things, you have to use No the problem isn't using the + for concatentation. Even though "&" is the preferred method the + will work. > >Workbooks.OpenText FileName:="I:\ncms\squares\" & i & ".dat" Have you tried your solution? It will give you a type mismatch error. Try: Workbooks.OpenText FileName:="I:\ncms\squares\" + cstr(i) + ".dat" > >Eelco Mulder >EMulder at Ravelin.NL > > >
Re: passing a variable into a file path
Author: Jon Helms
Date: Fri, 04 Jun 1999 00:00
Date: Fri, 04 Jun 1999 00:00
28 lines
1690 bytes
1690 bytes
This has been well answered already, but for future reference it would be helpful if you tell us how you are getting stuck, does it give an error message when you try "play" it in the IDE, does it give a RTE? Also the specific error message is helpful. Jon lex comber wrote: > > Apologies for the cross postings... > > A simple bit of advice for a novice needed: > > I have a list of files "0.dat" to "255.dat" > I am trying to pass a variable into a string to open a series of files > and am getting stuck on the line > > (For i = 0 To 255) > Workbooks.OpenText FileName:="I:\ncms\squares\" + i + ".dat", > Origin:= _ > xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=... > (...etc.. > Next i ) > > Any suggestions gratefully received > > Lex Comber
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads