Jump to content

Recommended Posts

Posted

Here are two more fuctions that may be useful.

1. Converts String to Hex String

2. Converts Hex String to String

The files are attached below.

Thanks,

JS

StrToHex.zip

HexToStr.zip

<{POST_SNAPBACK}>

I have updated the old code to use less line and possibly a bit optimized for speed.

Old Code

Func _StrToHex($strChar)
    Local $aryChar, $i, $iDec, $hChar, $file, $strHex
    
    $aryChar = StringSplit($strChar, "")
    
    For $i = 1 To $aryChar[0]
        $iDec = Asc($aryChar[$i])
        $hChar = Hex($iDec, 2)
        $strHex = $strHex & $hChar
    Next
    
    If $strHex = "" Then
        SetError(1)
        Return -1
    Else
        Return $strHex
    EndIf
EndFunc

Func _HexToStr($strHex)
    Local $strChar, $aryHex, $i, $iDec, $Char, $file, $strHex
    
    $aryHex = StringSplit($strHex, "")
    
    For $i = 1 To $aryHex[0]
        $iOne = $aryHex[$i]
        $i = $i + 1
        $iTwo = $aryHex[$i]
        $iDec = Dec($iOne & $iTwo)
        $Char = Chr($iDec)
        $strChar = $strChar & $Char
    Next

    If $strChar = "" Then
        SetError(1)
        Return -1
    Else
        Return $strChar
    EndIf
EndFunc

New Code

Func _StringToHex($strChar)
    Local $aryChar, $i, $iDec, $hChar, $file, $strHex
    
    $aryChar = StringSplit($strChar, "")
    
    For $i = 1 To $aryChar[0]
        $strHex = $strHex & Hex(Asc($aryChar[$i]), 2)
    Next
    
    If $strHex = "" Then
        SetError(1)
        Return -1
    Else
        Return $strHex
    EndIf
EndFunc

Func _HexToString($strHex)
    Local $strChar, $aryHex, $i, $iDec, $Char, $file, $strHex, $iOne, $iTwo
    
    $s_Length = StringLen($strHex)
    
    For $i = 1 To $s_Length Step 2
        $strChar = $strChar & Chr(Dec(StringMid($strHex, $i, 2)))
    Next

    If $strChar = "" Then
        SetError(1)
        Return -1
    Else
        Return $strChar
    EndIf
EndFunc

I have re uploaded the files so that they would be in proper format, and updated.

StrToHex.zip

HexToStr.zip

Thanks,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

  • 2 weeks later...
Posted

To get UDF's added to the standard library you will have to follow the standards as defined in the first post in this threat...

Its also better to publish your UDF's in the Scripts and Scraps forum first so people can comment/test them so we can see if people like to have them included in the standard library and if they find bugs or have ideas about changes.

:)

<{POST_SNAPBACK}>

You could get arrested for threatning people.

I think I am gona go convert all my UDFs into a format suitable for publishment.

  • 2 weeks later...
Posted (edited)

I have just created a UDF for Math.au3. It converts degrees into radians and can be used in conjunction with the Sin(), Cos(), and Tan() functions because they require radians, not degrees. I searched the helpfile and noticed AutoIt doesn't have a function to convert degrees into radians so I made one. :)

Math.zip

EDIT: Added a _Degree() function.

EDIT2: Updated. Proper format.

Edited by erifash
  • 1 month later...
Posted (edited)

This UDF will print a file using the ShellExecute function of shell32.dll. I have included a global constants list that defines the error codes. Thanks to ezzetabi for making the _ShellExecute function! The code helped me make this.

Here's the function documentation:

;===============================================================================
;
; Function Name:   _FilePrint()
;
; Description:     Prints a plain text file.
;
; Syntax:          _FilePrint ( $s_File [, $i_Show] )
;
; Parameter(s):    $s_File     = The file to print.
;                  $i_Show     = The state of the window. (default = @SW_HIDE)
;
; Requirement(s):  External:   = shell32.dll (it's already in system32).
;                  Internal:   = None.
;
; Return Value(s): On Success: = Returns 1.
;                  On Failure: = Returns 0 and sets @error according to the global constants list.
;
; Author(s):       erifash <erifash [at] gmail [dot] com>
;
; Note(s):         Uses the ShellExecute function of shell32.dll.
;
; Example(s):
;   _FilePrint("C:\file.txt")
;
;===============================================================================

The zip is attached. You can find the topic here.

File.zip

Edited by erifash
Posted

Hi!

If somebody has time to look at it:

I created some functions to animate text in controls. It's still in development, but ideas are welcome and there's still a little display problem.

Link: http://www.autoitscript.com/forum/index.php?showtopic=14409

peethebee

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Posted

what can it print other then .txt ?

<{POST_SNAPBACK}>

It can print any plain text file type that has an editor associated with it that has a print option. I have only tested it with txt files but I am certain it will work with other types. To print a plain text file that has no editor associated with it, you would simply need to do this:

FileMove("textfile.extention", "textfile.txt")
_FilePrint("textfile.txt")
FileDelete("textfile.txt")
  • 2 months later...
Posted

With w0uter's help, I have created a UDF that returns a process name out of a given PID. I believe this could be quite useful. Here is the documentation:

;===============================================================================
;
; Description -   Returns a string containing the process name that belongs to a given PID.
;
; Syntax -      _ProcessGetName( $iPID )
;
; Parameters -  $iPID - The PID of a currently running process
;
; Requirements -  None.
;
; Return Values - Success - The name of the process
;                Failure - Blank string and sets @error
;                      1 - Process doesn't exist
;                      2 - Error getting process list
;                      3 - No processes found
;
; Author(s) -    Erifash <erifash [at] gmail [dot] com>, Wouter van Kesteren.
;
; Notes -        Supplementary to ProcessExists().
;
;===============================================================================

The topic can be found here. The zip is attached. Thanks for your time! B)

process.zip

Posted

A small correction to _GUICtrlListViewDeleteItemsSelected() UDF in AutoIt v3.1.1.87

Func _GUICtrlListViewDeleteItemsSelected($h_listview, $s_WindowTitle = "", $s_WindowText = "")
    Local $i, $ItemCount
    If (StringLen($s_WindowTitle) == 0) Then
        $s_WindowTitle = WinGetTitle("")
    EndIf
    
    $ItemCount = _GUICtrlListViewGetItemCount($h_listview)
    If (_GUICtrlListViewGetSelectedCount($h_listview) == $ItemCount) Then
        _GUICtrlListViewDeleteAllItems($h_listview)
    Else
        Local $items = _GUICtrlListViewGetSelectedIndices($h_listview, 1, $s_WindowTitle, $s_WindowText)
        ;************* added by CatchFish ***********
        If Not IsArray($items) Then Return   ;******* without this, an error will occur when no item is selected
        ;********************************************
        ControlListView($s_WindowTitle, $s_WindowText, $h_listview, "SelectClear")
        For $i = $items[0] To 1 Step - 1
;~          ConsoleWrite($items[$i] & @LF)   ;commented by CatchFish
            _GUICtrlListViewDeleteItem($h_listview, $items[$i])
        Next
    EndIf
EndFunc  ;==>_GUICtrlListViewDeleteItemsSelected
Guest Darksoul71
Posted

May be my filename proccessing UDF´s are also something you are interested,

-D$

Straight from the readme:

Purpose:

Filename.au3 is a small set of UDF´s (=User defined functions) which

I developed for my own little scripts. Freel free to use the source

code as you like. I just would like to encourage everyone to release

his sources under GPL whenever you distribute a script as binary.

My UDF´s are depending on the file.au3 script from the latest beta

as I´m using some of the included functions.

Functions included and what the do:

*Func _FileExtractPath ($FileName)

This function extracts the file path with trailing "\" for a

filename with path.

Example: _FileExtractPath("C:\MyPath\MyFile.TXT") returns "C:\MyPath\"

* Func _FileExtractFilename ($FileName)

This function extracts the file name for a filename with path.

Example: _FileExtractFilename("C:\MyPath\MyFile.TXT") returns "MyFile.TXT"

* Func _FileGetExt ($FileName)

This function returns the extension for a filename with path with "."

Example: _FileGetExt ("C:\MyPath\MyFile.TXT") returns ".TXT"

* Func _FileChangeExt ($FileName, $Extension)

This function changes the extension for a filename with path.

Example: _FileChangeExt ("C:\MyPath\MyFile.TXT", "doc") returns "C:\MyPath\MyFile.doc"

* Func _FileStripExt ($FileName)

This function strips the extension for a filename with path.

Example: _FileStripExt ("C:\MyPath\MyFile.TXT") returns "C:\MyPath\MyFile"

* Func _FileIncrementFileName ($FileName)

