PDA

View Full Version : Problem with VB Script statement


Green4Ever
11-07-02, 07:20
Hello, I've got a problem with the following statement:

help=mid( DTSSource("VARIABLES") , InStr( 1 , DTSSource("VARIABLES") ,"&PN=" , 1 )+3, Instr(InStr( 1 , DTSSource("VARIABLES") , "&PN=" , 1 ), DTSSource("VARIABLES"),"&",1) - (InStr( 1 , DTSSource("VARIABLES") , "&PN=" , 1 )+3))

Do you know what's wrong?

Thx!

Bruce A. Baasch
11-07-02, 12:18
Hello Green4Ever,

Your statement is generating the same value for the second InStr that it did for the first InStr. You are ending up with help = Mid$(DTSSOURCE("VARIABLES"),N,-3). You need to change Instr(InStr( 1 , DTSSource("VARIABLES") , "&PN=" , 1 ), DTSSource("VARIABLES"),"&",1) to Instr(InStr( 1 , DTSSource("VARIABLES") , "&PN=" , 1 )+1, DTSSource("VARIABLES"),"&",1) to correct this.

You could also try setting a variable = InStr(1,DTSSOURCE("VARIABLES"),"&PN=",1) outside the expression to make it easier to read and faster to execute as follows.

lclSplit = InStr( 1 , DTSSource("VARIABLES") , "&PN=" , 1 )

help = mid( DTSSource("VARIABLES") , lclSplit+3, Instr(lclSplit+1, DTSSource("VARIABLES"),"&",1) - lclSplit+3)

Good Luck with your strings,

rnealejr
11-08-02, 13:32
For your future reference, when you have a problem like this in your code, you can split your complex statement into smaller simpler statements and merge together under the mid function. This would allow you to "step" through the smaller statements to see if there is a problem.

And you may want to be more specific as to what the problem is.