cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
PunitPanjwani
Level II

How to read read from text file and load the data into Text Edit Box component?

Hello,

 

I am trying to save the content from a window into the Text file. After saving it, I am trying to give user the capability to read the content from the saved text file and populate it in the Text Edit Box so that they don't have to retype again.

 

I was able to save the text file by using Save Text function.

I was also able to browse the text file by using Pick File function.

 

I need help with the extraction of the data and the populating it in the Text Edit Box.

Following is my code:

initial_ECN = ""; // Define initial_ECN outside of the function
initial_PIDTag = "";



// Define a function to create the input window
WinInput = Function({},
    ECN = initial_ECN;
    PIDTag = initial_PIDTag;
    New Window( "Input", <<Modal,
        V List Box(     									
            Border Box( Left( 10 ), Right( 94 ), Bottom( 10 ), Top( 10 ), Sides( 15 ),
                V List Box(
                    Lineup Box( N Col( 3 ),
                        //System ECN
                        Text Box( "System ECN:" ),			
                        S1 = Text Edit Box( ECN , Justify Text( "left" ), <<Set Width(100)),
                        Spacer Box( Size( 1, 1 ) ),
                        
                        //System P&ID Tag
						Text Box( "P&ID Tag:" ),    		
						S2 = Text Edit Box( PIDTag, Justify Text( "left" ), <<Set Width(100) ),
						S2_note = Text Box( " Attach system P&ID indicating boundaries included in these calculations.", Set Wrap( 400 ),Justify Text( "center" )),
						S2_note << Set Font Style( "Italic" ),
						
						Spacer Box( Size( 1, 1 ) ),
						teb5 = Text Edit Box("$Documents\Report\", <<Set Width(100), << Set Hint("e.g. /Tech/")),
						Button Box("Browse",<<Set Function(Function({},
											{Default Local},
											fileName = Pick File("Select Text File", "$DESKTOP", {"Text Files|*.txt", "All Files|*"}, 1, 0, ""); // Pick the text file
											If(fileName != "",  // If a file is selected
												teb5 << Set Text(Read File(fileName))  // Read the file and set its content in the text edit box
											)
										)
									)
								)
                    )
                )
            )
        ),     	
        Button Box( "OK",
            RunTimestamp = Today();
            System_info = {S1, S2} << Get Text;
            initial_ECN = System_info[1]; // Update the global variable
            initial_PIDTag = System_info[2]; // Update the global variable
            OutputWindow(initial_ECN, initial_PIDTag);  // After getting input, open the output window
        )
    )	  	
);

// Function to create the output window
OutputWindow = Function({ECN, PIDTag},
    OutputContent = New Window( "Final Output",
        V List Box(
            Border Box( Left( 10 ), Right( 50 ), bottom( 10 ), top( 10 ), sides( 15 ),
                V List Box(
                    Lineup Box( N Col( 3 ), Spacing( 10 ),
						//System ECN
                        Text Box( "System ECN:", Justify Text( "right" ) ),
                        S1 = Text Box( ECN, <<Set Width(100), Justify Text( "center" ) ),
                        Spacer Box( Size( 10, 10 ) ),
                        S1 << Background color( "yellow" ),
                        
                        //System P&ID Tag
						Text Box( "P&ID Tag:", Justify Text( "right" ) ),
						S2 = Text Box( PIDTag, <<Set Width(100), Justify Text( "center" ) ),
						S2_note = Text Box( " Attach system P&ID indicating boundaries included in these calculations.", Set Wrap( 500 ) ),
						S2_note << Set Font Style ("Italic"),
						S2 << Background color( "yellow" ),
                    )
                )
            ),
            H List Box(3, 
                Button Box( "Print PDF", 
					 OutputContent << Set Page Setup(margins( 1, 1, 1, 1 ), scale( 0.80 ), portrait( 1 ), paper size( "Letter" ));                    
                    // OutputContent << Save PDF( "C:\Users\panjwanip\OneDrive - Barry-Wehmiller\Desktop\surface_area_output.pdf" )
                    OutputContent << Save Text( "C:\Users\panjwanip\OneDrive - Barry-Wehmiller\Desktop\surface_area_output.txt" ) 
                    //OutputContent << Save Excel File( "C:\Users\panjwanip\OneDrive - Barry-Wehmiller\Desktop\surface_area_output.xlsx" )   
                     
                ), 
                Spacer Box( size( 520, 20 ) ),
                Button Box( "Back", 
                    Current Window() << Close Window; 
                    WinInput(); // Pass the current value of ECN back to the input window
                ),
                
            )
        )
    )
);

// Initially open the input window with initial_ECN
WinInput();

 

 

4 REPLIES 4
jthi
Super User

Re: How to read read from text file and load the data into Text Edit Box component?

PunitPanjwani
Level II

Re: How to read read from text file and load the data into Text Edit Box component?

Hi Jarmo,

 

Thanks for the response.

 

I am able to read the file using Load File function. How do I parse data and extract information. The split function doesn't work in JMP.

 

initial_ECN = ""; // Define initial_ECN outside of the function
initial_PIDTag = "";



// Define a function to create the input window
WinInput = Function({},
    ECN = initial_ECN;
    PIDTag = initial_PIDTag;
    New Window( "Input", <<Modal,
        V List Box(     									
            Border Box( Left( 10 ), Right( 94 ), Bottom( 10 ), Top( 10 ), Sides( 15 ),
                V List Box(
                    Lineup Box( N Col( 3 ),
                        //System ECN
                        Text Box( "System ECN:" ),			
                        S1 = Text Edit Box( ECN , Justify Text( "left" ), <<Set Width(100)),
                        Spacer Box( Size( 1, 1 ) ),
                        
                        //System P&ID Tag
						Text Box( "P&ID Tag:" ),    		
						S2 = Text Edit Box( PIDTag, Justify Text( "left" ), <<Set Width(100) ),
						S2_note = Text Box( " Attach system P&ID indicating boundaries included in these calculations.", Set Wrap( 400 ),Justify Text( "center" )),
						S2_note << Set Font Style( "Italic" ),
						
						Spacer Box( Size( 1, 1 ) ),
						teb5 = Text Edit Box("", <<Set Width(100), << Set Hint("e.g. /Tech/")),
						/*Button Box("Browse",<<Set Function(Function({},
											{Default Local},
											fileName = Pick File("Select Text File", "$DESKTOP", {"Text Files|*.txt", "All Files|*"}, 1, 0, ""); // Pick the text file
											If(fileName != "",  // If a file is selected
												teb5 << Set Text(Read File(fileName))  // Read the file and set its content in the text edit box
											)
											
										)
									)
								
								)*/
						Button Box("Browse",<<Set Function(Function({},
											{Default Local},
											fileName = Pick File("Select Text File", "$DESKTOP", {"All Files|*"}, 1, 0, ""); // Pick the text file
											//fileName = Load Text File(Get Path Variable("D:\Punit Documents\Projects\2024\2303196A - Regeneron/surface_area_output.txt"), Charset("utf-8")); // Pick the text file
											If(fileName != "",  // If a file is selected
												fileContent = Load Text File(fileName, Charset("utf-8")); // Load text file content
												ExtractAndSetData(fileContent); // Extract data and set it in S1
											
											)
											
											
										)
									)
								
								)
                    )
                )
            )
        ),     	
        Button Box( "OK",
            RunTimestamp = Today();
            System_info = {S1, S2} << Get Text;
            initial_ECN = System_info[1]; // Update the global variable
            initial_PIDTag = System_info[2]; // Update the global variable
            OutputWindow(initial_ECN, initial_PIDTag);  // After getting input, open the output window
        )
    )	  	
);

// Function to extract data from file content and set it in S1 and S2
ExtractAndSetData = Function({fileContent},
    lines = Split(fileContent, "\n");
    For Each(line, fileContent,
        if(Contains(line, ":"),
            parts = Split(line, ":");
            fieldName = Trim(parts[1]);
            fieldValue = Trim(parts[2]);
            if(fieldName == "System ECN", S1 << Set Text(fieldValue));
            if(fieldName == "P&ID Tag", S2 << Set Text(fieldValue));
        )
    )
);

// Function to create the output window
OutputWindow = Function({ECN, PIDTag},
    OutputContent = New Window( "Final Output",
        V List Box(
            Border Box( Left( 10 ), Right( 50 ), bottom( 10 ), top( 10 ), sides( 15 ),
                V List Box(
                    Lineup Box( N Col( 3 ), Spacing( 10 ),
						//System ECN
                        Text Box( "System ECN:", Justify Text( "right" ) ),
                        S1 = Text Box( ECN, <<Set Width(100), Justify Text( "center" ) ),
                        Spacer Box( Size( 10, 10 ) ),
                        S1 << Background color( "yellow" ),
                        
                        //System P&ID Tag
						Text Box( "P&ID Tag:", Justify Text( "right" ) ),
						S2 = Text Box( PIDTag, <<Set Width(100), Justify Text( "center" ) ),
						S2_note = Text Box( " Attach system P&ID indicating boundaries included in these calculations.", Set Wrap( 500 ) ),
						S2_note << Set Font Style ("Italic"),
						S2 << Background color( "yellow" ),
                    )
                )
            ),
            H List Box(3, 
                Button Box( "Print PDF", 
					 OutputContent << Set Page Setup(margins( 1, 1, 1, 1 ), scale( 0.80 ), portrait( 1 ), paper size( "Letter" ));                    
                    // OutputContent << Save PDF( "C:\Users\panjwanip\OneDrive - Barry-Wehmiller\Desktop\surface_area_output.pdf" )
                    OutputContent << Save Text( "C:\Users\panjwanip\OneDrive - Barry-Wehmiller\Desktop\surface_area_output.txt" ) 
                    //OutputContent << Save Excel File( "C:\Users\panjwanip\OneDrive - Barry-Wehmiller\Desktop\surface_area_output.xlsx" )   
                     
                ), 
                Spacer Box( size( 520, 20 ) ),
                Button Box( "Back", 
                    Current Window() << Close Window; 
                    WinInput(); // Pass the current value of ECN back to the input window
                ),
                
            )
        )
    )
);

// Initially open the input window with initial_ECN
WinInput();
jthi
Super User

Re: How to read read from text file and load the data into Text Edit Box component?

I'm not sure where you are getting your functions from but those aren't JSL functions. Utilize Scripting Index with correct category (Character in this case) and check out what functions JMP does offer (most likely you are looking for Words())

jthi_0-1715619085423.png

https://www.jmp.com/support/help/en/17.2/#page/jmp/list-functions.shtml?os=win&source=application#ww...

-Jarmo
PunitPanjwani
Level II

Re: How to read read from text file and load the data into Text Edit Box component?

Please see the attached photos.. Any help is much appreciated.

Capture.JPGCapture1.JPGCapture2.JPG