From: mrkramer on 17 Apr 2010 09:17 Hello I'm newbie on vbs programing. I'm trying use subsstring method, but I get error "object required 'helo great world'" and code:800A01A08. ------- dim str str="helo great world" wscript.echo str.substring(5,10) --------------------- It is wierd for me because documentation says: strVariable.substring(start, end) "String Literal".substring(start, end) It is possible that substring method is only in Jscript?
From: Richard Mueller [MVP] on 17 Apr 2010 09:59 "mrkramer" <hhfm(a)poczta.fm> wrote in message news:4bc9b4cc$0$19174$65785112(a)news.neostrada.pl... > Hello > > I'm newbie on vbs programing. I'm trying use subsstring method, but I get > error "object required 'helo great world'" and code:800A01A08. > > ------- > dim str > str="helo great world" > wscript.echo str.substring(5,10) > --------------------- > > > It is wierd for me because documentation says: > > strVariable.substring(start, end) > "String Literal".substring(start, end) > > > It is possible that substring method is only in Jscript? The expression "str.substr(5,10)" implies that substr is a method of a object str. The variable str is not an object reference, but a string. All object references in VBScript are established with "Set" statements, as in: Set objShell = CreateObject("Wscript.Shell") There is no substring function in VBScript (that I am aware of). Your example looks more like .NET to me. I note that when I search for syntax examples I frequently find .NET examples. I don't know what documentation you found, but the example is definitely not VBScript. I believe the Mid function does what you intend. For example: str = "helo great world" Wscript.Echo Mid(str, 5, 10) This will echo the string "great worl". Or, since the third parameter of the Mid function is optional, you could try: Wscript.Echo Mid(str, 5) which would result in "great world". For VBScript documentation, download the help file script56.chm at this link: http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net --
From: mrkramer on 17 Apr 2010 10:17 Richard Mueller [MVP] napisal w dniu 2010-04-17 15:59: > "mrkramer"<hhfm(a)poczta.fm> wrote in message > news:4bc9b4cc$0$19174$65785112(a)news.neostrada.pl... >> Hello >> >> I'm newbie on vbs programing. I'm trying use subsstring method, but I get >> error "object required 'helo great world'" and code:800A01A08. >> >> ------- >> dim str >> str="helo great world" >> wscript.echo str.substring(5,10) >> --------------------- >> >> >> It is wierd for me because documentation says: >> >> strVariable.substring(start, end) >> "String Literal".substring(start, end) >> >> >> It is possible that substring method is only in Jscript? > > The expression "str.substr(5,10)" implies that substr is a method of a > object str. The variable str is not an object reference, but a string. All > object references in VBScript are established with "Set" statements, as in: > > Set objShell = CreateObject("Wscript.Shell") > > There is no substring function in VBScript (that I am aware of). Your > example looks more like .NET to me. I note that when I search for syntax > examples I frequently find .NET examples. I don't know what documentation > you found, but the example is definitely not VBScript. I believe the Mid > function does what you intend. For example: > > str = "helo great world" > Wscript.Echo Mid(str, 5, 10) > > This will echo the string "great worl". Or, since the third parameter of the > Mid function is optional, you could try: > > Wscript.Echo Mid(str, 5) > > which would result in "great world". For VBScript documentation, download > the help file script56.chm at this link: > > http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en > I'm using exactly the same help file. There is substring method, but as I said previously, i'm afraid that is Jscript method only. Mid function is good and is similar to substring. I'll use mid function. Thanks for help
From: Mayayana on 17 Apr 2010 10:41 | > http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en | > | I'm using exactly the same help file. There is substring method, but as | I said previously, i'm afraid that is Jscript method only. Yes. They used to provide separate help files, but now it's all in the WSH help. (Apparently they were spending too much on paper with multiple CHMs. :) Now you have to check at the top of the topic page to make sure you've got a VBScript topic. There is a file called vbscrip5.chm. I have a copy. You might do a search for that if you want to have a straight VBS reference.
From: Richard Mueller [MVP] on 17 Apr 2010 10:57
"mrkramer" <hhfm(a)poczta.fm> wrote in message news:4bc9c2fe$0$19175$65785112(a)news.neostrada.pl... > Richard Mueller [MVP] napisal w dniu 2010-04-17 15:59: >> "mrkramer"<hhfm(a)poczta.fm> wrote in message >> news:4bc9b4cc$0$19174$65785112(a)news.neostrada.pl... >>> Hello >>> >>> I'm newbie on vbs programing. I'm trying use subsstring method, but I >>> get >>> error "object required 'helo great world'" and code:800A01A08. >>> >>> ------- >>> dim str >>> str="helo great world" >>> wscript.echo str.substring(5,10) >>> --------------------- >>> >>> >>> It is wierd for me because documentation says: >>> >>> strVariable.substring(start, end) >>> "String Literal".substring(start, end) >>> >>> >>> It is possible that substring method is only in Jscript? >> >> The expression "str.substr(5,10)" implies that substr is a method of a >> object str. The variable str is not an object reference, but a string. >> All >> object references in VBScript are established with "Set" statements, as >> in: >> >> Set objShell = CreateObject("Wscript.Shell") >> >> There is no substring function in VBScript (that I am aware of). Your >> example looks more like .NET to me. I note that when I search for syntax >> examples I frequently find .NET examples. I don't know what documentation >> you found, but the example is definitely not VBScript. I believe the Mid >> function does what you intend. For example: >> >> str = "helo great world" >> Wscript.Echo Mid(str, 5, 10) >> >> This will echo the string "great worl". Or, since the third parameter of >> the >> Mid function is optional, you could try: >> >> Wscript.Echo Mid(str, 5) >> >> which would result in "great world". For VBScript documentation, download >> the help file script56.chm at this link: >> >> http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en >> > I'm using exactly the same help file. There is substring method, but as I > said previously, i'm afraid that is Jscript method only. > Mid function is good and is similar to substring. I'll use mid function. > Thanks for help Yes, now I see in script56.chm that substring is a jscript function. I find the Mid function under VBScript functions (not methods) in the contents. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |