Question Writing in text-file using 2 arrays

jorrex

New member
Joined
Nov 2, 2011
Messages
4
Programming Experience
1-3
hi there,


I'm trying to solve a problem I'm having with writing in a text file using 2 arrays

the first array is the normal text, line by line
e.g.

dim arrCode as string()

arrcode(0) = "This is the first line"
arrcode(1) = "The second line etc."

now, the 2nd array would have to be implemented in the first array.
I'm using this array to get the filenames from a specific folder.
but now my question is, how do I write these filename in the same textfile as the first array?

Considering there is some text after the filenames, I haven't got a clue how to mix these 2 together :/
I thought it may be possible to work with a For Each to write these in the textfile.
but if there are any other suggestions, better ones, feel free to share them.

I'm stuck and it's sort of a huge assignment for me, and I can't put the pieces in the right place.
If I'm unclear 'bout my situation, I can post my code, or an example of what I mean exactly.

thanks you guys!
 
Use a 2-dimensional array...

arrcode(0,0) = "Something"
arrcode(0,1) = "Something else"
...

Except your description is vague at best.

Please supply a sample of real-world data and the exact goal of this...
 
the code

What I mean is, to explain it with a part of my code

I need to write a VBScript with VB.net when a button is clicked, when clicked, the script needs to be written.
And to do this is, I'm using an array to write the specific lines in the textfile (or VBScript in this case)
All this is fine, but there's something extra needed in the textfile, and this is the names of the files of a specific folder.

The code for the array, to write specific lines in the textfile:

Dim arrCode(34) As String

arrCode(0) = "dim filesys"
arrCode(1) = "set filesys=CreateObject(""Scripting.FileSystemObject"")"
arrCode(2) = "If filesys.FileExists(""" & strNaam & "\*.*""" & ") Then "
arrCode(3) = "filesys.Copyfile """ & strNaam & "" & "\*.*"", """ & strDoel & "\" & """"
arrCode(4) = "End If"
arrCode(5) = "'*************************************************************************"
arrCode(6) = "if filesys.FileExists(""" & strDoel & "\*.*" & """) Then"
arrCode(7) = "Set objEmail = CreateObject(""CDO.Message"")"
arrCode(8) = "objEmail.From = ""8_GIP_Opdracht@gmail.com"""
arrCode(9) = "objEmail.To=""verstroate.jorre@gmail.com"""
arrCode(10) = "objEmail.Subject=""Kopieren voltooid"""
arrCode(11) = "objEmail.Textbody = ""Het kopieren is geslaagd. De volgende bestanden zijn gekopieerd: """
This is were the second array should kick in, but explained under all this
arrCode(12) = "objEmail.configuration.fields.item _"
arrCode(13) = "(""http://schemas.microsoft.com/cdo/configuration/sendusing"")=2"
arrCode(14) = "objEmail.Configuration.Fields.Item _"
arrCode(15) = "(""http://schemas.microsoft.com/cdo/configuration/smtpserver"")= _"
arrCode(16) = """uit.telenet.be"""
arrCode(17) = "objEmail.Configuration.Fields.Update"
arrCode(18) = "objEmail.Send"
arrCode(19) = "End If"
arrCode(20) = "'************************************************************************"
arrCode(21) = "if not filesys.FileExists(""" & strDoel & "\*.*"") Then"
arrCode(22) = "Set objEmail = CreateObject(""CDO.Message"")"
arrCode(23) = "objEmail.From = ""8_GIP_Opdracht@gmail.com"""
arrCode(24) = "objEmail.To=""verstroate.jorre@gmail.com"""
arrCode(25) = "objEmail.Subject=""Kopieren gefaald"""
arrCode(26) = "objEmail.Textbody = ""Het kopieren is niet geslaagd, de taak is mislukt."""
arrCode(27) = "objEmail.configuration.Fields.item _"
arrCode(28) = "(""http://schemas.microsoft.com/cdo/configuration/sendusing"")=2"
arrCode(29) = "objEmail.Configuration.Fields.Item _"
arrCode(30) = "(""http://schemas.microsoft.com/cdo/configuration/smtpserver"")= _"
arrCode(31) = """uit.telenet.be"""
arrCode(32) = "objEmail.Configuration.Fields.Update"
arrCode(33) = "objEmail.Send"
arrCode(34) = "End if"

For i = 0 To 34
objWriter.WriteLine(arrCode(i))
Next

objWriter.Close()


Now this code is what I've been able to compose to get the filenames, except they'd have to be written in the same textfile as above, so I'd have to invoke this array in the first one, this is were I'm stuck 'cause of the arraylocationnumber (0-34), I suppose the second one will have to pick up where the first one stopped and clockwise, the first one will have to pick up where the second one stops to keep writing, unless there's a more simple solution to this.

But anyway, the code for the filenames goes like this:


Dim strFileSize As String = "" Dim di As New IO.DirectoryInfo("C:\data") Dim aryFi As IO.FileInfo() = di.GetFiles("*.txt") Dim fi As IO.FileInfo For Each fi In aryFi Messagebox.Show(fi.Name & VbCrlf) Next

So these 2 arrays would have to be mixed in each other to be able to write the filenames in the textfile.
How do I do this?
The actual part were I'm stuck is where the arrays need to pick up each others line where they left of.
If you know what I mean ...


thnx a bunch!
 
seems like the 2nd array code was a bit mixed up

Dim di as New IO.DirectoryInfo("C:\data")
Dim aryFi as IO.FileInfo() = di.GetFiles("*.txt")
Dim fi As IO.FileInfo

For Each fi in aryFi
Messagebox.Show(fi.Name & VbCrlf)
Next
 
You should probably use resources instead. Because the largest part of the script is static and need no modification, you can split it in two. I did something very similar recently. I split an entire script in 7 parts, part 1 being top of the script (declarations), parts 2 to 6 being code formatting, part 7 being the whole rest of the script. Something like this:

ScriptPart1:
VB.NET:
Option Explicit

'###############################################################################
'### Modify these settings to suit your needs. If username and password are left
'### empty we use Windows security. Make sure that SQL Server has permissions to
'### the backup path.


	SQLDataSource  =  "

ScriptPart2:
VB.NET:
"
	SQLDatabase    =  "

ScriptPart3:
VB.NET:
"

MsgBox SQLDataSource & VbCrLf & SQLDatabase

Then in code use My.Resources to get the different parts of the script together with your variables:
VB.NET:
                System.IO.File.WriteAllText(SaveFileDialog.FileName, My.Resources.BackupScriptPart1 & ConnectionString.DataSource & _
                                                                     My.Resources.BackupScriptPart2 & ConnectionString.InitialCatalog & _
                                                                     My.Resources.BackupScriptPart3)
 
Thank you!

Thanks you for your reply, your solution actually did the trick!

so far, I'm almost there with my program :)
there's just one tiny little thing that isn't working yet.

I don't suppose you'd have an answer for that either?
It's where I'm programming a scheduled task through CMD, but the option "run when user is logged on" should be disabled.

I do know the command line is like this:
schtasks /create /tn Something /tr c:\whatever\script.vbs /sc once /sd 11/11/2011 /st 19:00 (European time)

But how do I enable this option when I'm supposed to run the task when I'm not logged in on my Server 2008 (I know this isn't the right forum to ask it on, but you never know)
 
Back
Top