This function generates a unique filename for a filename with path if the file exists.

Example: _FileIncrementFileName ("C:\MyPath\MyFile.TXT") returns

"C:\MyPath\MyFile.TXT" when "C:\MyPath\MyFile.TXT" does not exist

"C:\MyPath\MyFile (1).TXT" when "C:\MyPath\MyFile.TXT" does exist

"C:\MyPath\MyFile (2).TXT" when "C:\MyPath\MyFile (1).TXT" does exist

"C:\MyPath\MyFile (3).TXT" when "C:\MyPath\MyFile (2).TXT" does exist

and so on.

I´ve provided a little sample script called "MoveFileUnique.au3" as example for what you

can use this function.

* Func _GenerateIncrementedFileNames ($FullPath, $Count, byRef $myArray)

This function is intended to be a "counterpart" for _FileIncrementFileName and generates

a directory which keeps up to $Count filenames with the same naming scheme as _FileIncrementFileName

produces. This enables you to search for incremental filnames based on the "base name" without dealing

with FileFindFirstFile. In one of my scripts I use _FileIncrementFileName to store multiple setting files

under unique names. Afterwards I generate an array with _GenerateIncrementedFileNames with 10000 filenames

and do a simple "FileExists" loop for each of those filenames stored in the array.

Note: If $myArray isn´t initialized, the function will do a DIM by itself.

Example: _GenerateIncrementedFileNames ("C:\MyPath\MyFile.TXT", 4, $myArr) would return the following array

$myArr[0] = "C:\MyPath\MyFile.TXT"

$myArr[1] = "C:\MyPath\MyFile (1).TXT"

$myArr[2] = "C:\MyPath\MyFile (2).TXT"

$myArr[3] = "C:\MyPath\MyFile (3).TXT"

* Func _DrivePercentFree ($FullPath)

This function return the available diskspace on a drive in %

