Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


replace parameters in text file

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61451
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> replace parameters in text file
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 replace parameters in text file - 6/16/2008 7:57:29 PM   
  avipenina

 

Posts: 101
Score: 0
Joined: 4/24/2006
Status: offline
Hi,

I've a file that have in it a lot of parameters that the name is @P1,@P2,@P3  etc
i need to replace those parameters with values that are in the end of the file or i can put the values in a different file to read it from there.
can it be done?

THX
 
 
Post #: 1
 
 RE: replace parameters in text file - 6/16/2008 8:17:06 PM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi avipenina,

yes. Have a look at

  http://www.visualbasicscript.com/fb.aspx?m=52215

Perhaps it would help, if you post a sample of your input file.

Regards

ehvbs

(in reply to avipenina)
 
 
Post #: 2
 
 RE: replace parameters in text file - 6/16/2008 8:23:48 PM   
  avipenina

 

Posts: 101
Score: 0
Joined: 4/24/2006
Status: offline
i couldn't figure out how to set it to my file.

my main file

select pilot.dbo.CUSTOMERS.CUSTNAME , case when ( ( coalesce( pilot.dbo.NSCUST.CUSTDES , '''' ) = rtrim(ltrim(reverse( @P1 ))) ) ) then ( pilot.dbo.CUSTOMERS.CUSTDES ) else ( coalesce( pilot.dbo.NSCUST.CUSTDES , '''' ) ) end , pilot.dbo.ORDERS.CURDATE , pilot.dbo.ORDERS.ORDNAME , pilot.dbo.ORDERS.BOOKNUM , pilot.dbo.DOCUMENTS.DOCNO , pilot.dbo.ORDSTATUS.ORDSTATUSDES , pilot.dbo.ORDSTATUS.XVR_GRADING , case when ( ( pilot.dbo.ORDERS.CLOSED = @P2 ) ) then ( @P3 ) else ( @P4 ) end , case when ( ( pilot.dbo.ORDERS.PCLOSED = @P5 ) ) then ( @P6 ) else ( @P7 ) end , pilot.dbo.CPROF.CPROFNUM , pilot.dbo.DEAL.ORDNAME , pilot.dbo.ORDERS.DETAILS , pilot.dbo.ORDERS.REFERENCE , (0.0 + ( convert(decimal(19,2), pilot.dbo.ORDERS.QPRICE) ))

the input file

,'','C','Y',' ','C','Y',' '


this is only partial main file and input file

< Message edited by avipenina -- 6/16/2008 8:43:04 PM >

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: replace parameters in text file - 6/16/2008 8:49:22 PM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi avipenina,

(1) so you want to work with 2 files?

(2) given ... reverse( @P1 ) ... pilot.dbo.ORDERS.CLOSED = @P2 ... ( @P3 ) else ( @P4 )
      and >> ,'','C','Y',' ','C','Y',' '<<
      what should the result look like? (I want to know what to replace with what)

Regards

ehvbs

(in reply to avipenina)
 
 
Post #: 4
 
 RE: replace parameters in text file - 6/16/2008 9:12:54 PM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Some POC code:


      

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: replace parameters in text file - 6/16/2008 10:03:30 PM   
  avipenina

 

Posts: 101
Score: 0
Joined: 4/24/2006
Status: offline
this syntax has about 58 of that @P1,@P2,@P3 until @P58
i need to replace each @P with the first replacement like that
@P1 = ''
@P2 = 'C'
@P3 = 'Y'
etc  until @P58


replacements
'','C','Y',' ','C','Y',' ' ,etc

yes it should look like your code.

example

select pilot.dbo.CUSTOMERS.CUSTNAME , case when ( ( coalesce( pilot.dbo.NSCUST.CUSTDES , '''' ) = rtrim(ltrim(reverse( ''))) ) ) then ( pilot.dbo.CUSTOMERS.CUSTDES ) else ( coalesce( pilot.dbo.NSCUST.CUSTDES , '''' ) ) end , pilot.dbo.ORDERS.CURDATE , pilot.dbo.ORDERS.ORDNAME , pilot.dbo.ORDERS.BOOKNUM , pilot.dbo.DOCUMENTS.DOCNO , pilot.dbo.ORDSTATUS.ORDSTATUSDES , pilot.dbo.ORDSTATUS.XVR_GRADING , case when ( ( pilot.dbo.ORDERS.CLOSED = 'C') ) then ( 'Y') else ( ' ') end , case when ( ( pilot.dbo.ORDERS.PCLOSED = 'C') ) then ( 'Y') else ( ' ') end , pilot.dbo.CPROF.CPROFNUM , pilot.dbo.DEAL.ORDNAME , pilot.dbo.ORDERS.DETAILS , pilot.dbo.ORDERS.REFERENCE , (0.0 + ( convert(decimal(19,2), pilot.dbo.ORDERS.QPRICE) ))

the input file

,'','C','Y',' ','C','Y',' '

i've 58 @P and 58 replacements

< Message edited by avipenina -- 6/16/2008 10:08:21 PM >

(in reply to ehvbs)
 
 
Post #: 6
 
 RE: replace parameters in text file - 6/16/2008 10:55:47 PM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi avipenina,

if you can solve the problem of 'empty' parameters, i see no reason, why my POC wouldn't work.

Of course, answering my question about the desired result - e.g.

  ... reverse( @P1 ) ... pilot.dbo.ORDERS.CLOSED = @P2 ... ( @P3 ) else ( @P4 )

==>

... reverse( '' ) ... pilot.dbo.ORDERS.CLOSED = @P2 ... ( @P3 ) else ( @P4 )

or

  ... reverse( '' ) ... pilot.dbo.ORDERS.CLOSED = @P2 ... ( @P3 ) else ( @P4 )

or

    ... reverse(  ) ... pilot.dbo.ORDERS.CLOSED = @P2 ... ( @P3 ) else ( @P4 )

or
 
   ...

would help me to help you.

Regards

ehvbs

(in reply to avipenina)
 
 
Post #: 7
 
 RE: replace parameters in text file - 6/16/2008 11:06:09 PM   
  avipenina

 

Posts: 101
Score: 0
Joined: 4/24/2006
Status: offline
i need to take my syntax and replace it with the replacement that are there.i can't change anything in the replacement at all.
if there are '' or ' ' i need them.
the result should be the syntax like it is but instead of @P the current replacement.

I've add a file for my full syntax.
add the bottom you can see the replacement from 1 to 58.every 1 replacement needs to replace 1 @P,starting from @P1,@P2 etc.

THX

Attachment (1)

< Message edited by avipenina -- 6/16/2008 11:07:20 PM >

(in reply to ehvbs)
 
 
Post #: 8
 
 RE: replace parameters in text file - 6/17/2008 12:03:06 AM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi avipenina,

See if this:


      

does what you want.

Good luck!

ehvbs

(in reply to avipenina)
 
 
Post #: 9
 
 RE: replace parameters in text file - 6/17/2008 12:24:39 AM   
  avipenina

 

Posts: 101
Score: 0
Joined: 4/24/2006
Status: offline
i try the script but it's not working like i need.
first it doesn't replace the @P like it should be.
second it leave the number of the @P,example look at @P58 after the replace that it's not the current replace that should be,it leave the eight (8) number after the 'C' replace that shouldn't be there.the number that replace @P58 is '1001431'

THX

(in reply to ehvbs)
 
 
Post #: 10
 
 RE: replace parameters in text file - 6/17/2008 12:38:45 AM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi avipenina,

Ok, let's look at the @P58:

  ... CUSTNAME = @P58 ...

the (bad) result is:

  ... CUSTNAME = 'C'8 ...

So "@P58" is treated as "@P5" + "8". And, for sure, "4 >@P5< >'C'<".
Looks like replacing the small (1 digit) numbers first is a very bad idea.
How do we change

        For nIdx = 0 To UBound( aRpl )

Eagerly waiting for your answer!

ehvbs

(in reply to avipenina)
 
 
Post #: 11
 
 RE: replace parameters in text file - 6/17/2008 1:00:29 AM   
  avipenina

 

Posts: 101
Score: 0
Joined: 4/24/2006
Status: offline
i don't understand what you ask from me?

(in reply to ehvbs)
 
 
Post #: 12
 
 RE: replace parameters in text file - 6/17/2008 1:07:36 AM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
I ask you to do a little bit of bug/design error hunting of your own. Can't you explain
why the program as it is, especially with the line

  For nIdx = 0 To UBound( aRpl )

will change/replace "@P58" with "'C'8", given the additional info that "'C'"
is the replacement for "@P5"?

(in reply to avipenina)
 
 
Post #: 13
 
 RE: replace parameters in text file - 6/17/2008 1:41:53 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Yay! Ehvbs is on the teaching train too!

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 14
 
 RE: replace parameters in text file - 6/17/2008 3:27:09 AM   
  avipenina

 

Posts: 101
Score: 0
Joined: 4/24/2006
Status: offline
if i would know how to write this vb script code i wouldn't ask you guys,but thanks anyway.

(in reply to ebgreen)
 
 
Post #: 15
 
 RE: replace parameters in text file - 6/17/2008 5:18:57 AM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi avipenina,

ok, because it was my error and I can't/won't force you to do something you don't like:

Looping thru the placeholders "@P1", .. "@P10", .. "@P58" in that order by starting the
loop like

    For nIdx = 0 To UBound( aRpl )

was a very bad idea: Given that sFrom is "@P1", the replacement in

   sMain = Replace( sMain, sFrom, sTo )

will affect "@P1", "@P10", "@P11", ... "@P19" (that is why I use placeholders
like "@xxx@", if I have the choice). The remedy is to loop the other way around:

    For nIdx = UBound( aRpl ) To 0 Step -1

so that the bigger markers will be replaced first ("@P58" can't affect "@P5").

Regards

ehvbs

(in reply to avipenina)
 
 
Post #: 16
 
 RE: replace parameters in text file - 6/17/2008 6:34:15 AM   
  avipenina

 

Posts: 101
Score: 0
Joined: 4/24/2006
Status: offline
thx.
it's not that i don't want it's that i don't know how.
the script works find.
THX

(in reply to ehvbs)
 
 
Post #: 17
 
 RE: replace parameters in text file - 6/17/2008 6:55:31 AM   
  ehvbs

 

Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi avipenina,

you are welcome - and no hard feelings, I hope.

Regards

ehvbs

(in reply to avipenina)
 
 
Post #: 18
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> replace parameters in text file Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts