Drag and Drop script 
Author Message
 Drag and Drop script

I want to create a script that you can drag a file onto and it will open
up the contents of that file in notepad.  But I also want to "for each"
through that file and add a line number and a space to the beginning of
each line. So a text file with:

<html>
<head>
  <title></title>
</head>

Would turn into:

1 <html>
2 <head>
3   <title></title>
4 </head>

I looked up the WScript.Arguments function but can't get it working with
a foreach statement.  I'm also not sure how to implement the count.
Could somebody help me out with this?  Here's what I started with but
it's not even close...

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objArgs = WScript.Arguments

set fso = createObject("scripting.filesystemobject")
set ts = fso.opentextfile("objArgs")
arTextLines = split(ts.readall,vbcrlf)
set ts = nothing
for each sTextLine in arTextLines
'For I = 0 to objArgs.Count - 1
  WScript.write("Count" & "sTextLine")
'WScript.echo objArgs(I)
  'Count = Count + 1
next



Wed, 18 Dec 2002 03:00:00 GMT  
 Drag and Drop script
Warren,

I just spotted this while looking for something else.  It does exactly what
you want.
http://cwashington.netreach.net/script_repository/view_scripts.asp?In...
&ScriptType=VBScript

--
Steve Yandl


Quote:
> I want to create a script that you can drag a file onto and it will open
> up the contents of that file in notepad.  But I also want to "for each"
> through that file and add a line number and a space to the beginning of
> each line. So a text file with:

> <html>
> <head>
>   <title></title>
> </head>

> Would turn into:

> 1 <html>
> 2 <head>
> 3   <title></title>
> 4 </head>

> I looked up the WScript.Arguments function but can't get it working with
> a foreach statement.  I'm also not sure how to implement the count.
> Could somebody help me out with this?  Here's what I started with but
> it's not even close...

> Set WshShell = WScript.CreateObject("WScript.Shell")
> Set objArgs = WScript.Arguments

> set fso = createObject("scripting.filesystemobject")
> set ts = fso.opentextfile("objArgs")
> arTextLines = split(ts.readall,vbcrlf)
> set ts = nothing
> for each sTextLine in arTextLines
> 'For I = 0 to objArgs.Count - 1
>   WScript.write("Count" & "sTextLine")
> 'WScript.echo objArgs(I)
>   'Count = Count + 1
> next



Wed, 18 Dec 2002 03:00:00 GMT  
 Drag and Drop script
if wscript.arguments.count = 0 then
  msgbox "Missing file name..."
  wscript.quit
end if
sFilename = WScript.Arguments(0)

set fso = createObject("scripting.filesystemobject")
if not fso.fileexists(sFilename) then
  msgbox "File not found..."
  wscript.quit
end if
set ts = fso.opentextfile(sFilename)
arTextLines = split(ts.readall,vbcrlf)
set ts = nothing

for n = 0 to ubound(arTextLines)
  arTextLines(n) = right("000" & n+1, 4) & " " & arTextLines(n)
next

set ie = createobject("internetexplorer.application")
ie.navigate "about:blank"

on error resume next : Do : err.clear
  while ie.document.readystate <> "complete" : wend
loop while err : on error goto 0

with ie
  .document.title = "Contents of: " & sFilename
  .addressbar = 0
  .menubar = 0
  .toolbar = 0
  .visible = 1
end with
with ie.document.body
  .innerhtml = join(arTextLines,"<br>")
  .style.font = "10pt courier new"
end with

--
Michael Harris
MVP Scripting

I want to create a script that you can drag a file onto and it will open
up the contents of that file in notepad.  But I also want to "for each"
through that file and add a line number and a space to the beginning of
each line. So a text file with:

<html>
<head>
  <title></title>
</head>

Would turn into:

1 <html>
2 <head>
3   <title></title>
4 </head>

I looked up the WScript.Arguments function but can't get it working with
a foreach statement.  I'm also not sure how to implement the count.
Could somebody help me out with this?  Here's what I started with but
it's not even close...

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objArgs = WScript.Arguments

set fso = createObject("scripting.filesystemobject")
set ts = fso.opentextfile("objArgs")
arTextLines = split(ts.readall,vbcrlf)
set ts = nothing
for each sTextLine in arTextLines
'For I = 0 to objArgs.Count - 1
  WScript.write("Count" & "sTextLine")
'WScript.echo objArgs(I)
  'Count = Count + 1
next



Wed, 18 Dec 2002 03:00:00 GMT  
 Drag and Drop script
