Jump to content

Recommended Posts

Posted

Hi guys, 
I have using search feature for searching my problem but i got nothing.
I have a set a number in my txt file that contains :
1
2
3
4
5
7
8
10

how do I get an unvailable number for next variable?
I mean i need number 6 to run other script.

Posted

I am not really sure what you are trying to do ... but if you just want to make sure all the numbers in your text file are sequential and you want to fill in any missing numbers, then you could try something like this:

; insert missing value from text file
#include <Array.au3>

$numArray=FileReadToArray(@DesktopDir&"\numbers.txt") ; swap out your file location
_ArrayDisplay($numArray)

for $a =UBound($numArray)-1 to 0 step -1
    local $firstVal=$numArray[$a]
    if $a>=1 then
        if $firstVal-$numArray[$a-1] > 1 then
            for $b=1 to $firstVal-$numArray[$a-1]-1
                _ArrayInsert($numArray,$a,$firstVal-$b)
            Next
        EndIf
    EndIf
next
_ArrayDisplay($numArray)

Otherwise, I think we would need more info.  Test file attached.

numbers.txt

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Posted

The most simple (and fast) way is to use Scripting.Dictionary to compare this array of numbers against a reference array which contains all numbers. The numbers in both arrays can be in any order

#include <Array.au3>

