How to change a global variable in a function?

Hello

I want to change a globalvariable in a function, as a first step I made in this way:

class Global_output_class

GlobalDim("Correlation_Status,fail_part,End_Exp")
dim pouet

Correlation_Status = 12
Call Correlation()
pouet = Correlation_Status

Function Correlation()
  Dim Global_output_class_sub
  Set Global_output_class_sub = new Global_output_class

  Correlation_Status = 1
  fail_part = 2
  End_Exp = 3

  Global_output_class_sub.CorrelationStatus = Correlation_Status
  Global_output_class_sub.failpart = fail_part
  Global_output_class_sub.EndExp = End_Exp
  set Correlation = Global_output_class_sub
End function

In this case: correlation_status receives a value of 12, then I go to my correlationn() function where it became 1

Then he comes out of the Sub-function and takes the previous value of the program (12) (I hate that)

To solve the problem I did it this way:

class Global_output_class
public CorrelationStatus
public failpart
public EndExp
end class 

GlobalDim("Correlation_Status,fail_part,End_Exp")

Correlation_Status = 12
Set Global_Output = Correlation()
Correlation_Status = Global_Output.CorrelationStatus
fail_part = Global_Output.failpart
End_Exp = Global_Output.EndExp
pouet = Correlation_Status

Function Correlation()
  Dim Global_output_class_sub
  Set Global_output_class_sub = new Global_output_class

  Correlation_Status = 1
  fail_part = 2
  End_Exp = 3

  Global_output_class_sub.CorrelationStatus = Correlation_Status
  Global_output_class_sub.failpart = fail_part
  Global_output_class_sub.EndExp = End_Exp
  set Correlation = Global_output_class_sub
End function

This way my global value are copied in themselves after leaving the subprogramme

I had a lot of variables, is there an easier way for the global variable in a function of change keep the value after you leave the service?

Thanks for the help,

Fred

Hi Fred,.

It is possible to use a global variable defined, but the best way is to use a function call (or procedure call) with parameters. Please first find the right solution for a function call with parameter and the suboptimal way with a comprehensive valiable:

dim oParameter
set oParameter = new cGlobal_output_class

oParameter.Correlation_Status = 12

msgbox "Correlation_Status before Call Correlation: " & oParameter.Correlation_Status
Call Correlation(oParameter)
msgbox "Correlation_Status after Call Correlation: " & oParameter.Correlation_Status

'-------------------------------------------------------------------------------
Function Correlation(oPara)
  msgbox "Correlation_Status in the FUNCTION before change: " & oPara.Correlation_Status
  oPara.Correlation_Status = 1
  oPara.fail_part = 2
  oPara.End_Exp = 3
  msgbox "Correlation_Status in the FUNCTION after change: " & oPara.Correlation_Status
End function

'-------------------------------------------------------------------------------
class cGlobal_output_class
  dim Correlation_Status,fail_part,End_Exp
end class
call GlobalDim("oPouet")

dim oPouet
set oPouet = new cGlobal_output_class

oPouet.Correlation_Status = 12

msgbox "Correlation_Status before Call Correlation: " & oPouet.Correlation_Status
Call Correlation()
msgbox "Correlation_Status before Call Correlation: " & oPouet.Correlation_Status

'-------------------------------------------------------------------------------
Function Correlation()
  msgbox "Correlation_Status in the FUNCTION before change: " & oPouet.Correlation_Status
  oPouet.Correlation_Status = 1
  oPouet.fail_part = 2
  oPouet.End_Exp = 3
  msgbox "Correlation_Status in the FUNCTION after change: " & oPouet.Correlation_Status
End function

'-------------------------------------------------------------------------------
class cGlobal_output_class
  dim Correlation_Status,fail_part,End_Exp
end class

Greetings

Walter

Tags: NI Software