Example: _DrivePercentFree ("C:\") would return 50 if your HD has a size of 8 GB and 4 GB are still free.

* Func _IsSearchedType ($FullPath, $Types)

This function return "1" it the filename in $FullPath matches one of the extension defined by $Types

and returns "0" if it doesn´t match any of the defined extensions. $Types can be a single extension without

any separator (e.g. $Types = "txt") or multiple extensions using one of the following separators "|,;:",

e.g. $Types = "avi,mpg,mpeg" is similar to $Types = "avi|mpg|mpeg" or $Types = "avi:mpg:mpeg"

The dot for the extension is optional and will be added if missing, e.g. both $Types = ".avi,.mpg" and

$Types = "avi,mpg" are valid. Extensions are NOT casesensitive and will be converted to uppercase prior

comparison.

Example: _IsSearchedType ("C:\This is a file.txt", "txt,doc,rtf") would return 1 as one of the specified

extensions is txt.

* Func _FileSearchForText ($SearchFile, $SearchString, $CaseSensitive)

This function searches for a searchstring within a textfile. The search can be casesensitive or

not.

Example:

_FileSearchForText ("C:\myTextfile.txt", "myString", 1) returns 1 if "myString" is found within

"C:\myTextfile.txt" or returns 0 if it´s not found. Setting $CaseSensitive to 0 will deactivate

casesensitive search. In other words "myString" equals "MYSTRING", "mySTRING", MyStRiNG", etc.

* Func _FileSearchAndReplaceText ($SearchFile, $SearchString, $ReplaceString, $CaseSensitive)

This function does nearly the same as _FileSearchForText but instead of only searching for a

searchstring within a textfile, it will replace any instance of the found string by $ReplaceString.

The search and replace process can be casesensitive or not.

Examples:

_FileSearchAndReplaceText ("C:\myTextfile.txt", "myString", "Replace", 1) will replace any instance

of "myString" within "C:\myTextfile.txt" by the String "Replace". Setting $CaseSensitive to 0 will

deactivate casesensitive search and replace. In other words "myString" equals "MYSTRING", "mySTRING",

MyStRiNG", etc. and will be replaced by the String "Replace".

* Func _FileAppendTextfile ($ToAppend, $FromAppend)

This function appends the content of the textfile specified under $FromAppend to the textfile specified

under $ToAppend.

Example:

_FileAppendTextfile ("C:\myFile.txt", "C:\myAppendFile.txt") would append all the content from

"C:\myAppendFile.txt" at the end of "C:\myFile.txt".

dsfile.zip

  • 1 month later...
Posted

Could we squeeze in a small addition to the standard date.au3 UDF functions? I've called it _MonthStringToNumber

This is the opposite function of _DateMonthOfYear($iMonthNum, $iShort). It takes a month name as a string parameter and returns it as the numeric value of the month.

Very useful when date is extracted from text to convert it into usable format for manipulation by other functions within date.au3, especially when screen scraping from other applications and the Internet.

Note: Logically it follows just after the _DateMonthOfYear function in date.au3

;===============================================================================
;
; Description:    Returns the month in two digit number from alpha month name
; Parameter(s):  $MonthString - Input month code in format where first three characters are valid months
;                  irrespective of case or rest of spelling
; Requirement(s):   None
; Return Value(s):  On Success - Returns two digit numeric month code
;                  On Failure - 0  and Sets @ERROR to:  1 - Invalid $MonthString
; Author(s):        Confuzzled
; Note(s):        Assumes English spelling of Months
;
;===============================================================================

Func _MonthStringToNumber($MonthString);Returns month in two digit number from alpha month name
;==============================================
; Local Constant/Variable Declaration Section
;==============================================
 Local $MonthNum
 
;Convert supplied month string by stripping the left three characters and changing them to uppercase
 $MonthString=StringUpper(StringLeft($MonthString,3)) 
 
 Select
  Case $MonthString = "JAN" 
   $MonthNum = "01"
  Case $MonthString = "FEB" 
   $MonthNum = "02"
  Case $MonthString = "MAR" 
   $MonthNum = "03"
  Case $MonthString = "APR" 
   $MonthNum = "04"
  Case $MonthString = "MAY" 
   $MonthNum = "05"
  Case $MonthString = "JUN" 
   $MonthNum = "06"
  Case $MonthString = "JUL" 
   $MonthNum = "07"
  Case $MonthString = "AUG" 
   $MonthNum = "08"
  Case $MonthString = "SEP" 
   $MonthNum = "09"
  Case $MonthString = "OCT" 
   $MonthNum = "10"
  Case $MonthString = "NOV" 
   $MonthNum = "11"
  Case $MonthString = "DEC" 
   $MonthNum = "12"
 ; Allow for non-valid entries if got to here
  Case Else
   $MonthNum = "00" 
   SetError(1)
   Return (0)
 EndSelect
 
;Send back the month in numeric format
 Return $MonthNum
 
EndFunc ;==>_MonthStringToNumber

Example of usage would be to call it as _MonthStringToNumber("JaNUary") and get "01" returned. Note the input case and spelling are not an issue if the first three letters are valid month prefixes.

I can't say it's bulletproof, but it does include some workarounds for common corrupt input data. Any suggestions, changes, additions welcome. :P

Posted (edited)

why not like this :P

Func _MonthStringToNumber($MonthString)
    Switch StringLeft($MonthString, 3)
        Case "JAN"
            Return "01"
        Case "FEB"
            Return "02"
        Case "MAR"
            Return "03"
        Case "APR"
            Return "04"
        Case "MAY"
            Return "05"
        Case "JUN"
            Return "06"
        Case "JUL"
            Return "07"
        Case "AUG"
            Return "08"
        Case "SEP"
            Return "09"
        Case "OCT"
            Return "10"
        Case "NOV"
            Return "11"
        Case "DEC"
            Return "12"
    EndSwitch
    SetError(1)
    Return "00"
EndFunc  ;==>_MonthStringToNumber
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Posted

I agree with changing it from the "Select" to the "Switch" statement, but you forgot to make the string uppercase. So you need to replace:

Switch StringLeft($MonthString, 3)

with:

Switch StringUpper( StringLeft($MonthString, 3) )

Regards

Dragonrider

why not like this :P

Func _MonthStringToNumber($MonthString)
    Switch StringLeft($MonthString, 3)
        Case "JAN"
            Return "01"
        Case "FEB"
            Return "02"
        Case "MAR"
            Return "03"
        Case "APR"
            Return "04"
        Case "MAY"
            Return "05"
        Case "JUN"
            Return "06"
        Case "JUL"
            Return "07"
        Case "AUG"
            Return "08"
        Case "SEP"
            Return "09"
        Case "OCT"
            Return "10"
        Case "NOV"
            Return "11"
        Case "DEC"
            Return "12"
    EndSwitch
    SetError(1)
    Return "00"
EndFunc ;==>_MonthStringToNumber
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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