Thanks, it works perfect.
Quote:

> if wscript.arguments.count = 0 then
>   msgbox "Missing file name..."
>   wscript.quit
> end if
> sFilename = WScript.Arguments(0)

> set fso = createObject("scripting.filesystemobject")
> if not fso.fileexists(sFilename) then
>   msgbox "File not found..."
>   wscript.quit
> end if
> set ts = fso.opentextfile(sFilename)
> arTextLines = split(ts.readall,vbcrlf)
> set ts = nothing

> for n = 0 to ubound(arTextLines)
>   arTextLines(n) = right("000" & n+1, 4) & " " & arTextLines(n)
> next

> set ie = createobject("internetexplorer.application")
> ie.navigate "about:blank"

> on error resume next : Do : err.clear
>   while ie.document.readystate <> "complete" : wend
> loop while err : on error goto 0

> with ie
>   .document.title = "Contents of: " & sFilename
>   .addressbar = 0
>   .menubar = 0
>   .toolbar = 0
>   .visible = 1
> end with
> with ie.document.body
>   .innerhtml = join(arTextLines,"<br>")
>   .style.font = "10pt courier new"
> end with

> --
> Michael Harris
> MVP Scripting


> I want to create a script that you can drag a file onto and it will open
> up the contents of that file in notepad.  But I also want to "for each"
> through that file and add a line number and a space to the beginning of
> each line. So a text file with:

> <html>
> <head>
>   <title></title>
> </head>

> Would turn into:

> 1 <html>
> 2 <head>
> 3   <title></title>
> 4 </head>

> I looked up the WScript.Arguments function but can't get it working with
> a foreach statement.  I'm also not sure how to implement the count.
> Could somebody help me out with this?  Here's what I started with but
> it's not even close...

> Set WshShell = WScript.CreateObject("WScript.Shell")
> Set objArgs = WScript.Arguments

> set fso = createObject("scripting.filesystemobject")
> set ts = fso.opentextfile("objArgs")
> arTextLines = split(ts.readall,vbcrlf)
> set ts = nothing
> for each sTextLine in arTextLines
> 'For I = 0 to objArgs.Count - 1
>   WScript.write("Count" & "sTextLine")
> 'WScript.echo objArgs(I)
>   'Count = Count + 1
> next



Wed, 18 Dec 2002 03:00:00 GMT  
 Drag and Drop script
That works good too, thanks.

Man there's a lot of possibilities with the WSH.  I started using Linux
for the scripting abilities but now with the WSH you get the best of
both worlds. :)

Quote:

> Warren,

> I just spotted this while looking for something else.  It does exactly what
> you want.
> http://cwashington.netreach.net/script_repository/view_scripts.asp?In...
> &ScriptType=vbscript

> --
> Steve Yandl



> > I want to create a script that you can drag a file onto and it will open
> > up the contents of that file in notepad.  But I also want to "for each"
> > through that file and add a line number and a space to the beginning of
> > each line. So a text file with:

> > <html>
> > <head>
> >   <title></title>
> > </head>

> > Would turn into:

> > 1 <html>
> > 2 <head>
> > 3   <title></title>
> > 4 </head>

> > I looked up the WScript.Arguments function but can't get it working with
> > a foreach statement.  I'm also not sure how to implement the count.
> > Could somebody help me out with this?  Here's what I started with but
> > it's not even close...

> > Set WshShell = WScript.CreateObject("WScript.Shell")
> > Set objArgs = WScript.Arguments

> > set fso = createObject("scripting.filesystemobject")
> > set ts = fso.opentextfile("objArgs")
> > arTextLines = split(ts.readall,vbcrlf)
> > set ts = nothing
> > for each sTextLine in arTextLines
> > 'For I = 0 to objArgs.Count - 1
> >   WScript.write("Count" & "sTextLine")
> > 'WScript.echo objArgs(I)
> >   'Count = Count + 1
> > next



Wed, 18 Dec 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Can you do drag-and-drop in script?

2. TreeView Drag n Drop don't allow dropping a parent into a child

3. Detect Drop in Drag and Drop

4. DRAG AND DROP

5. preventing print scrn and drag and drop of image in IE 5.5

6. ActiveX TreeView control not allowing drag drop

7. ActiveX TreeView Drag 'n Drop

8. ps2pdf shortcut for drag-n-drop (windows)

9. Drag-And-Drop

10. have you tried drag-and drop

11. have you ever tried drag-and-drop functionality in your Web page

12. How to disable drag and drop.

 

 
Powered by phpBB® Forum Software