Issue with Notebook selection= command

Hello,

I have here a strange behavior when using the following syntax in a function:
Notebook n_Para selection={(V_startParagraph+2, 0), endOfChars}


Only if I supply the line two times in a row, the text in the notebook gets selected as I would expected it. Then again I'm totally new to Igor.

With best regards, Lars

ps.: Igor Version is 6.3.0.1
I don't know why this would not work unless V_startParagraph+2 is invalid.

Keep in mind that paragraph numbers are zero-based.

For debugging purposes change it to:
Variable paragraph = V_startParagraph + 2
Print paragraph
Notebook n_Para selection={(paragraph, 0), endOfChars}


If you are unable to figure it out, try to create a reproducible test case and post the code here with an attached sample notebook file.

FWIW, Here is a function that tells you the number of paragraphs in a notebook:
Function NumberOfParagraphs(nb)
    String nb               // Name of notebook
   
    // Get current selection for later restore
    GetSelection Notebook, $nb, 1
    Variable startParagraph = V_startParagraph
    Variable startPos = V_startPos
    Variable endParagraph = V_endParagraph
    Variable endPos = V_endPos
   
    // Move selection to end of notebook
    Notebook $nb, selection = {endOfFile, endOfFile}

    // Determine selected paragraph number (zero-based)
    GetSelection Notebook, $nb, 1

    // Compute number of paragraphs in the notebook
    Variable numParagraphs = V_endParagraph + 1
   
    // Restore original selection
    Notebook $nb, selection = {(startParagraph,startPos),(endParagraph,endPos)}
   
    return numParagraphs
End


hrodstein wrote:
I don't know why this would not work unless V_startParagraph+2 is invalid. ...


Out of curiosity, what happens when V_startParagraph + N > NumberOfParagraphs(nb)? Is an error thrown at run time, does the selection "stick" at the end of the notebook, or does something else happen?

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
Thanks I will look into that as soon as possible.

I use the search command on the below type of text. The relevant code would be:
Notebook $nb_name selection={startOfFile,startOfFile}, findText={"~~ Concentration", 2}
GetSelection Notebook, $nb_name, 1
    Notebook $nb_name selection={(V_startParagraph+1, 0), endOfChars}
    Notebook $nb_name selection={(V_startParagraph+1, 0), endOfChars}
    GetSelection Notebook, $nb_name, 2
...
End


If I pass the above mentioned selection line only one time, the cursor is placed at the beginning of the correct line but does not select the expected part of the line. That only happens after reissuing the command.

With best regards, Lars


~~ Operator: Date: 2012-02-16 File Name: ShoT_001 Start Time: 10:27:21 Stop Time: 10:27:28 Notes: Ar: 10.050 mBar C2HF5: ->11.011 mBar Ar: ->950.0 mBar ~~ Bath Gas Molecule: Argon (Ar) Pre Pressure: 40.00 mbar 4.000000E+003 Pa Concentration: 1.614426E-006 mol/cm³ ~~ Probe Molecule: Cemical Molecule Molar Fraction: 1011.6 ppm Concentration: 1.633119E-009 mol/cm³ ~~ Tube Foil: 0.2 mm Temperature: 298.00 K ~~ Absorbtion Wave Length: 248.00 nm Slit Width: 0.9 mm ~~ Wave Travel Time Sensor 1 -> 2: 258.070573 µs 1.549964E+003 m/s Sensor 2 -> 3: 259.530577 µs 1.541244E+003 m/s Sensor 3 -> 4: 263.460585 µs 1.518254E+003 m/s Sensor 4 -> Window: 33.096740 µs 1.510723E+003 m/s Damping: 2.411165 % ~~ Temperature (Ideal) (Empirical) Before Reflection: 2319.133467 K 2307.194170 K After Reflection: 5093.861596 K 5055.703891 K ~~ Pressure (Ideal) (Empirical) Before Reflection: 1.092520E+005 Pa 1.099455E+005 Pa After Reflection: 5.671345E+005 Pa 5.749778E+005 Pa ~~ Mass Density Ratio (Ideal) (Empirical) Before Reflection: 3.509620 3.550173 After Reflection: 8.294595 8.472776 ~~ Mass Density (Ideal) (Empirical) Before Reflection: 2.263462E-007 kg/cm³ 2.294258E-007 kg/cm³ After Reflection: 5.349439E-007 kg/cm³ 5.475434E-007 kg/cm³ ~~ Concentration (Ideal) (Empirical) Before Reflection: 5.731627E-009 mol/cm³ 5.797856E-009 mol/cm³ After Reflection: 1.354606E-008 mol/cm³ 1.383705E-008 mol/cm³
This is actually working as expected.

When you execute
    Notebook Notebook0 selection={(V_startParagraph+1, 0), endOfChars}


endOfChars refers the the end of the currently selected paragraph at the time the command is invoked. That is, it refers to the end of the V_startParagraph paragraph, not the V_startParagraph+1 paragraph.

To achieve what you want you can change it to this:
    Notebook Notebook0 selection={(V_startParagraph+1, 0), (V_startParagraph+1, 1000)}

Thank you for the replay. I somehow assumed that the second selection would work work relative to the first one. That got me pretty confused.

Regards, Lars