0 Replies - 954 Views - Last Post: 30 April 2008 - 07:09 AM Rate Topic: -----

#1 MattGooch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-March 08

Problems using Loops and Text Files

Posted 30 April 2008 - 07:09 AM

Hi, I have been making a VB program for a while but am stuck on 2 things.

here is my problem code
Location = FolderChoiceTextBox.Text + "\copy.bat"

		FileOpen(1, Location, OpenMode.Output) 'open text file for writing

		'used in the loop
		Dim pa As Integer

		PrintLine(1, "@echo off") 'autorun.inf
		PrintLine(1, ":: variables") 'autorun.inf
		PrintLine(1, "set drive=", locationdrive.Text) 'autorun.inf
		PrintLine(1, "set backupcmd=xcopy /s /c /d /e /h /i /r /k /y") 'autorun.inf

		'loop round each item in the list box
		Do While pa < CheckedListBox1.Items.Count
			PrintLine(1, "echo ### Backing up Selected Documents...") '
			PrintLine(1, "%backupcmd%", Chr(34) & CheckedListBox1.Items.Item(pa) & Chr(34) & "%drive%\", outputdir.Text & Chr(34)) 'this line here currently output the user selected path and then the output drive
			pa = pa + 1

		PrintLine(1, "echo Backup Complete!") 'autorun.inf INPUTS
		PrintLine(1, "@pause") 'autorun.inf INPUTS


That outputs a .bat file when the save button is clicked the output of the file looks like this:

@echo off
:: variables
set drive=	sssw

set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

echo ### Backing up Selected Documents...
%backupcmd%   "C:\Documents and Settings\Matthew gooch\My Documents\My Pictures\untitled.bmp"%drive%\		   "

echo Backup Complete!

When I run the bat file it doesnt work, which i think is due to the large gaps between:

set drive= sssw


%drive%\ "

Is there anyway to stop VB outputting it like this ?

The second problem is a little more complex (i think) than the first. In the program I have a text box which is used to fill in the drive path(marked in red) which will be used as an output folder for the little bat file this program creates.

PrintLine(1, "%backupcmd%", Chr(34) & CheckedListBox1.Items.Item(pa) & Chr(34) & "[color=#FF0000]%drive%\", outputdir.Text [/color]& Chr(34)) 

Breakdown of code:

PrintLine(1, "%backupcmd%", In here goes a file that the user has selected a JPG,GIF,PDF etc etc the output looks like (C:\image.jpg) & "drive%\", In here should go an output folder on the drive selected (output folder).)

So my problem is if i enter an output folder into outputdir.Text then it adds the output folder i entered to every file added to the list due to the loop in my code. I need it so if outputdir.text has text in it it then atatches it to that user selcected file only then continues around the loop.

I can send the compelte source of .exe if necassery on request.

Thanks in advance for the help

Is This A Good Question/Topic? 0
  • +

Page 1 of 1