VBScript runtime error in script filter called "field maths"

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

DFH
Posts: 644
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

VBScript runtime error in script filter called "field maths"

Postby DFH » Sun Oct 30, 2011 5:24 am

In the script filter called "field maths", I get

Code: Select all

[13] Microsoft VBScript runtime error:Type mismatch at line:9, char:2near:
when using the Trial Run data.

Line 9 reads

Code: Select all

  fields = split( line, chr(9) )


Code: Select all

'Perform maths on tab delimited fields

'Called for every line in the file
'EOL contains the end of line characters (Unix, DOS or Mac) that must be
'appended to each line
function processLine(line, EOL)
  'ie a tab
  dim fields(3)
  fields = split( line, chr(9) )
  redim preserve fields(4)
  fields(3) = fields(1) / fields(2)
  processLine = join(fields, chr(9)) & EOL
end function


'Called at the start of a processing job -
'perform one-time initialisation here
sub startJob()
end sub


'Called at the end of a processing job -
'destroy any declared objects here
sub endJob()
  'do nothing
end sub


'Called before each file is opened -
'perform per-file initialisation here
function startFile()
  startFile = ""
end function


'Called before each file is closed -
'flush all pending file output here
function endFile()
  endFile = ""
end function


Please explain why.

If this filter doesn't work, please correct it before the next release of TextPipe.

DFH
Posts: 644
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

Re: VBScript runtime error in script filter called "field ma

Postby DFH » Mon Oct 31, 2011 10:18 pm

Got it!

The problem is actually in line 8.

Code: Select all

  dim fields(3)

This should read

Code: Select all

  dim fields

Then the filter works, and trial run outputs as follows:

Code: Select all

2009-06-06   61383.9200   10529.8651   5.82950678067091   
2009-06-07   42263.6000   10089.0255   4.18906662491833   
2009-06-08   23442.0400   10904.0565   2.14984579362735   
2009-06-09   22708.4600   6829.3108   3.32514666048   
2009-06-10   .0000   6656.4652   0   
2009-06-11   64457.2700   6503.6794   9.91089290163965   
2009-06-12   65525.3200   7755.4558   8.44893216978943   
2009-06-13   61298.4800   9503.1016   6.45036563641496   
2009-06-14   24457.5700   10175.7505   2.40351510190821   

That's not quite the whole story, because there is an extra tab in the output lines.
This is because line 10 reads

Code: Select all

  redim preserve fields(4)

Changing line 10 to

Code: Select all

  redim preserve fields(3)

fixes this secondary bug.
The trial output then becomes

Code: Select all

2009-06-06   61383.9200   10529.8651   5.82950678067091
2009-06-07   42263.6000   10089.0255   4.18906662491833
2009-06-08   23442.0400   10904.0565   2.14984579362735
2009-06-09   22708.4600   6829.3108   3.32514666048
2009-06-10   .0000   6656.4652   0
2009-06-11   64457.2700   6503.6794   9.91089290163965
2009-06-12   65525.3200   7755.4558   8.44893216978943
2009-06-13   61298.4800   9503.1016   6.45036563641496
2009-06-14   24457.5700   10175.7505   2.40351510190821
without the extra tabs after the calculated field.

David

DFH
Posts: 644
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

Re: VBScript runtime error in script filter called "field ma

Postby DFH » Mon Oct 31, 2011 10:21 pm

NB. To show the difference between the above outputs, you need to use SELECT ALL in the code section headings.

User avatar
DataMystic Support
Site Admin
Posts: 2154
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: VBScript runtime error in script filter called "field ma

Postby DataMystic Support » Wed Nov 02, 2011 12:17 pm

Thanks David - updated for next release. It looks like the vbscript array is now zero-based not 1-based.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

DFH
Posts: 644
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

Re: VBScript runtime error in script filter called "field ma

Postby DFH » Fri Nov 04, 2011 11:02 pm

I think it always was zero based as regards the indexing, but I guess that the redimensioning statement has been made more consistent for dynamic arrays.

I have the O'Reilly book VBScript in a Nutshell in front of me.

Have you checked whether any other script filters had the same problem?

David

User avatar
DataMystic Support
Site Admin
Posts: 2154
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: VBScript runtime error in script filter called "field ma

Postby DataMystic Support » Mon Nov 07, 2011 7:53 am

I've checked through all the filters in the vbscript folder manually and no other problems were found.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: No registered users and 2 guests