Jump to content

Recommended Posts

Posted

I hope you can excuse me as this is my first post and I think might be useful to someone.

I was putting a loop in but found that my loop contindition was getting a bit unreadable

e.g.

Do

$nRnd = Random(1,10,1)

ConsoleWrite ("Random Number " & $nRnd & @CR)

Until $nRnd = 4 Or $nRnd = 7 or $nRnd = 9

Since I also write in Progress there are a couple of commands called LOOKUP and CAN-DO which can do something much simpler and here is what I came up with.

ConsoleWrite("The word bag is in position " & _StringLookUp("One,bag,Three","Bag") & @cr)
ConsoleWrite("Does the list contain the number 4 = " & _StringLookUp("1,2,3,5,6,10,12",4,",",1) & @cr) ; Does the list 1,2,3,5,6,10,12 Contain 4

for $iLoop = 1 to 10
    ; Removing the last parameter will also work due to the way true (non zero) and false (zero) works
    Switch _StringLookUp ("5|9|10",$iLoop,"|",1)
        Case True
            ConsoleWrite("Found number " & $iLoop & @cr)
        Case False
            ConsoleWrite("Number " & $iLoop & " is not in list " & @CR)
    EndSwitch
Next

; Loop around until a random number matches
Do
  $nRnd = Random(1,10,1)
  ConsoleWrite ("Random Number " & $nRnd & @CR)
Until _StringLookUp("4,7,9",$nRnd, Default, 1)

;==================================================================================================
; Function Name:         _StringLookUp($sStr, $sKey, $sSeparator, $iFlag)
;
; Parameters:            $sStr:   The delimited list of characters
;                        $sKey:   The search string
;                        $sSeparator:   The seperator string you wish to use as the delimiter (default = comma)
;                        $iFlag:  Optional parameter to indicate whether the index position is returns (default)
;                                 or True or False if the search string can not be found.
;
; Description:           Searches a delimited list for a given string and returns it position in the list.
;
; Return Value(s)
;                        On Success:        Returns the position of the word or True if $iFlag is 1
;                        On Failure:        Returns zero if the word can not be found or False if $iFlag is 1
; Author(s):             pickbone
;==================================================================================================
Func _StringLookUp($sStr, $sKey, $sSeparator = -1, $iFlag = 0)
    local $sArray, $iLoop, $iIndex
    If $sSeparator = -1 Or $sSeparator = Default Then $sSeparator = ','
    
    $sArray = StringSplit($sStr,$sSeparator)
    $iIndex = 0
    for $iLoop = 1 To $sArray[0] 
        If $sKey = $sArray[$iLoop] Then 
            $iIndex = $iLoop
            ExitLoop
        EndIf
    Next
    
    If $iFlag = 1 Then
        If $iIndex = 0 Then
            Return False    
        Else
            Return True
        EndIf
    Else
        Return $iIndex
    EndIf
EndFunc
  • 2 weeks later...
Posted (edited)

I noticed that there's no _GDIPlus_GraphicDrawImageRect() in GDIPlus Management UDF.

Seemed odd as there's a _GDIPlus_GraphicDrawImageRectRect() function.

_GDIPlus_GraphicDrawImageRect() is the same as _GDIPlus_GraphicDrawImage() but with the 2 extra params for Width & Height

It's handy if you want to draw an image on your gui or controls or another image and are trying to set the size/position of the graphic image without clipping the image.

; #FUNCTION# =======================================================================================
; Name...........: _GDIPlus_GraphicsDrawImageRect
; Description ...: Draw an Image object at coordinate, width & height
; Syntax.........: _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, $iX, $iY, $iW, $iH)
; Parameters ....: $hGraphics   - Handle to a Graphics object
;                  $hImage      - Handle to an Image object
;                  $iX          - The X coordinate of the upper left corner of the rendered image
;                  $iY          - The Y coordinate of the upper left corner of the rendered image
;                  $iW          - The Width to draw the image.
;                  $iH          - The Height to draw the image.
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Paul Campbell (PaulIA)
; Modified.......: smashly
; Remarks .......: Same function as _GDIPlus_GraphicsDrawImage() with width and height option
; Related .......:
; Link ..........; @@MsdnLink@@ GdipDrawImageRectI
; Example .......; No
; ==================================================================================================
Func _GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage, $iX, $iY, $iW, $iH)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectI", "hwnd", $hGraphics, "hwnd", $hImage, "int", $iX, "int", $iY, "int", $iW, "int", $iH)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_GraphicsDrawImageRect

Cheers

Edit: added description, added @error bailout..

Edited by smashly
  • 11 years later...
Posted

The link in the first post is broken.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

  • Developers
Posted
23 minutes ago, MrCreatoR said:

The link in the first post is broken.

Yea right....  did you actually read the first post?
This is a set of UDF's I worked on in 2004 now incorporated in the standard installer of AutoIt3. ;)

Jos

*click*

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

  • Jos locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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