|
-
Sep 27th, 2000, 08:16 PM
#1
Thread Starter
Frenzied Member
Code:
Open "C:\1.dat" For Output As #1
Write #1, "WAZZZZZZUPPPPPPPPP"
Close #1
Open "C:\2.dat" For Output As #1
Write #1, "WAZZZZZZUPPPPPPPPP"
Close #1
Open "C:\3.dat" For Output As #1
Write #1, "WAZZZZZZUPPPPPPPPP"
Close #1
is there a way to make that shorter?
NXSupport - Your one-stop source for computer help
-
Sep 27th, 2000, 08:18 PM
#2
Lively Member
Dim i as Integer
For i = 1 to 3
Open "C:\" & i & ".dat" For Output As #1
Write #1, "WAZZZZZZUPPPPPPPPP"
Close #1
Next
-
Sep 27th, 2000, 08:33 PM
#3
Fanatic Member
It's just a matter of setting up a function or sub (or a property for that matter ...)
Your code:
Code:
Open "C:\1.dat" For Output As #1
Write #1, "WAZZZZZZUPPPPPPPPP"
Close #1
Open "C:\2.dat" For Output As #1
Write #1, "WAZZZZZZUPPPPPPPPP"
Close #1
Open "C:\3.dat" For Output As #1
Write #1, "WAZZZZZZUPPPPPPPPP"
Close #1
The way I might do it.
Code:
Private Sub Main()
Dim Z As Integer
For Z = 1 to 3
SaveFile "C:\", Z & ".dat", "WAZZZZZZUPPPPPPPPP"
Next Z
End Sub
Private Sub SaveFile(fPath As String, fName As String, fOut as String)
Dim FF as Integer
FF = FreeFile()
If Right(fPath,1) <> "\" Then fPath = fPath & "\"
If fPath <> "" or fName <> "" Then
Open fPath & fName For Output as #FF
Write #FF, fOut
Close #1
End If
End Sub
I know the SaveFile subroutine might need a little bit of work, but you only have to write it once after that. I put in a minor bit of error handling with the filepath due to the problem with App.Path (if you intend to use that). If you're running your program from the root drive, App.Path does not add the trailing \, however, if it is a subdirectory off of the root or another directory, it does.
I used the FF = FreeFile() line to help reduce disk I/O conflicts. Since it looked like you were wanting to use 1-3 (or some other number) and putting them in basically the same file type with the same data, I thought it would be ok to use the for ... next loop. Though you can get rid of the for next and just plop in the parameters like this:
Code:
SaveFile <File Path>, <File Name>, <Data>
Hope this helps.
-Excalibur
-
Sep 27th, 2000, 09:11 PM
#4
Thread Starter
Frenzied Member
I tried putting this into VB Scipt and neither worked, how come?
NXSupport - Your one-stop source for computer help
-
Sep 27th, 2000, 09:18 PM
#5
Fanatic Member
This is due to how VBScript works.
Try not declaring any of the variables with a type. This would make them all variants (which is what VBScript likes to work with, as I understand it).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|