Difference between VBScript in .hta and in .wsf -


i have simple bit of vbscript "pads" out .csv file have specific number of columns (useful when .csv file doesn't have uniform number of columns). .wsf file works when incorporated .hta file part of toolbox fails.

i'm not looking code such, more explanation on why fails in 1 file , not other. sorry poor code have ideas?

works.wsf

 <job id="csvpad"> <script language="vbscript">         dim delim, colnum     'set delim based on delimiter type of csv file: 1 = comma 2 = pipe 3 = caret         delim = 2     'set colnum based on number of columns pad out     colnum = 10     ''get location of .csv file     'set type of dialog box want use: 1 = open 2 = saveas 3 = file picker 4 = folder picker     const msofiledialogopen = 1     set fso = createobject("scripting.filesystemobject")     set objword = createobject("word.application")     set wshshell = createobject("wscript.shell")     'launch @ default path     strinitialpath = wshshell.expandenvironmentstrings("v:\toolbox\test")     objword.changefileopendirectory(strinitialpath)      objword.filedialog(msofiledialogopen)         .title = "select file process"         .allowmultiselect = false         .filters.clear         .filters.add "csv files / txt files", "*.csv; *.txt"         .filters.add "all files", "*.*"                       if .show = -1              each file in .selecteditems              set objfile = fso.getfile(file)              next          end if     end     objword.quit      dim ofso, oreg, objinputfile, objoutputfile, sline, lcount     const forreading = 1     set oreg = new regexp     set ofso = createobject("scripting.filesystemobject")     set objinputfile = ofso.opentextfile(objfile.path,1)     set objoutputfile = ofso.opentextfile(objfile.path&".bak",8,true)     until objinputfile.atendofstream         sline = objinputfile.readline         oreg.global = true         if delim = 1             oreg.pattern = ",(?=(([^""\\]|\\.)*""([^""\\]|\\.)*"")*([^""\\]|\\.)*$)"         elseif delim = 2             oreg.pattern = "\|(?=(([^""\\]|\\.)*""([^""\\]|\\.)*"")*([^""\\]|\\.)*$)"         elseif delim = 3             oreg.pattern = "\^(?=(([^""\\]|\\.)*""([^""\\]|\\.)*"")*([^""\\]|\\.)*$)"         end if         lcount = oreg.execute(sline).count + 1         while lcount < colnum             if delim = 1                 sline = sline + ","             elseif delim = 2                 sline = sline + "|"             elseif delim = 3                 sline = sline + "^"             end if             lcount = oreg.execute(sline).count + 1         loop         objoutputfile.writeline(sline)         set lcount = nothing     loop     objinputfile.close     objoutputfile.close     set ofso = nothing     set oreg = nothing     set delim = nothing     set sline = nothing     set lcount = nothing     msgbox "operation complete" </script> 

notwork.hta

 <job id="csvpad">  <head>     <title>support toolbox</title>     <hta:application       id="test"      applicationname="test"      border="thin"      contextmenu="no"      maximizebutton="no"      minimizebutton="yes"      resize="no"      scroll="no"      showintaskbar="yes"      singleinstance="yes"      windowstate="normal"      version="1.0"      navigable="yes"     />      <script language="vbscript">              sub padcsv             if isnumeric(csvpadno.value)                 dim delim, colnum                 if delimeter(0).checked                   delim = "1"                 end if                 if delimeter(1).checked                   delim = "2"                 end if                 if delimeter(2).checked                   delim = "3"                 end if                 'set colnum based on number of columns pad out                 colnum = csvpadno.value                 ''get location of .csv file                 'set type of dialog box want use: 1 = open 2 = saveas 3 = file picker 4 = folder picker                 const msofiledialogopen = 1                 set fso = createobject("scripting.filesystemobject")                 set objword = createobject("word.application")                 set wshshell = createobject("wscript.shell")                 'launch @ default path                 strinitialpath = wshshell.expandenvironmentstrings("v:\toolbox\test")                 objword.changefileopendirectory(strinitialpath)                  objword.filedialog(msofiledialogopen)                     .title = "select file process"                     .allowmultiselect = false                     .filters.clear                     .filters.add "csv files / txt files", "*.csv; *.txt"                     .filters.add "all files", "*.*"                                   if .show = -1                          each file in .selecteditems                          set objfile = fso.getfile(file)                          next                      end if                 end                 objword.quit                  dim ofso, oreg, objinputfile, objoutputfile, sline, lcount                 const forreading = 1                 set oreg = new regexp                 set ofso = createobject("scripting.filesystemobject")                 set objinputfile = ofso.opentextfile(objfile.path,1)                 set objoutputfile = ofso.opentextfile(objfile.path&".bak",8,true)                 until objinputfile.atendofstream                     sline = objinputfile.readline                     oreg.global = true                     if delim = 1                         oreg.pattern = ",(?=(([^""\\]|\\.)*""([^""\\]|\\.)*"")*([^""\\]|\\.)*$)"                     elseif delim = 2                         oreg.pattern = "\|(?=(([^""\\]|\\.)*""([^""\\]|\\.)*"")*([^""\\]|\\.)*$)"                     elseif delim = 3                         oreg.pattern = "\^(?=(([^""\\]|\\.)*""([^""\\]|\\.)*"")*([^""\\]|\\.)*$)"                     end if                     lcount = oreg.execute(sline).count + 1                     while lcount < colnum                         if delim = 1                             sline = sline + ","                         elseif delim = 2                             sline = sline + "|"                         elseif delim = 3                             sline = sline + "^"                         end if                         lcount = oreg.execute(sline).count + 1                     loop                     objoutputfile.writeline(sline)                     set lcount = nothing                 loop                 objinputfile.close                 objoutputfile.close                 set ofso = nothing                 set oreg = nothing                 set delim = nothing                 set sline = nothing                 set lcount = nothing                 msgbox "operation complete"             else                 msgbox "please enter number"              end if         end sub      </script> </head>  <body>     <span id="csvpad">         <div id="pagecsvpad" class="pagecsvpad">             <table class="csvpad" border="0" cellspacing="0" align="left">                 <tr>                     <td width=25%><b>delimiter type: </b></td>                     <td><input type="radio" name="delimeter" value="1" checked>comma</td>                     <td><input type="radio" name="delimeter" value="2">pipe</td>                     <td><input type="radio" name="delimeter" value="3">caret</td>                 </tr>                 <tr>                     <td>&nbsp;</td>                 </tr>                 <tr>                     <td colspan="2"><b>number of columns: </b></td>                     <td><input type="text" name="csvpadno"></td>                 </tr>                 <tr>                     <td>&nbsp;</td>                 </tr>                 <tr>                     <td><input type="button" value="browse" onclick="padcsv" name="radb"><br></tr>                 </tr>             </table>         </div>     </span> </body> 

the code changed allow input of values, me should work same.

am missing something?

thank's guys!

in line 78 of hta:

do while lcount < colnum 

you're not comparing think you're comparing. insert following line before above line , you'll see what's different:

msgbox "lcount: " & typename(lcount) & vbnewline & "colnum: " & typename(colnum) 

as resolving issue, change line:

colnum = csvpadno.value 

into this:

colnum = cint(csvpadno.value) 

and problem disappear.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -