Reading tab delimited data from a text file (JS CS3)
Hi --I am working on a script to read data from a text file and use within a dialog. But I have hit a wall.
I have used a script from a previous post that sets a variable from the text document when the script user chooses it from a dropdown.
var myDialog = app.dialogs.add({name:"Map",canCancel:true});
with(myDialog){
with(dialogColumns.add()){
with(borderPanels.add()){
staticTexts.add({staticLabel:"Choose location:"});
with(dialogColumns.add()){
var file = File("~/Desktop/myPlacesfile.txt");
file.open("r");
var str = file.read();
file.close();
var myPlaceList = str.split(/[\r\n]+/);
var myPlaceMenu = dropdowns.add({stringList:myPlaceList, selectedIndex:0});
}
}}}
var myResult = myDialog.show();
if(myResult == true){
if (myPlaceMenu.selectedIndex == 0){
var myPlace = "- Not Defined -";
}else{
var myPlace = myPlaceList[myPlaceMenu.selectedIndex];
alert(myPlace);
}
myDialog.destroy();
}
This is what I need to do now:
The text file is in this format:
value1 [TAB] value2
value1 [TAB] value2
value1 [TAB] value2
I need to have the dialog pulldown only show value 1, and after the user selects it, the script returns only value 2. (The alert is just there for testing -- I am doing something else with the variable).
Is there a way to display the first part of a tab delimited line in the pulldown and return the second half as a variable?
Any help would be greatly appreciated.
thanks
