Jump to content
BatMan22

Organizing array data into files

Recommended Posts

BatMan22

Hey Guys.. So I am trying to split up my data that I have loaded into two arrays by my test code (in this case I'm just showing 300.0 and 300.1).. I want it so that if for $ColumnC=300.1 then write to a file called "IC3.txt" the SampleID and 300.1. I will have a lot more functions and test codes eventually but I don't understand why this test case is failing.. Instead of writing "Sample 3 300.1""Sample5 300.1" it just writes "300.1" once.. 

Global $ColumnC[10]
 Global $ColumnB[10]

 $ColumnC[1]="300.0"
 $ColumnC[2]="300.0"
 $ColumnC[3]="300.1"
 $ColumnC[4]="300.0"
 $ColumnC[5]="300.1"
 $ColumnB[1]="Sample1"
 $ColumnB[2]="Sample2"
 $ColumnB[3]="Sample3"
 $ColumnB[4]="Sample4"
 $ColumnB[5]="Sample5"


For $i= 0 to UBound($ColumnC) -1
;~  ConsoleWrite($ColumnC[$i] & @LF)
    If $ColumnC[$i]="300.1" Then
        _FileWriteFromArray(@ScriptDir & "\IC3.txt", $ColumnB, $i, $i)
        _FileWriteFromArray(@ScriptDir & "\IC3.txt", $ColumnC, $i, $i)

    EndIf
Next

ConsoleWrite(UBound($ColumnC))

 

Edited by BatMan22
code didn't insert

Share this post


Link to post
Share on other sites
Bowmore

For what you are wanting to do _FileWriteFromArray is the wrong function to use. It is designed to write the whole or specified section of the array to a file at once. As such it creates a new file each time overwriting any existing file. 

For your purposes you need to use FileWrite or FileWriteLine as shown in the example below.

 

#include <FileConstants.au3>


 Global $ColumnC[10]
 Global $ColumnB[10]

 $ColumnC[1]="300.0"
 $ColumnC[2]="300.0"
 $ColumnC[3]="300.1"
 $ColumnC[4]="300.0"
 $ColumnC[5]="300.1"
 $ColumnB[1]="Sample1"
 $ColumnB[2]="Sample2"
 $ColumnB[3]="Sample3"
 $ColumnB[4]="Sample4"
 $ColumnB[5]="Sample5"


Local $hFile = FileOpen(@ScriptDir & "\IC3.txtm", $FO_OVERWRITE)

For $i= 0 to UBound($ColumnC) -1
;~  ConsoleWrite($ColumnC[$i] & @LF)
    If $ColumnC[$i]="300.1" Then
        FileWriteLine(@ScriptDir & "\IC3.txt", $ColumnB[$i] & " " & $ColumnC[$i])
    EndIf
Next

    FileClose($hFile)

ConsoleWrite(UBound($ColumnC))

 

  • Like 1

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites
Danyfirex

Hello. You could do this:

 

Global $ColumnC[5]
Global $ColumnB[5]

$ColumnC[0] = "300.0"
$ColumnC[1] = "300.0"
$ColumnC[2] = "300.1"
$ColumnC[3] = "300.0"
$ColumnC[4] = "300.1"
$ColumnB[0] = "Sample1"
$ColumnB[1] = "Sample2"
$ColumnB[2] = "Sample3"
$ColumnB[3] = "Sample4"
$ColumnB[4] = "Sample5"

;make sure $ColumnC and $ColumnB have same bound
For $i = 0 To UBound($ColumnC) - 1
    If $ColumnC[$i] = "300.1" Then
        FileWrite(@ScriptDir & "\IC3.txt", $ColumnB[$i] & " " & $ColumnC[$i] & @CRLF)
    EndIf
Next

Saludos

Edited by Danyfirex
  • Like 1

Share this post


Link to post
Share on other sites
BatMan22

You guys rock.. Now I can expand from here :)

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.