Jump to content
Sign in to follow this  
jerem488

How to change a list of numbers with a text file

Recommended Posts

jerem488

Hello,

I would like change a suite of numbers but he must read this numbers in a text file

my text file is like this :

3, 12, 34, 89, 109, 35

489, 184, 890, 7, 18

I have about 1000 lines.

And my varaible is

$numbers[5] =

How to do this ?

thanks in advance


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites
Valuater

How do you want to change them?

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
jerem488

I want recover the numbers in my text file.

per line there is firsts numbers for the varaible.

for example, I have this numbers in my text file :

line 1 : 3, 12, 34, 89, 109, 35

line 2 : 489, 184, 890, 7, 18

so I do a loop with the "while" command

and my first variable would $numbers[5] = [3, 12, 34, 89, 109, 35]

is it explicit ?


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites
Valuater

I want recover the numbers in my text file.

per line there is firsts numbers for the varaible.

for example, I have this numbers in my text file :

line 1 : 3, 12, 34, 89, 109, 35

line 2 : 489, 184, 890, 7, 18

so I do a loop with the "while" command

and my first variable would $numbers[5] = [3, 12, 34, 89, 109, 35]

is it explicit ?

Actually... No

That part I can manage.. it's "what are you going to do ( want to do ) after that?"

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
jerem488

After i use this numbers to do an operation.

How can you mange this ?


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites
Valuater

Look at FileRead,StringSplit, For/Next loop

Yep....

Ya know, had you given more info Zedna or myself would have been able to help you with code

8)_


NEWHeader1.png

Share this post


Link to post
Share on other sites
jerem488

So first I can't use fileread but also filereadline bacause my numbers suite are lines.

Stringsplit ? Why ? between what ?

and for/next... I think the while function is better than for/next for reading a file who can change.


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites
SoulA

Why not just give a further explanation of what it is you are trying to do these numbers in the file? What are you trying to change about them?

Share this post


Link to post
Share on other sites
jerem488

Thank you

I am doing like this :

$File = FileOpen(@homedrive & "\Numbers_MAJ.txt", 0)

If $File = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $LignePair = FileReadLine($File)
    If @error = -1 Then ExitLoop
    $Separation = StringSplit($LignePair,",",0)
    Dim $numbers[8] = [$Separation[1],$Separation[2],$Separation[3],$Separation[4],$Separation[5],$Separation[6],$Separation[7],$Separation[8]]
Wend

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites
SoulA

With what you have the $numbers array is getting overwritten every time it goes through the loop. Why not put them in a 2d array. The first dimension being the line number and the second being the numbers on that line?

#include <file.au3>

$sPath = @homedrive & "\Numbers_MAJ.txt"
$iLineNum = _FileCountLines($sPath)
Dim $numbers = [$iLineNum][8]

$File = FileOpen($sPath, 0)

If $File = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

For $i = 0 to $iLineNum - 1
    $LignePair = FileReadLine($File)
    If @error = -1 Then ExitLoop
    $Separation = StringSplit($LignePair,",",0)
    $numbers[$i][8] = [$Separation[1],$Separation[2],$Separation[3],$Separation[4],$Separation[5],$Separation[6],$Separation[7],$Separation[8]]
Next

For $i = 0 to UBound($numbers, 1) - 1
    $sString = ""
    For $i1 = 0 to UBound($numbers, 2) - 1
        $sString &= $numbers[$i][$i1] & @CRLF
    Next
    MsgBox(0, "Line " & $i + 1, $sString)
Next
Edited by SoulA

Share this post


Link to post
Share on other sites
jerem488

Thank you but there are two errors

#include <file.au3>

$sPath = @homedrive & "\Numbers_MAJ.txt"
$iLineNum = _FileCountLines($sPath)
Dim $numbers = [$iLineNum][8]

$File = FileOpen($sPath, 0)

If $File = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

For $i = 0 to $iLineNum - 1
    $LignePair = FileReadLine($File)
    If @error = -1 Then ExitLoop
    $Separation = StringSplit($LignePair,",",0)
    $numbers[$i][8] = [$Separation[1],$Separation[2],$Separation[3],$Separation[4],$Separation[5],$Separation[6],$Separation[7],$Separation[8]]
Next

For $i = 0 to UBound($numbers, 1) - 1
    $sString = ""
    For $i1 = 0 to UBound($numbers, 2) - 1
        $sString &= $numbers[$i][$i1] & @CRLF
    Next
    MsgBox(0, "Line " & $i + 1, $sString)
Next

Syntax error.

---------------------------------------------------------------------------------------------

H:\Bureau\ser_3.au3(5,16) : ERROR: syntax error

Dim $numbers = [

~~~~~~~~~~~^

H:\Bureau\ser_3.au3(18,23) : ERROR: syntax error

$numbers[$i][8] = [

~~~~~~~~~~~~~~^

---------------------------------------------------------------------------------------------

Edited by jerem488

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites
SoulA

hrm can try this I guess. I probably should try and make my own test file to do this with but I am lazy so I'm not sure how well all this is working.

#include <file.au3>

$sPath = "test.txt"
$iLineNum = _FileCountLines($sPath)
Dim $numbers[$iLineNum][8]

$File = FileOpen($sPath, 0)

If $File = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

For $i = 0 to $iLineNum - 1
    $LignePair = FileReadLine($File)
    If @error = -1 Then ExitLoop
    $Separation = StringSplit($LignePair,",",0)
    For $i1 = 0 to $Separation[0] - 1
        $numbers[$i][$i1] = $Separation[$i1 + 1]
    Next
Next

For $i = 0 to UBound($numbers, 1) - 1
    $sString = ""
    For $i1 = 0 to UBound($numbers, 2) - 1
        $sString &= $numbers[$i][$i1] & @CRLF
    Next
    MsgBox(0, "Line " & $i + 1, $sString)
Next
Edited by SoulA

Share this post


Link to post
Share on other sites
jerem488

Hi Soula !

I just try and it works ! !

and in addition it is very useful for others programs

Very good, very thanks.

Edited by jerem488

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
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
Sign in to follow this  

×