How to use SliderValue of a SliderControl inside a function

I want to implement a slider control without Structure based code...I dont fully dont understand how to use the value of Slider control to my function that I call when Slider is moved and rest in a value. and also it gives me error in the SliderProc as ''Parameter not defined..."
The function MoveSegment shift( along y) the part of the graph between two cursor. Can anybody give me some idea.
The example in Igor helpfiles are mainly based on structure based code...so didnt help me lot

NVAR SliderValue= root:SliderValue

Slider slider1,pos={700,50},size={50,200},proc=MySliderProc
Slider slider1,limits={-500,500,10},value= 0, vert= 1

//---------------------------
Function MySliderProc(ctrl, SliderValue, event) : SliderControl
    String ctrl
    // Slider $cntl
    Variable event  // bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved

if (event %& 0x1)   // bit 0, value set

MoveSegment()

    endif

    return 0
End

//---------------------------------------------

Function MoveSegment()

NVAR SliderValue= root:SliderValue


    WAVE/Z yWave = CsrWaveRef(A)
    if (!WaveExists(yWave))         // Cursor is not on any wave
        return -1
    endif
 
    WAVE/Z xWave = CsrXWaveRef(A)
    if (!WaveExists(xWave))         // Cursor is not on XY pair
        return -1
    endif
 
    Variable startX = hcsr(A)
    Variable endX = hcsr(B)
 
    if (startX > endX)
        return -1
    endif
 
    YWave = (XWave>=startX && XWave<=endX) ? YWave + SliderValue : YWave
 
    return 0
End
Slider slider1,pos={700,50},size={50,200},proc=MySliderProc
Slider slider1,limits={-500,500,10},value= 0, vert= 1
 
//---------------------------
Function MySliderProc(ctrl, SliderValue, event) : SliderControl
    String ctrl
    Variable SliderValue
    Variable event  // bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved
 
    if (event & 0x1)    // bit 0, value set
 
        MoveSegment(SliderValue)
 
    endif
 
    return 0
End
 
//---------------------------------------------
 
Function MoveSegment(SliderValue)
    Variable SliderValue
 
    WAVE/Z yWave = CsrWaveRef(A)
    if (!WaveExists(yWave))         // Cursor is not on any wave
        return -1
    endif
 
    WAVE/Z xWave = CsrXWaveRef(A)
    if (!WaveExists(xWave))         // Cursor is not on XY pair
        return -1
    endif
 
    Variable startX = hcsr(A)
    Variable endX = hcsr(B)
 
    if (startX > endX)
        return -1
    endif
 
    YWave = (XWave>=startX && XWave<=endX) ? YWave + SliderValue : YWave
 
    return 0
End

NOTE: I haven't run this- there may still be problems.

It really isn't hard to use the structure-based version of the action procedure, and they are faster and future developments will go into the structure-based procedures. Like this:
Function MySliderProc(s) : SliderControl
    STRUCT WMSliderAction &s
 
    if (s.eventCode & 0x1)  // bit 0, value set
        MoveSegment(s.curval)
    endif
 
    return 0
End


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thanks John ...indeed it works great...I just want to ask you another thing...

in the current code of MoveSegment function when I move the silder the y wave changes..but it changes the y wave in every slider move ..I cant bring it back to its initial value of y ...

how can I do that...such that ..say if I change slider by 10 ..y wave will be y+10 ...and then next time if I change the slider by 50 it should be y+50 ...now in current sitaution it becomes cumulative like this two slider change makes y+10+50 and eventually its completley out of control ( as I apply it to graph...the motivation is to shift the graph along y by certain value)
supra wrote:

in the current code of MoveSegment function when I move the silder the y wave changes..but it changes the y wave in every slider move ..I cant bring it back to its initial value of y ...

how can I do that...such that ..say if I change slider by 10 ..y wave will be y+10 ...and then next time if I change the slider by 50 it should be y+50 ...now in current sitaution it becomes cumulative like this two slider change makes y+10+50 and eventually its completley out of control ( as I apply it to graph...the motivation is to shift the graph along y by certain value)


I would recommend making a copy of yWave. say,

Duplicate/O ywave ycopy


Then, your function could do ywave = ycopy + slidervalue.

This way, ywave on the graph will always move in reference to it's original values.
Hi
Thank you so much for your reply. As you said I tried to duplicate Ywave in Ycopy..
Duplicate/O YWave Ycopy

YWave = (XWave>=startX && XWave<=endX) ? YCopy + SliderValue : YWave

but still it does not work. Can you think of any other way to do it ?
The suggestion about a copy was that you would make one copy of the wave at the beginning and use that copy for all slider adjustments.

But you don't need to copy the entire wave. All you need to store is what you previously added to the wave. Here is code that does that:

Function/DF GetSupraPackageDFR()
    DFREF dfr = root:Packages:Supra
    if (DataFolderRefStatus(dfr) != 1)
        NewDataFolder /O root:Packages
        NewDataFolder /O root:Packages:Supra
        DFREF dfr = root:Packages:Supra
        Variable/G dfr:gLastSliderValueAdded = 0
    endif
    return dfr
End

Function AddSliderValue(xWave, yWave, startX, endX, sliderValue)
    Wave xWave, yWave
    Variable startX, endX
    Variable sliderValue
   
    // Take the previously-added slider value, if any, into account
    DFREF dfr = GetSupraPackageDFR()
    NVAR gLastSliderValueAdded = dfr:gLastSliderValueAdded

    // To avoid accumulation of roundoff error we do this in two steps
    YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
    YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0

    gLastSliderValueAdded = sliderValue
End