Sign in to follow this  
Followers 0
60aside

An easy question - if you know the answer.....

6 posts in this topic

Why is this not working?

dim $var
$var = "test.ost"

if $var = "*.ost" Then
    msgbox(0,"","working")
EndIf
Exit

Share this post


Link to post
Share on other sites



"*.ost" isn't the same as "test.ost". Simple as that. Wildcards aren't supported in variable names. The strings are compared literally and those strings aren't the same.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

ok.

so if I need to do something if a variable does contain ".ost"

is there a simple way to do this?

or do I have to read the filename somehow, seperate to the right of the "." and then do if var="ost"

sorry, just starting out.....

Thanks.

Share this post


Link to post
Share on other sites

ok - I worked it out....

dim $var
$var = "test.ost"
$var2 = StringSplit($var,'.')

if $var2[2] = "ost" Then
    msgbox(0,"","working")
EndIf
Exit

Share this post


Link to post
Share on other sites

You can use StringSplit, but the most-useful function here is StringInStr()

For example:

$result = StringInStr("test.ost",".ost")

should yield a numeric 5 as the substring is found (starting) in the fifth position. If ".ost" is not present, the function will return numeric zero. You can use the returned value directly in an If statement, as zero will be interpreted as False, any other number as True. If you want to be sure that something precedes the ".ost" then check for a value greater than one.

The other more sophisticated method is to use regular expressions, but beware the trap that a regexes use different logic from filesystems. "*" in a regex has a very different meaning from "*.exe" or whatever in a filename.

Share this post


Link to post
Share on other sites

Thanks in the end I used this :-

dim $var
$var = "test.ost"
$var2 = StringRight($var,4)

if $var2 = ".ost" then
    msgbox(0,"","working")
EndIf
Exit

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0