Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


vbTextCompare & vbBinaryCompare

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> vbTextCompare & vbBinaryCompare
  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 >>
 vbTextCompare & vbBinaryCompare - 5/30/2007 1:17:46 AM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
What's the differnce between the 2, in terms of using InStr? The VB reference docs aren't very clear on this.

What I'm trying to do is find a way to replace the 1st space in a line of text with a comma, but then all subsequent spaces with a dash.

So:

1111 AAA BBB should become 1111,AAA-BBB and so on.

Any ideas? I thought InStr might be where to start
 
 
Post #: 1
 
 RE: vbTextCompare & vbBinaryCompare - 5/30/2007 1:22:28 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
try this:

Option Explicit
Dim strTest
strTest = "1111 AAA BBB"
strTest = Replace(Replace(strTest, " ", ",", 1, 1), " ", "-")
WScript.Echo strTest

_____________________________

"... 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 markmcrobie)
 
 
Post #: 2
 
 RE: vbTextCompare & vbBinaryCompare - 5/30/2007 1:31:24 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
To answer your question regarding the difference between the two comparison methods, essentially vbTextCompare is case insensitive while vbBinaryCompare (which is the default) is case sensitive.

_____________________________

"... 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 ebgreen)
 
 
Post #: 3
 
 RE: vbTextCompare & vbBinaryCompare - 5/30/2007 1:38:19 AM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
In an attempt to solve what I'm trying to do, I came up with the following:


      

But I get an "invalid procedure call" on the 1st line with Replace.

Any ideas?

(in reply to ebgreen)
 
 
Post #: 4
 
 RE: vbTextCompare & vbBinaryCompare - 5/30/2007 1:45:33 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
If you use the optional "Compare" parameter then you must use the optional "Start" parameter:

Are you sure that every single entry in arrD has a space in it. If it does not have a space, then intFirstSpace will be set to 0 which is not valid.

_____________________________

"... 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 markmcrobie)
 
 
Post #: 5
 
 RE: vbTextCompare & vbBinaryCompare - 5/30/2007 1:57:28 AM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
Ok, first of all my problem was a dreaded blank line at the end of the text file I'm reading in.  Having got round that, my new problem is Replace is replacing everything BEFORE the 1st space.

So given a line:

11111 AAA BBB CCC

The code:


      

Is turning that line into:

,AAA-BBB-CCC

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: vbTextCompare & vbBinaryCompare - 5/30/2007 2:02:05 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
For the first replace, just tell it to start at the beginning and replace the firts space that it sees, so change these lines:

intFirstSpace = InStr(entry," ")
entry = Replace(entry," ",",",intFirstSpace,1)

with this line:

entry = Replace(entry," ",",",1,1)

_____________________________

"... 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 markmcrobie)
 
 
Post #: 7
 
 RE: vbTextCompare & vbBinaryCompare - 5/30/2007 2:10:40 AM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
Thanks, believe it or not I sussed it out myself.  The whole function works now, no matter if there are blank lines at the end of the text file:


      

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: vbTextCompare & vbBinaryCompare - 5/30/2007 2:13:30 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
Cool. Glad you got it worked out.

_____________________________

"... 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 markmcrobie)
 
 
Post #: 9
 
 
 
  

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 >> vbTextCompare & vbBinaryCompare 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