Local $a[8] = [1, 2, 3, 4, 5, 7, 8, 10]
Local $b[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  ; reference

Local $sda = ObjCreate("Scripting.Dictionary")
Local $sdb = ObjCreate("Scripting.Dictionary")

For $i In $b
    $sdb.Item($i)
Next
For $i In $a   
    If $sdb.Exists($i) Then $sdb.Remove($i)
Next
$diff = $sdb.Keys()

_ArrayDisplay($diff)

 

Posted
1 hour ago, Jfish said:

I am not really sure what you are trying to do ... but if you just want to make sure all the numbers in your text file are sequential and you want to fill in any missing numbers, then you could try something like this:

; insert missing value from text file
#include <Array.au3>

$numArray=FileReadToArray(@DesktopDir&"\numbers.txt") ; swap out your file location
_ArrayDisplay($numArray)

for $a =UBound($numArray)-1 to 0 step -1
    local $firstVal=$numArray[$a]
    if $a>=1 then
        if $firstVal-$numArray[$a-1] > 1 then
            for $b=1 to $firstVal-$numArray[$a-1]-1
                _ArrayInsert($numArray,$a,$firstVal-$b)
            Next
        EndIf
    EndIf
next
_ArrayDisplay($numArray)

Otherwise, I think we would need more info.  Test file attached.

numbers.txt

Thank you for your replies Jfish :D
sorry if i have not give information clearly.
i want the number between 5 and 7 becomes my next process. 
for example I have a data :
1/3/2:5
1/3/2:7
I want 1/3/2:6 be my new data to input in the next process.  

42 minutes ago, mikell said:

The most simple (and fast) way is to use Scripting.Dictionary to compare this array of numbers against a reference array which contains all numbers. The numbers in both arrays can be in any order

#include <Array.au3>

Local $a[8] = [1, 2, 3, 4, 5, 7, 8, 10]
Local $b[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  ; reference

Local $sda = ObjCreate("Scripting.Dictionary")
Local $sdb = ObjCreate("Scripting.Dictionary")

For $i In $b
    $sdb.Item($i)
Next
For $i In $a   
    If $sdb.Exists($i) Then $sdb.Remove($i)
Next
$diff = $sdb.Keys()

_ArrayDisplay($diff)

 

I just knew Scripting.Dictionary. thank you mikell :D
by the way, it does show the unavailable number but how do I extract the value from the array display?

Posted
2 hours ago, mikell said:

$diff is an array. If the unavailable number you want is the first one found, it is in $diff[0] (array element at index 0)

It works beautifully. Alhamdulillah.

Thank you very much Mikell. :D
May Allah reward you with goodness. 

Posted

if they are always going to be sequential, you could check your target values against the index.

Local $a[9] = ['1/3/2:0', '1/3/2:1', '1/3/2:2', '1/3/2:3', '1/3/2:4', '1/3/2:5', '1/3/2:7', '1/3/2:8', '1/3/2:10']

For $i = 0 to ubound($a)
    if $i <> stringsplit($a[$i] , ":")[2] Then exit(msgbox(0, '' , stringsplit($a[$i] , ":")[1] & ":" & $i))
Next

 

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

Here is another method with a little more complexity and options.

Local $sText = _
        1 & @CRLF & _
        2 & @CRLF & _
        3 & @CRLF & _
        5 & @CRLF & _
        6 & @CRLF & _
        10

; ------- Example 1 -----------
; The consecutive digits, "\d+", sit between the start of line, "^", and the end of line, "$", on each line. Returns: Example 1: 4
Local $iNewNum = _GetConsecutiveNumber($sText, "(?m)(?<=^)\d+(?=$)") ; Or, the RE pattern, "\d+", could be used.
ConsoleWrite("Example 1: " & $iNewNum & @CRLF)

Local $sTextA = _
        "1/3/2:4" & @CRLF & _
        "1/3/2:7" & @CRLF & _
        "1/3/2:5" & @CRLF & _
        "1/4/2:4" & @CRLF & _
        "1/5/2:4" & @CRLF & _
        "1/4/2:6"

; ------------ Example 2 --------------
; The consecutive digits, "\d+", sit between, ":", and the end, "$", on each line. Returns: Example 2: 1/3/2:6
Local $iNewNumA = _GetConsecutiveNumber($sTextA, "(?m)(?<=:)\d+(?=$)")
ConsoleWrite("Example 2: " & $iNewNumA & @CRLF)

; ------------ Example 3 --------------
; The consecutive digits, "\d+", sit between, ":", and the end, "$", on each line. Returns: Example 3: 1/3/2:8
Local $iNewNumA = _GetConsecutiveNumber($sTextA, "(?m)(?<=:)\d+(?=$)", "1/3/2:7") ; Note the given starting line.
ConsoleWrite("Example 3: " & $iNewNumA & @CRLF)


; ------------ Example 4 --------------
; The consecutive digits, "\d+", sit between, "/", and, "/", on each line. Returns: Example 4: 1/6/2:4
;  (First line with specific number + 3). Already in list is "1/3/2:4", "1/4/2:4", and "1/5/2:4"
Local $iNewNumA = _GetConsecutiveNumber($sTextA, "(?m)(?<=/)\d+(?=/)")
ConsoleWrite("Example 4: " & $iNewNumA & @CRLF)


; Increases the appropiate number that the RE pattern identifies, based on the first line of the $string, or the given first line parameter.
; Note from StringRegExp()function in AutoIt help file (slightly modified):-
;  - PCRE metacharacters are \ . ^ $ | [ ( { * + ? # which have one or more special meaning, depending on context.
;    To insert a literal metacharacter, precede it by adding a backslash (this is called escaping (or quoting) a character):
;    "\$" means the literal dollar character.   "$" means end of string.   >> "$", preceded by "(?m)" means end of line. <<-- This one used in examples
;  - "\d+(?=;)"  - matches digits followed by a semicolon, but does not include the semicolon in the match. (positive lookahead assertion)
;  - "(?<=;)\d+" - matches digits that are preceded by a semicolon, but does not include the semicolon in the match. (positive lookbehind assertion)
; Note: If the $sFirstLine parameter is not a complete line in $string, the actual first line in $string will be used'
;
Func _GetConsecutiveNumber($string, $sREPattern, $sFirstLine = "")
    ; First line is used as a template and the number's starting point.
    If $sFirstLine = "" Or StringRegExp($string, "(?m)^" & $sFirstLine & "$") = 0 Then $sFirstLine = StringRegExpReplace($string, "(?s)\R.+", "")
    Local $iStart = StringRegExp($sFirstLine, $sREPattern, 1)[0] ; The number to start increasing.
    Local $sTemplate = '"' & StringRegExpReplace($sFirstLine, $sREPattern, '" & $iStart & "') & '"'

    ; Continue increasing $iStart until StringRegExp() = 0. Then, the $iStart variable has the required next consecutive number.
    While StringRegExp($string, Execute($sTemplate))
        $iStart += 1
    WEnd
    Return StringRegExpReplace($sFirstLine, $sREPattern, $iStart)
EndFunc   ;==>_GetConsecutiveNumber

 

Posted

Another skin for this cat:

; toy example: unprefixed numbers separated by ;
Local $s = "1;3;4;6"
Local $t = $s
Local $start = Int($t)
Local $n
Do
    $t = StringRegExpReplace($t, $start & ";" & _Inc($start), $start)
Until @extended < 1
Local $missing = Int($t) + 1
ConsoleWrite("In string '" & $s & "' the first missing number is " & $missing & @LF & @LF)

; real example. Pretend the string $s is loaded thru FileRead()
Local $s = "1/3/2:2" & @CRLF & "1/3/2:3" & @CRLF & "1/3/2:4" & @CRLF & "1/3/2:5" & @CRLF & "1/3/2:7" & @CRLF & "1/3/2:8"
; simplify subject by removing unneeded parts
Local $t = StringRegExpReplace($s, "(?m)(\d+\/\d+\/\d+:)(\d+)", "$2")
Local $start = Int($t)
Local $n
Do
    $t = StringRegExpReplace($t, $start & @CRLF & _Inc($start), $start)
Until @extended < 1
Local $missing = Int($t) + 1
ConsoleWrite("In string '" & $s & "' the first missing number is " & $missing & @LF)

Func _Inc(ByRef $str)
    $str += 1
    Return $str
EndFunc

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

While we must explain to the OP that the first element in an array is at index 0, it's not really sure that they could handle and appreciate these snippets for their true worth  :)

Posted

I must have taxidermists in my genealogy.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

building on a nice foundation of what appear to be scalped feline corpses.

;~ Local $a[8] = [0, 1, 2, 3, 4, 5, 7, 8]
;~ Local $a[8] = [1, 2, 3, 4, 5, 7, 8, 9]
Local $a[8] = [146, 147, 148, 150, 151, 152, 153, 154]

For $i = $a[0] to $a[ubound($a) - 1]
   If $a[$i - $a[0]] <> $i Then Exit Msgbox(0,"", $i)
Next

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

but it sounds like this if you do it with strings

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
  • Recently Browsing   0 members

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