Dashboard_avatar
Feb 13, 2012
Post id: 309631 Report Item

So the problem I face is that I have an array that I want to use as text in a scrollField. What I need it to do is write each element of the array onto a different line of the scrollField.


similar to:

for ($eachFile in $Files){
    print ($eachFile + "\n");
    }




...but I need that to work here:


string $scrollField = `scrollField -e -text ("$eachFile printed onto a new line") scrollField`;

Any thoughts???
Thanx for any help! 


 

Dashboard_avatar
Feb 13, 2012
Post id: 309632 Report Item

ok- I've got it working. I was trying to be too fancy about it, but it's actually very simple.

my thanks to the authors at http://www.scriptswell.net


proc getTxt (){


     string $getTxtPath[] = `fileDialog2 -fileMode 4 -dialogStyle 1`; //Dialog to find file


     $txtFile = `fopen $getTxtPath[0] "r"` ;


     string $content = `fread $txtFile $content` ;


 


    scrollField -e -text $content scriptTxt;


}

Dashboard_avatar
Feb 13, 2012
Post id: 309633 Report Item

OK, so my problem exists again. I've run into the Byte size limitation of "fread"  ...I think my solution now is to read my text file line by line and write that to a variable. That's no trouble, but how do I then edit the text of my scrollField having each member of the array being its own line?  Is there a way to append to the existing text in the scroll Field rather than completely replacing it? 

Dashboard_avatar
Feb 14, 2012
Post id: 309634 Report Item

by adding the data to a single variable over and over (or using the stringArrayToString command)

Method 1:
string $list[]={"one","two","three"} ;
string $data ;
for($item in $list)
    $data+=$item+"\n" ;
print $data ;



Method 2:
string $list[]={"one","two","three"} ;
string $data=stringArrayToString($list,"\n") ;
print $data ;

Dashboard_avatar
Feb 16, 2012
Post id: 309644 Report Item

Thanks for the reply, but those don't really for my situation. Below is the proc that I ended up using with success. Basically it reads one line of the file at a time and then prints it into the scrollfield based on an insertion point and line number. This kept the text below the 1024 byte limitation.




proc getTxt(){


 


    string $getTxtPath[] = `fileDialog2 -fileMode 4 -dialogStyle 1`; //Dialog to find file


    textField -e -text $getTxtPath txtField; // Edits the text field with file path


 


    $fileId = `fopen $getTxtPath[0] "r"` ;


    string $nextLine = `fgetline $fileId`;


 


    for($i=0; $i < size($nextLine); $i++){


        while ( size( $nextLine ) > 0 ) {


            print ( $nextLine );


            scrollField -e -ip $i -it $nextLine scriptTxt;    


            $nextLine = `fgetline $fileId`;


        }


    }


 


    fclose $fileId;


 


}