Jump to content

How to change a list of numbers with a text file


 Share

Recommended Posts

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 weeks later...

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
 Share

  • Recently Browsing   0 members

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