DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

view.activesheet.cursor.x1 = x1

I am using DiaDem10.2. I was trying to set up band cursor on View and had some difficulties which come down to following code. Please help if the following code should work or not...? If not please provide alternative...? The purpose of the code is to set band cursor such that x1 becomes less than x2,  if the band is not selected initially in this way. Thanks.

 

 

 

Option Explicit

Dim n1, n2, n3

n1 = View.ActiveSheet.Cursor.X1

n2 = View.ActiveSheet.Cursor.X2

 

If n1 > n2 Then         ' Swapping n1 and n2

   n3 = n1

   n1 = n2

   n2 = n3

   View.ActiveSheet.Cursor.X1 = n1

   View.ActiveSheet.Cursor.X2 = n2

End If

 

 

 

 

' This code is not working with me. The band still stays the same, i.e. after running the script x1 and x2 propoerty of the cursor are not swapped. This is getting really frustrated now. It works if I set n1 and n2 to be some fixed values say 1 and 2.

0 Kudos
Message 1 of 8
(5,902 Views)

rajoria,

I tested your code and it seems to work correctly for me.  Can you verify the cursors are showing up correctly using the Coordinate Window (View»Display Coordinates)?  It should show the numeric values for the cursors and then you can verify that X1 & X2 were swapped before and after your code.  From your description it sounds like this is only a subset of your code.  If so does this snippet work by itself?

John B.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 8
(5,894 Views)

Thanks John. I find it surprising that the code worked on your computer.

 

When I was doing it, I verified in the coordinate window that x1 and x2 were not swapped. I hope you set the band cursor such that x1 > x2 and then ran the code. If x1 < x2, then the code does not have to be run. Whenever, I selected the band from right to left (thereby making x1 > x2) and then running the code, it would not swap x1 and x2 including in coordinate window. And I think, yesterday I found the reason for it also which is that we cannot make dX to be zero which is what would happen with the first 'View' statement in the 'If-Then' condition. So, View.ActiveSheet.Cursor.X1 = n1 does not get evaluated and the cursor stays at where it was. Similarly second statement is also not evaluated.

 

I tried this code separately from my main code and even this smaller code was not working, so I posted only this part. It is still very surprising to me that the code as it is worked for you. Could you please verify for me that it works whenever x1 > x2....? If it still works then I think some more thinking is needed.

0 Kudos
Message 3 of 8
(5,880 Views)

rajoria,

I copy-pasted your code and ran it and below are my results (for only when x1>x2, otherwise nothing happens):

workingscript.PNG

Since you aren't seeing the same results, I think there might be a difference in our settings.  Can you post a screenshot of the dialog that opens when you choose View»Cursor Parameters?  I will investigate further and see if there are any other possible causes we might want to check that is preventing your code from running correctly but I think that that window is a good place to start.

John B.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 8
(5,874 Views)

John, Thanks for your ananlysis and time. My results are attached below and also Cursor Parameters. I tried with unchecking the "Keep delta-x and delta-y constant" checkbox, but still x1 and x2 are not swapped. Anything you can suggest...??

 

 

BEFORE

 

DIAdem Band Cursor_Before.png

 

 

AFTER

 

DIAdem Band Cursor_After running script.png

 

 

CURSOR PARAMETERS

 

DIAdem Band Cursor_Cursor Parameters.png

0 Kudos
Message 5 of 8
(5,871 Views)

Looks like I found something. I had my cursor set to "Curve" while yours is "Free". The script works fine on my computer when cursor is set to "Free" and x1 and x2 were swapped. It does not work when the cursor is set to "Curve".

 

Also, in 'Coordinate Window' dX can be made 0 only in "Free" cursor mode.

 

This would be fine, but was not hoped so...!!! So, I have to stay in "Free" cursor mode in order to do the swap with my script or change the script for some dithering.

 

John, is the above correct or did you find any solution...?

0 Kudos
Message 6 of 8
(5,866 Views)

I have yet to be able to reproduce your behavior either. Not only does your code work fine with "Free" and "Curve" but it is possible to set the dX to 0 in both modes as well. Can you post your dataset that you are using. In addition, if you try a different data set does the same behavior occur? Finally, I noticed that your two cursors are much closer together than the other ones we've tested. If you move your cursors farther apart does that change anything?

 

Regards,

 

Steven Zittrower

Applications Engineer

National Instruments

http://www.ni.com/support

0 Kudos
Message 7 of 8
(5,850 Views)

StevieZ, What I meant in previous post was that the script worked when cursor is set to "Free" mode. It does not work when cursor is set to "Cursor" mode which is what I had. So, I am changing the mode for my calculations.

 

About dX, same thing is noted that only in "Free mode" I could set it to 0. In other modes, by typing values for dX in the "Coordinate window" I could make cursor lines as close as 1 data point difference, but not 0.

 

I have tried this with 5-6 datasets and the same behavior is noted. Also, I have tried with keeping the cursor lines far apart and also very close, but the script would still not work so long as the mode is not "Free". In the above pictures I kept cursor lines close for clarity.

 

I have attached a dataset that I was using. Thanks.

0 Kudos
Message 8 of 8
(5,840 Views)