Similar Questions

  • How to change a global variable of b form to form.

    Oracle forms builder 10.1.2.0.2 version
    version 10.1.2.0.2, Oracle database

    I try to pass a global variable of the form b to form one; I have an error frm-40815
    does not define a global variable in a form file.
    without doubt, I missed something. could you tell me what I missed?

    Here is my sample code;
    form a
    in when new forms instance trigger;
    :myblock.getvalue := :global.p_ck;
    .....
    
    forms b
    in when button pressed;
    call_form('a');
    :global.p_ck := :myblock2.checked;

    I assume that null value passed.
    you have an idea?

    If this previous error is resolved means that now form works well. Now, if there is then no value. So I think that the domain that you assign is not having any value for the test, you can use like this...

    :global.p_ck := NVL(:myblock2.checked,'Blank');
    call_form('a');
    

    -Clément

  • How to create a Global Variable through the Project Explorer

    Hello world!

    I know how to create a global variable (in a vi through the range of functions...).

    but I'm missing a way to create one via the Project Explorer.

    It's a missing feature or just this documentation (and the intuition of myself) are missing?

    It would be very convenient.

    THX for your time and hope that answers.

    jwscs

    Right click on my computer > new > new... > select Global Variable.

    EDIT: although I agree with Gerd (he probably wondering why you need so we can recommend a better way ), I rarely use them in easy to write once - read many applications such as security levels overall program at initialization (VER) to read later, but NOT modified.  I know it would be better to make a good class, functional Global Variable (FGV) or a motor Action (AE) but globals ARE practical and safe IF used wisely.

  • To access the Global Variables in the functions/methods

    Which of the following statements is better in terms of performance and efficiency?

    public var a: int = 0;


    public void add (): void {}

    a += 5;

    }

    Addition();

    OR

    public var a: int = 0;

    public void Addition(b:int):int {}
    b += 5;
    Back to b;
    }

    a = (a) Addition;

    I saw a lot of guides discourages the use of global variables in the functions/methods, but I just don't understand why anyone would create a copy of the variable, modify this copy and to grant this value to another variable and throw.

    You must create an instance to pass to your function.  the parameter (for example, mov) does not create a separate instance and creates only a temporary pointer to the passed object.

    If an instance is prepared for gc, having spent this instance to any number of methods (as a parameter) delay / will not interfere with ca.

    and Yes.

    MOV ['x'] = mov.x,

    MOV ["rotation"] = MOV.rotation,

    MOV [anypropertystring] = MC.anyproperty

    Flash uses array notation to solve strings into objects:

    var var1:ClassType = new ClassType();

    This ['var1'] = this.var1

  • How to pass the global variable...

    Hello

    I have a report in a page and form in another page...

    If I clicked on the icon change in the report page it navigates to the form in another page...

    In this im report have "bill_amount" as one of the column, if I clicked on the icon change report page means, it will go to the form in another page...

    This form consist of one text field which is "bill_amount"...

    Since the report that I bill_amount for each entry, if I clicked on the icon change the means of the respective row, it does not appear automatically the respective bill_amount in the text in the form field...

    I created a report separately on the sql_query table... I created a form with a single field 'bill_amount '...

    Given that I na not create a report and a form based on the table... If I have created as it means if I clicked on the icon change it will show the datas respective in the form... since I created a report and form separately...

    If it is possible to create a global variable... who will bring the value of the "invoice amount" in the relationship and you will go the respective value in the form field on the next page...

    I don't want to put the value in the form field by restricting by request... She must take through the global variable...

    How can I reach it...

    It is urgent...

    concerning
    Mini

    Hello

    In her edit link column u give, the respective form field name, and the name of the column in the report inside...

    So that the value in the report of the corresponding column will be inserted into the corresponding field in the form...

    (IE) like this

    > p1_item_name---> #corresponding report name column #.

    Concerning
    GTA...

  • How to access a global variable that is common between the different baskets project library

    My project consist of several libraries, after generation the library project packed for each library, I find it cannot share data in a global variable between different packaged project library file. For example: packed project library #1 contains VI variables global wirte 'position' and give it a value '400 '. Library #2 present another VI project try to read this global variable, but he gave reading of is NULL not "400". Why has this happened? Is it possible to solve, welcome any help, I wll appreciate for this!

    If you understand what is happening here...

    When you build a PPL, it takes in the .lvlib and also all the dependencies of the .lvlib.

    In your case, when you generate the Test Task.lvlib in a .lvlibp, she also pulls on a copy of the DataProcess.lvlib:GlobalsVariable.vi because it's addictive to read GlobalVar.vi.

    When your application runs, you end up with two copies of GlobalsVariable.vi in memory:

    DataProcess.lvlibp:GlobalsVariable.vi

    AND

    Test Task.lvlibp:: GlobalsVariable.vi (I don't know how PPLs namespace dependencies... If there is still the DataProcess.lvlibp)

    Because they are different screws (i.e. in a different namespace), they have their own memory and that's why you can't access the data.

    Your Test Task.lvlibp calls the version of GlobalsVariable.vi, he pulled the dependencies.

    To solve this problem - you must ensure that Task.lvlibp of Test calls the version of GlobalsVariable.vi of the DataProcess.lvlibp - you'll need to replace all instances with the version of the PPL. Of course, if you run DataProcess in the development environment, then it will always be bad namespaced, hence the suggestion to put your global variable VI in is own PPL that you then use in the process of data and Test tasks.

  • How to create a global variable?

    I want to create a global variable start button to control programs in the structure of the sequence. But I do not know how to creat it. Thanks for responding.


  • How to associate existing global variables

    It's probably something stupid that I'm missing.

    I created a global variable and there is a string.  I put it in a file called XML_Global.vi I then proceeded to make an another global var and would assign to the same variable.  However, the IDE shows me an another façade Globals 4.  How can I associate the existing façade of XML_Global.vi with the global variable I PLOPPED down there?  I looked everywhere on how to proceed in the properties and others, but couldn't find it.

    Have you read through this document?

    http://zone.NI.com/reference/en-XX/help/371361F-01/lvhowto/creating_global_variables/

    There may be some confusion about what is happening... When I add a global variable for the rough process, I followed the block diagram is:

    • Open the front panel to the global variable
    • Add FP (there may be several elements in a global variable VI)
    • Save the global variable VI
    • Then drag + drop of my project on a diagram VI
    • Select the variable I want by double clicking on the overall and will select an element > name Variable

    If this clears it for you? Looks like you try to simply place another instance of global variable in the palette of functions and then select the variable to assign this instance to (similar to what you would do with a local variable)? With globals, a new instance of a global VI is created when you drop the global BD... you want to place the world you have edited/saved (drag + drop of project or use the "Select" VI in the range of functions).

    I hope this helps...

  • How to use the global variable in the table target?

    Hello

    I am trying to load several files into a single interface. the data is loaded successfully. 92. the files are there. for this I used variables and package.

    My requrement is 92 files of data loaded into the target table. I want to know what data from file.

    to this I added a column (filename) to the existing target table.

    If I used joints (not same condition), its totally wrong. all file names are coming.

    Please see the following screenshots.

    err27.jpg

    exit; target table.

    err26.jpg

    in fact in the target table. first 10 lines are coming from file.i.e first _ACCOUNT_LIMIT_511.TXT. but all the files names are coming.

    I'm confuse. After the first data file inserted then insert second data file. in that all file names are coming. Please help me.

    I thought that the global variable is preferable to identify the data came from which file.

    to do this, the global variable is used in the target table. I don't always have my exit.

    Please help me.

    Thanks in advance.

    err25.jpg

    Hello

    You can use the same way, how you use the project variable, just you have to do a thin is #GLOBAL.variable_name for example: #GLOBAL. SMART_AL_FILE_NAME_S

    Note: Make sure you that while you use one variable overall in interface, indicator should be staged as you chose above the screen

    hope this helps you

    Kind regards

    Phanikanth

  • How to change the constant variable rate?

    Hello

    I export an HDV mpeg file that has a constant rate of a video H264 (.mp4) video for download on a web-based video player. I actually use the preset in Media Encoder 'YouTube HD 720 p 29.97'.

    The web interface of video online that I use requires a constant rate. But when you look at the video in MediaInfo it shows the video file as a variable rate. After looking through the settings in Media Encoder I found no option to fix this.  I see where you can change the frame rate and it is 29.97. So you might think, it would be constant but is not. And there is not any settings, I see, to change the constant variable. I don't see the flow settings, but this isn't the issue.

    I also have Apple Compressor and making a successful rate constant, but if possible I prefer to use Adobe Media Encoder. If anyone knows how to change this setting? Thank you

    Hi CLCTV,

    To close this thread, interpreted as variable rate exports are now interpreted as constant in the CC SOUL 2014 (8,0) and later. Please create a new thread if you are still having trouble with this problem.

    Thank you

    Kevin

  • How to get the global variable for an instanceId

    Hello

    I have data in global variables of an instance level. And using that instanceId, how can I get the global-level variables data.

    Please me tips


    Thank you
    Sailendra

    Hello
    I guess you want to get the value of the external variable within the process. You can do like this:

    assuming that it is of type string. For other types of type cast properly...
    String extVarValue = (String) (New Component(instance: this)).get(attribute: extVarName);

    Replace "extVarName" with your project name. It returns the value of your project for the instance that you are currently working.

    -Thank you,
    Malar.

  • How to declare a global variable

    Hi all

    I want to declare a variable in Graf and assign its value to the No.

    And in certain conditions in PFR() I want to change the value of this variable to YES.

    in Graf

    {

    String test = "NO";

    }

    in pfr()

    {

    If (some condition)

    {

    test = "YES";

    }

    }

    How can I do this?

    Thank you stephanie... Thank you very much...

  • How to link a global variable?

    Hello

    I tried to bind a variable with the new FlexGlobals.topLevelApplication but without success. Is there another way?

    Thanks in advance

    Add Metatag that can be bound to the class

    package
    {
    [Bindable]
    public class Test
    {

  • How to make a USB-TC01 temperature data a global variable?

    Hi all!  I have a simple question (probably).  I bought the box USB-TC01 and with the software came a VI called LabVIEWTempLogger.  This VI reads a thermocouple voltage and internal conversions using DAQmx and a CYC edge to give a reading of simple temperature.  My problem is that I want to use this temperature in an another VI, then I want to make a global variable of temperature of LabVIEWTempLogger.  How to set a global variable such as temperature of LabVIEWTempLogger?  Thank you!

    You must get out of the recorder temperature VI the DAQ Assistant. Put it in a Subvi if you wish.

    Your main VI has some problems. The first fact a comparison is equal to the current temperature. Never make an equal comparison on a floating point number. Use in the range and force.

    The local 'Set Temp deg C' should be replaced by a wire from the Terminal. All local variables should be replaced by a wire. You can easily have the cable terminals from outside the main loop.

    Can't the difference in code in the States True and False when you read voltage.

    Don't use VISA bytes to the Serial Port. It's just bad style. You programmed it for a terminal character LF to get rid of fixed forward and set the number of bytes to read at a high number. Playback will wait until the stop character is detected and then automatically end.

    Finally, you have already created a world so I do not understand your questions about it.

  • How to reword scope of global variables on a per instance basis?

    I have a legacy application of this unforutnatly makes a lot of use of global variables (not the functional kind).  If we want to run two instances of the first level VI simultaneously without using global variables collided with another, which is the least painful to achieve this way * without * having to build in an exe?

    I don't know if it'll work or not, but that would happen if you ran the screws in two different projects?   I might have to try that when I managed to find some free time.

Maybe you are looking for