Jump to content

Logic help


Recommended Posts

Hey guys I need some help with creating some better logic.

Here's the scoop: I have a script that grabs filenames from a database and then seperates the filename and fileversion number then calls another function that downloads the executable file from a webservice based on the filename and version # and then automates the setup process of that .exe file(the script is a little mopre complicated than that but I am trying to keep this simple so I don't loose you guys).

However I just discovered a bug in my script.

I have the following condition in the script

Where $FileDetect is the name of the .exe file in the directory ....eg. ice_amp_r5.3.4.exe

$FileDetect = _PathSplit($FindExe, $szDrive, $szDir, $szFName, $szExt)
$pkgNameArray = Stringsplit( $szFName,"_")
$TTProduct_Name = $pkgNameArray[1]

If $TTProduct_Name = "ice" or "XTsim" or "PP" or "X" Then 
    $pkgIDArray = _StringBetween( $FindExe, "_r", ".exe")
    $TTProduct_PackageID = $pkgIDArray[0]
    $prodversion =  StringLeft($TTProduct_PackageID, 3)
Else 
    $pkgIDArray = _StringBetween( $FindExe, "_", ".exe")
    $TTProduct_PackageID = $pkgIDArray[0]
    $fullversion = StringTrimLeft($TTProduct_PackageID, 1)
    $prodversion =  StringLeft($fullversion, 3)
EndIF

The problem I encounter is that my condition does not work for products such as DD_repel_r3.4.2 and others similar

since the logical places epel_r3.4.2 in the $TTProduct_PackageID variable when I want r3.4.2

It also places epe in $prodversion when I want 3.4

I have searched but can't seem to find any existing functions -In Autoit -that might help me....Any logic advice would be appreciated. What would be the best way to have this work for all cases.

Possible cases include:

ice_amp_r5.3.4.exe

DD_repel_r3.4.2

PP_Trade_r5.1.2

Xxam_r3.7.5

etc...

Link to comment
Share on other sites

Use StringRegexp, so it works. The Version consists only out of Points and Numbers :) And it ends with a digit.

$file = "ice_amp_r5.3.4.exe"
$Number = StringRegExp($file,"_r([0-9.]*\d)",1)
If IsArray($Number) Then $Number = $Number[0]
MsgBox(0, '', $Number)
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Use StringRegexp, so it works. The Version consists only out of Points and Numbers :) And it ends with a digit.

$file = "ice_amp_r5.3.4.exe"
$Number = StringRegExp($file,"_r([0-9.]*\d)",1)
If IsArray($Number) Then $Number = $Number[0]
MsgBox(0, '', $Number)
I think StringRegExp() is the right idea, but some may not be familiar enough with it. Another way to fix your script using ordinary string manipulation is to find the location of "_r" searching from the RIGHT end. Use an occurrence parameter of -1 with StrigInStr():
$file = "ice_amp_r5.3.4.exe"
$iVer = StringInStr($file, "_r", 0, -1)
$sVer = StringMid($file, $iVer + 1)
If StringRight($sVer, 4) = ".exe" Then $sVer = StringTrimRight($sVer, 4)
MsgBox(0, '', $sVer)

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Works.... thanks a bunch.... I hadn't a look of the StringRegExp function before.... thanks for the heads up

Thanks Prog and Psalty

Edited by Clay
Link to comment
Share on other sites

Psalty you are right StringRegExp() is a little confusing.... for me atleast. I am trying to understand this thing because now I want the other half of the string "ice_amp" and I can't seem to figure out a proper pattern

I hate asking for the explicit answer when coding, but could one of you guys help me with the pattern to achieve this or explain the _r([0-9.]*\d) pattern and maybe I can take it from there.

Is this thing saying match any 0-9 digit after _r and then escape after that?

Link to comment
Share on other sites

Psalty you are right StringRegExp() is a little confusing.... for me atleast. I am trying to understand this thing because now I want the other half of the string "ice_amp" and I can't seem to figure out a proper pattern

I hate asking for the explicit answer when coding, but could one of you guys help me with the pattern to achieve this or explain the _r([0-9.]*\d) pattern and maybe I can take it from there.

Is this thing saying match any 0-9 digit after _r and then escape after that?

I can't get the damn "_r5" out

$file = "tt_cdemei_r5.3.4.exe"
$Number = StringRegExp($file,"([^0-9.]*\d)",1)
If IsArray($Number) Then $Number = $Number[0]
MsgBox(0, '', $Number)
Link to comment
Share on other sites

I can't get the damn "_r5" out

$file = "tt_cdemei_r5.3.4.exe"
$Number = StringRegExp($file,"([^0-9.]*\d)",1)
If IsArray($Number) Then $Number = $Number[0]
MsgBox(0, '', $Number)
If you have time to figure out the RegExp patterns, it is well worth it. But in the interim:
Global $avFiles[3] = [2, "tt_cdemei_r5.3.4.exe", "ice_amp_r5.3.4.exe"]

For $n = 1 To UBound($avFiles) - 1
    $iVer = StringInStr($avFiles[$n], "_r", 0, -1)
    
    $sVer = StringMid($avFiles[$n], $iVer + 1)
    If StringRight($sVer, 4) = ".exe" Then $sVer = StringTrimRight($sVer, 4)
    
    $sName = StringMid($avFiles[$n], 1, $iVer - 1)
    
    MsgBox(64, 'Results', "$sName = " & $sName & "  $sVer = " & $sVer)
Next

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...