Im just trying to do a simple ImageSearch script usig AutoIt. But I cant get it to work propely even tho Im sure the image Im searching for is on the screen.
Here is my code:
#include <ImageSearch.au3>
global $x , $y
HotKeySet ("{F1}",StartScriptc)
HotKeySet ("{F2}",StopScript)
While 1
Sleep(200)
WEnd
Func StartScriptc()
;WinActivate("MyWindow")
FindPicture()
EndFunc
Func StopScript()
Exit
EndFunc
Func FindPicture()
While 1
ConsoleWrite ("Before search" & #CRLF)
$search = _ImageSearch("test2.bmp",0,$x,$y,50)
if $search = 1 Then
ConsoleWrite ("Found it!" & #CRLF)
Else
ConsoleWrite ("Fail!" & #CRLF)
EndIf
WEnd
EndFunc
When I run this code I get the "Before Search" output but it never passes to the lines after the _ImageSearch() function. Instead the scipt just ends (I guess its a crash)
Here is the output I get:
Before search
14:10:51 AutoIt3.exe ended.rc:-1073741819
14:10:51 AutoIt3Wrapper Finished.
Exit code: 3221225477 Time: 9.844
I am not the author of ImageSearch.au3, its from http://www.autoitscript.com/forum/topic/65748-image-search-library/.
I have tried both the 32 and 64 bit versions without success. I put the DLL and ImageSearch script into the same folder as my .bmp file and test script.
This Image Search library works for me.
#include-once
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language: English
; Description: Functions that assist with Image Search
; Require that the ImageSearchDLL.dll be loadable
;
; ------------------------------------------------------------------------------
;===============================================================================
;
; Description: Find the position of an image on the desktop
; Syntax: _ImageSearchArea, _ImageSearch
; Parameter(s):
; $findImage - the image to locate on the desktop
; $tolerance - 0 for no tolerance (0-255). Needed when colors of
; image differ from desktop. e.g GIF
; $resultPosition - Set where the returned x,y location of the image is.
; 1 for centre of image, 0 for top left of image
; $x $y - Return the x and y location of the image
;
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
; a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
return _ImageSearchArea($findImage,$resultPosition,0,0,#DesktopWidth,#DesktopHeight,$x,$y,$tolerance)
EndFunc
Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
$result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
; If error exit
if $result[0]="0" then return 0
; Otherwise get the x,y location of the match and the size of the image to
; compute the centre of search
$array = StringSplit($result[0],"|")
$x=Int(Number($array[2]))
$y=Int(Number($array[3]))
if $resultPosition=1 then
$x=$x + Int(Number($array[4])/2)
$y=$y + Int(Number($array[5])/2)
endif
return 1
EndFunc
;===============================================================================
;
; Description: Wait for a specified number of seconds for an image to appear
;
; Syntax: _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):
; $waitSecs - seconds to try and find the image
; $findImage - the image to locate on the desktop
; $tolerance - 0 for no tolerance (0-255). Needed when colors of
; image differ from desktop. e.g GIF
; $resultPosition - Set where the returned x,y location of the image is.
; 1 for centre of image, 0 for top left of image
; $x $y - Return the x and y location of the image
;
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$waitSecs = $waitSecs * 1000
$startTime=TimerInit()
While TimerDiff($startTime) < $waitSecs
sleep(100)
$result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance)
if $result > 0 Then
return 1
EndIf
WEnd
return 0
EndFunc
;===============================================================================
;
; Description: Wait for a specified number of seconds for any of a set of
; images to appear
;
; Syntax: _WaitForImagesSearch
; Parameter(s):
; $waitSecs - seconds to try and find the image
; $findImage - the ARRAY of images to locate on the desktop
; - ARRAY[0] is set to the number of images to loop through
; ARRAY[1] is the first image
; $tolerance - 0 for no tolerance (0-255). Needed when colors of
; image differ from desktop. e.g GIF
; $resultPosition - Set where the returned x,y location of the image is.
; 1 for centre of image, 0 for top left of image
; $x $y - Return the x and y location of the image
;
; Return Value(s): On Success - Returns the index of the successful find
; On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$waitSecs = $waitSecs * 1000
$startTime=TimerInit()
While TimerDiff($startTime) < $waitSecs
for $i = 1 to $findImage[0]
sleep(100)
$result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
if $result > 0 Then
return $i
EndIf
Next
WEnd
return 0
EndFunc
Related
I need to optimise this AHK script, currently the script runs in around 2 seconds. I would ultimately like it to run >1 second, the best case would be 0.6 seconds. The basic functionality is the script is clicking on red boxes, of which there can be between 2 - 8. I'd love some help on ways to increase the speed of this script if possible.
Thanks, code below.
1::
; Activate the target window
WinActivate, Paint
; Define the search area
SearchLeft := 1047
SearchTop := 572
SearchRight := 1222
SearchBottom := 650
SetDefaultMouseSpeed, 0
; Start the timer
StartTime := A_TickCount
; Loop through all pixels in the search area and click on them
Loop {
; Search for the next pixel
PixelSearch, Px, Py, SearchLeft, SearchTop, SearchRight, SearchBottom, 0x0000FF, RGBFast, Fastest
if (ErrorLevel = 0) {
; Click on the pixel
Click, %Px%, %Py%, 1
}
else {
; If no pixel is found, exit the loop
break
}
}
; Calculate the elapsed time
ElapsedTime := A_TickCount - StartTime
; Output the elapsed time as a message box
MsgBox, % "Script completed in " . ElapsedTime . " milliseconds."
3::ExitApp
The GS1 standard defines GTIN codes that contain a 4 or 5 digit variable weight or price. This variable weight or price part needs to be validated with a check digit.
How can I calculate this check digit in code? Please be aware that this check digit is not calculated the same way as the default check digit at the end of the GTIN.
For reference: https://www.gs1.org/docs/barcodes/GS1_General_Specifications.pdf Page 466/467
You did not specify the language of choice, so hopefully this will be useful to you. Essentially it can be boiled down to array lookups and simple math. This code is written is AutoITScript, but it should be simple to translate to others.
I am sure this code could be made smarter (with 2d array lookup, functions etc) but for simplicity I made it more readable.
It should be noted that AutoIT is not a typed language, so 1234 can be treated as a number and a string all the same. Also that AutoIT uses $var[index1][index2] to access a 0-based array value.
Hope this helps you on ! If so, please accept solution.
RESULTS
============= barcode checksum variable length ================
https://www.gs1.org/docs/barcodes/GS1_General_Specifications.pdf section 7.9.2
----------------------
Doing checksum on 4 digits: 2875
digit 1 is: 2 --> Check = 4
digit 2 is: 8 --> Check = 5
digit 3 is: 7 --> Check = 1
digit 4 is: 5 --> Check = 3
==> Sum is 39
==> CHECK DIGIT IS RIGHT-MOST DIGIT = 9
----------------------
Doing checksum on 5 digits: 14685
digit 1 is: 1 --> Check = 5
digit 2 is: 4 --> Check = 8
digit 3 is: 6 --> Check = 7
digit 4 is: 8 --> Check = 4
digit 5 is: 5 --> Check = 9
==> Sum is 33
==> CHECK DIGIT IS 40-sum = 7
The code
#include <String.au3>
; barcode checksum
; https://www.gs1.org/docs/barcodes/GS1_General_Specifications.pdf section 7.9.2
;
ConsoleWrite("============= barcode checksum variable length ================" & #CRLF)
ConsoleWrite("https://www.gs1.org/docs/barcodes/GS1_General_Specifications.pdf section 7.9.2" & #CRLF)
; index 0 index 1 index 2 index 3
; --- wf2- ---------- --- wf3 ----------- --- wf5+ ---------- ---- wf5- ----------
Static $f[4][10] = [ [0,2,4,6,8,9,1,3,5,7], [0,3,6,9,2,5,8,1,4,7], [0,5,1,6,2,7,3,8,4,9], [0,5,9,4,8,3,7,2,6,1] ]
; 4 digit version 5 digit version
static $lookupTables[2][5] =[ [ 0, 0, 1, 3] , [ 2, 0, 3, 2, 0] ]
; ==================================
; show some examples
_calcit(2875)
_calcit(14685)
; -------------------- function to calculate digits
;
Func _calcit($thenumber)
; assume the length is correct here
; theNumber is now array [0] is left-most
local $arrayNumber = _StringExplode($thenumber, "", 0)
local $t ; our lookup digit
local $tSum ; summarized
local $theversion = 0 ; 0 = 4 digit, 1 = 5 digits
if StringLen($thenumber) = 4 then
$theversion = 0
else
$theversion = 1
endif
ConsoleWrite("----------------------" & #CRLF)
ConsoleWrite("Doing checksum on " & StringLen($thenumber) & " digits: " & $thenumber & #CRLF)
for $i = 0 to StringLen($thenumber)-1
ConsoleWrite("digit " & $i+1 & " is: " & $arrayNumber[$i])
;lookup the number in our 2d array. Which row determined by the lookup table.
$t = $f [$lookupTables[$theversion][$i]] [$arrayNumber[$i] ]
ConsoleWrite(" --> Check = " & $t & #CRLF)
$tSum = $tSum + $t
Next
if $theversion = 0 then
$tSum = $tSum * 3
ConsoleWrite(" ==> Sum is " & $tSum & #CRLF)
ConsoleWrite(" ==> CHECK DIGIT IS RIGHT-MOST DIGIT = " & StringRight($tSum, 1) & #CRLF)
else
ConsoleWrite(" ==> Sum is " & $tSum & #CRLF)
$tSum = 40-$tSum
ConsoleWrite(" ==> CHECK DIGIT IS 40-sum = " & StringRight($tSum, 1) & #CRLF)
EndIf
EndFunc
PHP has usort and Java has the Comparator interface.
These allow you to create a simple function that compare two Objects, Strings, etc. without getting involved in the details of the sort implementation.
Generally, the comparison function looks something like this:
// Return value:
// Negative value: a before b
// Positive value: b before a
// Zero: strings are equal
function compare(String a, String b) {
return toLowerCase(a) - toLowerCase(b);
}
... and you can be as simple or as fancy as you like with your comparisons.
Is there anything in AutoIt that does this?
The documentation is great, and the Help File is great, but I cannot find anything that allows me to define a custom comparison function. (I will reimplement Quicksort if necessary, but with a framework as full-featured as AutoIt, I feel like I must just be overlooking something.)
"Is there anything in AutoIt that does this?"
Example as per _ArrayMultiColSort() :
#include <Array.au3>
#include "ArrayMultiColSort.au3"
Global Const $g_sHeaderRow = 'category|value'
Global Const $g_aSortOrder = [ _
[0, 'critical,important,regular'], _
[1, 1] _
]
Global $g_aArray = [ _
['critical', 7], _
['important', 2], _
['important', 6], _
['regular', 2], _
['critical', 5], _
['regular', 9] _
]
_ArrayMultiColSort($g_aArray, $g_aSortOrder)
_ArrayDisplay($g_aArray, #ScriptName, '', 0, Default, $g_sHeaderRow)
Returns:
critical 7
critical 5
important 6
important 2
regular 9
regular 2
While there does not seem to be anything build into AutoIt, continued research revealed several very useful libraries the community has created.
Below is one called _ArrayCustomSort.au3 by Erik Pilsits. Script has been copied at the end of this post for reference. Original can be found here:
https://www.autoitscript.com/forum/topic/83626-natural-order-string-comparison/
Usage:
#include <File.au3>
#include "_ArrayCustomSort.au3"
; Directory to list files
Local $dir = "C:\Windows"
Local $arr = _FileListToArray($dir, "*")
_ArrayDelete($arr, 0)
; Here is the name of the user-defined sorting function!
_ArrayCustomSort($arr, "_MyBasicStringCompare", 0)
_ArrayDisplay($arr)
; Now you can put all your crazy sorting logic in here!
Func _MyBasicStringCompare($s1, $s2)
Return StringCompare($s1, $s2)
EndFunc
Include Library:
#include-once
#include <Array.au3>
; #FUNCTION# ====================================================================================================================
; Name ..........: _ArrayCustomSort
; Description ...: Sort a 1D or 2D array on a specific index using the quicksort/insertionsort algorithms, based on a custom sorting function.
; Syntax ........: _ArrayCustomSort(Byref $avArray, $sSortFunc[, $iDescending = 0[, $iStart = 0[, $iEnd = 0[, $iSubItem = 0]]]])
; Parameters ....: $avArray - [in/out] Array to sort
; $sSortFunc - Name of custom sorting function. See Remarks for usage.
; $iDescending - [optional] If set to 1, sort descendingly
; $iStart - [optional] Index of array to start sorting at
; $iEnd - [optional] Index of array to stop sorting at
; $iSubItem - [optional] Sub-index to sort on in 2D arrays
; Return values .: Success - 1
; Failure - 0, sets #error:
; |1 - $avArray is not an array
; |2 - $iStart is greater than $iEnd
; |3 - $iSubItem is greater than subitem count
; |4 - $avArray has too many dimensions
; |5 - Invalid sort function
; Author ........: Erik Pilsits
; Modified ......: Erik Pilsits - removed IsNumber testing, LazyCoder - added $iSubItem option, Tylo - implemented stable QuickSort algo, Jos van der Zande - changed logic to correctly Sort arrays with mixed Values and Strings, Ultima - major optimization, code cleanup, removed $i_Dim parameter
; Remarks .......: Sorting function is called with two array elements as arguments. The function should return
; 0 if they are equal,
; -1 if element one comes before element two,
; 1 if element one comes after element two.
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _ArrayCustomSort(ByRef $avArray, $sSortFunc, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0)
If Not IsArray($avArray) Then Return SetError(1, 0, 0)
If Not IsString($sSortFunc) Then Return SetError(5, 0, 0)
Local $iUBound = UBound($avArray) - 1
; Bounds checking
If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound
If $iStart < 0 Then $iStart = 0
If $iStart > $iEnd Then Return SetError(2, 0, 0)
; Sort
Switch UBound($avArray, 0)
Case 1
__ArrayCustomQuickSort1D($avArray, $sSortFunc, $iStart, $iEnd)
If $iDescending Then _ArrayReverse($avArray, $iStart, $iEnd)
Case 2
Local $iSubMax = UBound($avArray, 2) - 1
If $iSubItem > $iSubMax Then Return SetError(3, 0, 0)
If $iDescending Then
$iDescending = -1
Else
$iDescending = 1
EndIf
__ArrayCustomQuickSort2D($avArray, $sSortFunc, $iDescending, $iStart, $iEnd, $iSubItem, $iSubMax)
Case Else
Return SetError(4, 0, 0)
EndSwitch
Return 1
EndFunc ;==>_ArrayCustomSort
; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: __ArrayCustomQuickSort1D
; Description ...: Helper function for sorting 1D arrays
; Syntax.........: __ArrayCustomQuickSort1D(ByRef $avArray, ByRef $sSortFunc, ByRef $iStart, ByRef $iEnd)
; Parameters ....: $avArray - Array to sort
; $sSortFunc - Name of sorting function.
; $iStart - Index of array to start sorting at
; $iEnd - Index of array to stop sorting at
; Return values .: None
; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima
; Modified.......: Erik Pilsits - removed IsNumber testing
; Remarks .......: For Internal Use Only
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func __ArrayCustomQuickSort1D(ByRef $avArray, ByRef $sSortFunc, ByRef $iStart, ByRef $iEnd)
If $iEnd <= $iStart Then Return
Local $vTmp
; InsertionSort (faster for smaller segments)
If ($iEnd - $iStart) < 15 Then
Local $i, $j
For $i = $iStart + 1 To $iEnd
$vTmp = $avArray[$i]
For $j = $i - 1 To $iStart Step -1
If (Call($sSortFunc, $vTmp, $avArray[$j]) >= 0) Then ExitLoop
$avArray[$j + 1] = $avArray[$j]
Next
$avArray[$j + 1] = $vTmp
Next
Return
EndIf
; QuickSort
Local $L = $iStart, $R = $iEnd, $vPivot = $avArray[Int(($iStart + $iEnd) / 2)]
Do
While (Call($sSortFunc, $avArray[$L], $vPivot) < 0)
$L += 1
WEnd
While (Call($sSortFunc, $avArray[$R], $vPivot) > 0)
$R -= 1
WEnd
; Swap
If $L <= $R Then
$vTmp = $avArray[$L]
$avArray[$L] = $avArray[$R]
$avArray[$R] = $vTmp
$L += 1
$R -= 1
EndIf
Until $L > $R
__ArrayCustomQuickSort1D($avArray, $sSortFunc, $iStart, $R)
__ArrayCustomQuickSort1D($avArray, $sSortFunc, $L, $iEnd)
EndFunc ;==>__ArrayCustomQuickSort1D
; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: __ArrayCustomQuickSort2D
; Description ...: Helper function for sorting 2D arrays
; Syntax.........: __ArrayCustomQuickSort2D(ByRef $avArray, ByRef $sSortFunc, ByRef $iStep, ByRef $iStart, ByRef $iEnd, ByRef $iSubItem, ByRef $iSubMax)
; Parameters ....: $avArray - Array to sort
; $iStep - Step size (should be 1 to sort ascending, -1 to sort descending!)
; $iStart - Index of array to start sorting at
; $iEnd - Index of array to stop sorting at
; $iSubItem - Sub-index to sort on in 2D arrays
; $iSubMax - Maximum sub-index that array has
; Return values .: None
; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima
; Modified.......: Erik Pilsits - removed IsNumber testing
; Remarks .......: For Internal Use Only
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func __ArrayCustomQuickSort2D(ByRef $avArray, ByRef $sSortFunc, ByRef $iStep, ByRef $iStart, ByRef $iEnd, ByRef $iSubItem, ByRef $iSubMax)
If $iEnd <= $iStart Then Return
; QuickSort
Local $i, $vTmp, $L = $iStart, $R = $iEnd, $vPivot = $avArray[Int(($iStart + $iEnd) / 2)][$iSubItem]
Do
While ($iStep * Call($sSortFunc, $avArray[$L][$iSubItem], $vPivot) < 0)
$L += 1
WEnd
While ($iStep * Call($sSortFunc, $avArray[$R][$iSubItem], $vPivot) > 0)
$R -= 1
WEnd
; Swap
If $L <= $R Then
For $i = 0 To $iSubMax
$vTmp = $avArray[$L][$i]
$avArray[$L][$i] = $avArray[$R][$i]
$avArray[$R][$i] = $vTmp
Next
$L += 1
$R -= 1
EndIf
Until $L > $R
__ArrayCustomQuickSort2D($avArray, $sSortFunc, $iStep, $iStart, $R, $iSubItem, $iSubMax)
__ArrayCustomQuickSort2D($avArray, $sSortFunc, $iStep, $L, $iEnd, $iSubItem, $iSubMax)
EndFunc ;==>__ArrayCustomQuickSort2D
I have written the following code without any Matlab built-in functions to rotate an image. I tried to write another loop to invert the rotation. the image does rotate back but I still get the size of the previously rotated image. How can I get rid of the black parts in the image?
INPUT_IMAGE = 'forest.png';
img_in=double(imread(INPUT_IMAGE))./255;
h=size(img_in,1);
w=size(img_in,2);
R=[cos(th) -sin(th) 0 ; sin(th) cos(th) 0 ; 0 0 1];
T=[1 0 (-w/2) ; 0 1 (-h/2) ; 0 0 1];
F=inv(T)*R*T;
img_out=zeros(h,w,3);
%Rotate image
for i=1:w
for j=1:h
a = [i ; j ; 1];
b = inv(F) * a;
x = b(1)/b(3);
y = b(2)/b(3);
x = floor(x);
y = floor(y);
if (x>0 & x<=W & j>0 & j<=H)
img_out(y,x,:)=img_in(j,i,:);
end
end
end
img_out2=zeros(h,w,3);
%invert rotation
for i=1:w
for j=1:h
a = [i ; j ; 1];
b = F * a;
x = b(1)/b(3);
y = b(2)/b(3);
x = floor(x);
y = floor(y);
if (x>0 & x<=W & j>0 & j<=H)
img_out2(y,x,:)=img_out(j,i,:);
end
end
end
The result:
I know the image has black gaps due to the forward mapping but I'm not concerned about that as I'm trying to implement a code without built-in functions that would only rotate the image back so I can calculate the error.
Instead of iterating the source image, inverse transformation matrix, and iterate destination image.
Iterating destination image guarantees to have no holes (each pixel gets a value).
The code you have posted is not working, please fix it...
I based my answer on your previous post: Matlab image rotation
I used 'peppers.png' instead of 'forest.png' (I can't find 'forest.png', next time, please add the image to your post).
The example code do the following:
Rotate input image (You may treat it as "reverse transformation").
Rotate result image back (using inverse transformation matrix).
Display absolute difference of original image and result image.
close all;
clear all;
img_in = 'peppers.png';
img_in =double(imread(img_in))./255;
orig_in = img_in;
h=size(img_in,1);
w=size(img_in,2);
th = pi/4;
R=[cos(th) -sin(th) 0 ; sin(th) cos(th) 0 ; 0 0 1];
T=[1 0 (-w/2) ; 0 1 (-h/2) ; 0 0 1];
F=inv(T)*R*T;
img_out=zeros(h,w,3);
%Rotate image
for i=1:w
for j=1:h
x = [i ; j ; 1];
y = F * x;
a = y(1)/y(3);
b = y(2)/y(3);
a = round(a);
b = round(b);
if (a>0 && a<=w && b>0 && b<=h)
img_out(j,i,:)=img_in(b,a,:);
end
end
end
figure;imshow(img_out);
%Rotate back
%---------------------------------------------------------
img_in = img_out;
img_out = zeros(h,w,3);
%Inverse transformation matrix.
F = inv(F);
%Rotate image (back)
for i=1:w
for j=1:h
x = [i ; j ; 1];
y = F * x;
a = y(1)/y(3);
b = y(2)/y(3);
a = round(a);
b = round(b);
if (a>0 && a<=w && b>0 && b<=h)
img_out(j,i,:)=img_in(b,a,:);
end
end
end
figure;imshow(img_out);
img_diff = abs(orig_in - img_out);
figure;imshow(img_diff);
img_diff image:
Is it possible to have a variable where only a part of it is changing?
I have a scale that gives me a value 6 times a second. Every time the weight on the scale changes, it gives me a value like $r00000 or 4$00400. But if the value stays constant for 1 sec it returns $b01234.
My problem is that I can't find a way to use the "$b" in an if statement, so that after $b I have a value that changes.
Dim MyString, MyArray, i
Dim test
MyString = Scale_Value
If MyString="*$b**????***" Then
MyArray = Split(MyString, "$b", -1, 1)
For i = 0 To UBound(MyArray)
test = (MyArray(i))
tmpPWgt = (CStr(Mid(test, 1,1) & "." & Mid(test, 2)))
Next
Else
tmpPWgt="0.000"
End If
As you seem to be interested in the $b values only, use Left() and Mid() to get the parts for each input:
>> a = Split("$r00000 $b01234 4$00400 $b54321 $r55555")
>> for each m in a
>> WScript.Echo "----", m
>> if "$b" = Left(m, 2) Then
>> m = CLng(Mid(m, 3))
>> WScript.Echo "1 sec w:", m
>> end if
>> next
>>
---- $r00000
---- $b01234
1 sec w: 1234
---- 4$00400
---- $b54321
1 sec w: 54321
---- $r55555
>>
...
If Left(MyString, 2) = "$b" Then
...