Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


assignment error

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> assignment error
  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 >>
 assignment error - 8/11/2006 1:41:10 AM   
  cronid

 

Posts: 2
Score: 0
Joined: 8/1/2006
Status: offline
I am trying to assign the value "Z' to the third position in a string called contents, which I populated from a ReadAll statement.

This is the code:

      mid(contents,three,1) = "Z"

On it I get the error:  type mismatch: 'mid'

What is the problem?
 
 
Post #: 1
 
 RE: assignment error - 8/11/2006 1:59:02 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Mid() returns a value. It will not set a value. Use Left() and Right() and concatenation to build the string that you want.

_____________________________

"... 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 cronid)
 
 
Post #: 2
 
 RE: assignment error - 8/11/2006 2:23:45 AM   
  cronid

 

Posts: 2
Score: 0
Joined: 8/1/2006
Status: offline
Thanks.

I tried

right(left(contents,three),1) = "Z" but get the same message.

When I put that right(left(contents,three),1) in a MsgBox I do see the value I am trying to replace.

Do you see what this error still is?


(in reply to ebgreen)
 
 
Post #: 3
 
 RE: assignment error - 8/11/2006 2:31:20 AM   
  Country73


Posts: 716
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
Something like this:

myString = "ABCDEFGHIJKLMNOP"

LenString = LEN(myString)                    'this gives us the length of the string: 16
fString = LEFT(myString,2)                   'this takes the first two characters of the string: AB
lString = MID(myString,4,LenString)     'this takes the last portion of the string from character 4 to end: DEFGHIJKLMNOP
newString = fString & "Z" & lString       'combine first two characters, our new character, last portion of original string

MsgBox myString & vbcr & newString

< Message edited by Country73 -- 8/11/2006 2:34:38 AM >

(in reply to cronid)
 
 
Post #: 4
 
 RE: assignment error - 8/11/2006 3:37:39 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Or to one line it:

strTest = "This Is a String"
WScript.Echo "BEFOR: " & strTest
strResult = Left(strTest, 6) & Replace(strTest, Mid(strTest, 7, 1), "Z", 7, 1)
WScript.Echo "AFTER: " & strResult

_____________________________

"... 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 Country73)
 
 
Post #: 5
 
 
 
  

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 >> assignment error 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