From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

If...Then...Else on event click buttons script, is it possible?

en:The general project is that i want to made something i already have in labview but with diadem i attached an image so you can understand what im looking for

es:El proyecto general es que quiero realizar algo que ya tengo en labview pero con diadem anexo la imagen para que puedan enteder lo que busco

 dif ang lab.jpg

 

en :so.. i'm trying to use conditions in my script but i have the problem that my event gets cut when i enter a condition

es :asi que estoy tratando de usar condiciones en el script pero tengo el problema de que el evento se recorta en la condición if

 

dif ang2.png

 

 

 

en:and i don't know if it is even possible to use them in the event script and this is what i have so far

es:y no sé si es siquiera posible de usar condicionales en el script de evento y esto es lo que llevo

 

dif ang1.png

 

en:as you can see i hid the code i need for testing

es:como pueden ver oculté el código que necesito para pruebas

0 Kudos
Message 1 of 5
(5,687 Views)

Your code contains a syntax error when using Globaldim.

Sub Button1_EventClick(ByRef This)
  If Not Iteminfoget("rVal") Then call GlobalDim("rVal")
  If Not Iteminfoget("rNewVal") Then call GlobalDim("rNewVal")
  rVal = chncombobox1.value
  if (rVal = 0) then 
    rVal = rNewVal 
  elseif rNewVal > 180  then
    rVal = rNewVal -360
  elseif rNewVal < 180  then
    rVal = rNewVal +360    
  end if

 

Do you really need GlobaDim or is it just a typo and you meant dim?

The red lines are caused because of the condition in single line if syntax.

0 Kudos
Message 2 of 5
(5,665 Views)

About global dim i was just following this if..then..else tutorial then i don't remember how but i found in the forum someone asking for nearly the same and his problem was he needed to use global dim, so that's why i used but i really don't know if i needed too.

 

thank you for helping me out with my code i know it now works because i added boxes displaying values but it seems using chncombobox just uses 1 value of all the data because after the substraction i only get a plot with no changes at all.

 

Sub Button1_EventClick(ByRef This) 'Created Event Handler
Dim rVal, rNewVal
Call Data.Root.ChannelGroups.Add("Dif_Angular", 2).Activate()
If Not Iteminfoget("rVal") Then call GlobalDim("rVal")
  If Not Iteminfoget("rNewVal") Then call GlobalDim("rNewVal")
  rVal = ChnComboBox1.Value
  if (rVal = 0) then 
    rVal = rNewVal 
  elseif rNewVal > 180  then
    rVal = rNewVal -360
  elseif rNewVal < 180  then
    rVal = rNewVal +360    
  end if
Call ChnSub(ChnComboBox1.Value, ChnComboBox2.Value, "Diferencia Angular")
Call MsgBoxDisp("the value is :" & rVal)
Call MsgBoxDisp("the value is :" & rNewVal)
End Sub

diadem 2.PNG

 

 so i tried using a new variable called ReturnValue and adding the result channel after the conditions 

ReturnValue= ChnSub(ChnComboBox1.Value, ChnComboBox2.Value, "Diferencia Angular")
Call ChnAlloc ("Diferencia Angular, rVal ")
Sub Button1_EventClick(ByRef This) 'Created Event Handler
Dim rVal, rNewVal, ReturnValue
Call Data.Root.ChannelGroups.Add("Dif_Angular", 2).Activate()
ReturnValue= ChnSub(ChnComboBox1.Value, ChnComboBox2.Value, "Diferencia Angular") If Not Iteminfoget("rVal") Then call GlobalDim("rVal") If Not Iteminfoget("rNewVal") Then call GlobalDim("rNewVal") rVal = ReturnValue if (rVal = 0) then rVal = rNewVal elseif rNewVal > 180 then rVal = rNewVal -360 elseif rNewVal < 180 then rVal = rNewVal +360 end if Call ChnAlloc ("Diferencia Angular, rVal") Call MsgBoxDisp("the value is :" & rVal) Call MsgBoxDisp("the value is :" & rNewVal) End Sub

after those changes i just get the error message  "type mismatch"

0 Kudos
Message 3 of 5
(5,648 Views)

Hi Johnny,

 

A combobox provides N different drop-down options, of which the user selects one, so it's perfectly expected that only one of its values would be operated on.  If you want a multi-select control, I'd suggest using a list box in multi-select mode.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 5
(5,623 Views)

I didn't notice you all can't make the image project biggerdif ang lab.jpg

 

alright! so i made the changes that was proposed and still i have 2 problems and i don't know if they have solution the way i am doing it 

 

Sub Button1_EventClick(ByRef This) 'Created Event Handler
Dim rVal, rNewVal, LV1, LV2,LV3', ReturnValue  'LV1 it's the variable from ChnListBox1 and LV2 ChnListBox
Call Data.Root.ChannelGroups.Add("Dif_Angular", 2).Activate()
Call ChnSub(ChnListBox1.Text, ChnListBox2.Text, "Diferencia Angular") 'this do the trick ChnListbox1 - ChnListbox2
'i'm testing this line using variables LV3 for result channel
LV3= Ch(""[2]/Diferencia Angular"") 'i get an error here
If Not Iteminfoget("rVal") Then Call GlobalDim("rVal")
  If Not Iteminfoget("rNewVal") Then call GlobalDim("rNewVal")
  rVal = LV3
  if (rVal = 0) then
    rVal = rNewVal
  elseif rNewVal > 180  then
    rVal = rNewVal -360
  elseif rNewVal < 180  then
    rVal = rNewVal +360    
  end if
'i read that ctnv can also be used for conditions 
'ChnCalculate("Ch(""example"") = Ch(""[2]/Diferencia Angular"")-CTNV(Ch(""[2]/Diferencia Angular"")<180)")
'still reading how to use it 
'Call Calculate("Ch(""Diferencia Angular"")=(ChnListBox1.Value - ChnListBox2.Value)")
'ReturnValue = ChnAdd ( , ,rVal)
'Call ChnSub(ChnListBox1.Text, ChnListBox2.Text, "Result5")
'was trying to use ChnAlloc to add my conditioned rVal but
i think that can't be done because i can't find where do i put rVal inside the coma's
'Call ChnAlloc ("Diferencia Angular",90000, , 1)
'this is for testing if the conditions after rVal are working
'Call MsgBoxDisp("Resultado: " & rVal)
End Sub

 and this is how my dialog box looks like now

dif ang3.png

 

so after the new subtracted channel is made i can't manage to use the new channel to apply my conditions

 

after my conditions are verified how do i make a new channel for the new result is it possible?

 

and after reading what does ctnv does in the command calculate should it be better using it in my subtraction Or it can't be done?

 

 

Download All
0 Kudos
Message 5 of 5
(5,575 Views)