How do you code ?

I have some about my program.Par exemple when I compile the program I see like this Error in Procedure: typrogram.How do you code in igo? Experimentmo.pxp (9.57 KB)
Here is the function to discuss:
function tryprogram()
String ctrlName
variable i
variable/G npt=4
Make/O/N=(npt) wavelength=ctrlName
do (i=0)
wavelength[i]=2*i+1
while(i<npt)
i+=1
end

It will compile like this:
function tryprogram()
String ctrlName
variable i
variable/G npt=4
    Make/O/N=(npt) wavelength
    i=0
    do
        wavelength[i]=2*i+1
        i+=1 // NOTE This is moved
    while(i<npt)
end

It would also work like this:
function tryprogram(npt)
variable npt
    Make/O/N=(npt) wavelength
    wavelength=2*p+1
end


What is your intention with ctrlName?
HJDrescher wrote:
Here is the function to discuss:
function tryprogram()
String ctrlName
variable i
variable/G npt=4
Make/O/N=(npt) wavelength=ctrlName
do (i=0)
wavelength[i]=2*i+1
while(i<npt)
i+=1
end

It will compile like this:
function tryprogram()
String ctrlName
variable i
variable/G npt=4
    Make/O/N=(npt) wavelength
    i=0
    do
        wavelength[i]=2*i+1
        i+=1 // NOTE This is moved
    while(i<npt)
end

It would also work like this:
function tryprogram(npt)
variable npt
    Make/O/N=(npt) wavelength
    wavelength=2*p+1
end


What is your intention with ctrlName?

for ctrlName. I would like to create a table when I have value of wavelength[i].

I see this program when he would like to plot Intensity vs wavelength. He use this program

Macro SpectreTotal(ctrlName) : ButtonControl
String ctrlName

KillWaves/Z Wavelength,Intensity
dowindow/K Graph0
dowindow/K Table0
LoadWave/A/G
String list = waveList("*", ";", "")
String traceName
variable i,lgond,cpix //correspondance pixel=cpix;longueur d'onde=lgond
String/G mypath=S_path
variable/G npt

traceName = StringFromList(0, list)
npt=pnt2x($traceName,numpnts($traceName)-1)+1 // N = numpnts(waveName)
Make/O/N=(npt) Wavelength=$traceName
traceName = StringFromList(1, list)
Make/O/N=(npt) Intensity=$traceName
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
lgond=K0*2
cpix=(lgond+29176.718286)/4587.899229
PRINT CPIX
do (i=0)
// Wavelength[i] = lgond + (512/cpix) - (i/cpix)
Wavelength[i] = lgond - (512/6.833) + (i/6.833) + 0.525
i+=1
while(i
edit Intensity,Wavelength
display /W=(10, 20, 600, 400) Intensity vs Wavelength
ModifyGraph rgb=(0,0,0)
//Label left "\\u#2Intensité (u.a.)";DelayUpdate
Label bottom "\\u#2longueur d'onde (A°)"
KillWaves/Z wave0,wave1
ShowInfo
End
I use this program for learn Igor programmation.
I forgot an even shorter version...
function tryprogram(npt)
variable npt
    Make/O/N=(npt) wavelength=2*p+1
end


There are a lot of new things in this fragment. To be honest, it doesn't make sense to explain every little bit here.

Anyway a few things:
* Please use <pre><code class="language-igor">&lt;/xml&gt; and &lt;xml&gt;</code></pre> tags for posting code here.
* Start small.
(and not with buttons, loading waves etc.)
* Read The Fabulous Manual.
* Do the guided tour.
displayhelptopic "Getting Started"

* Read the online help related to the commands in your code sample.
- Press F1; go to the tab labeled Command Help; click in the list on the left; and type the initial characters of the respective command
OR
- Type displayhelptopic "#commandname#" in the command window (ctrl-j), e.g.
displayhelptopic "edit"


HJ
can I have your Email. I would like to discuss with you about Igor inbox.
You can contact me by clicking on my name and then selecting contact.

But there will be no way around reading the manual. I'm serious.

HJ
modou wrote:
for ctrlName. I would like to create a table when I have value of wavelength[i].
...
I use this program for learn Igor programmation.


So, let's assume you mean this ...

Function MakeATableFromAWave(wavename)
     string wavename

     // make the table

    return 0
end


... where wavename is a string that is given in a call such as MakeATableFromAWave("myspectrum1"). Find the menu option that creates a table (Edit). Make all of the selections from the menu option. When you complete this menu option, a command appears in the history window. This command is what you will need to put in your function.

Otherwise as noted here and in other responses to your postings, we all would appreciate that you would spend some time to learn how to post Igor code, to read the manual, and to do the tutorials, especially on programming.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH