Showing results 1 to 5 of 5

Thread: Setting value to variable in VBA from variable in project

  1. #1
    Join Date
    03.11.2014
    Posts
    10

    Default Setting value to variable in VBA from variable in project

    Hi,
    In this sub I am trying to get w to get the value 3 (from u). First I assigning a variable in the project to the value 3 from u. Then I am setting the variable w to the value of the variable in the project. This works except for the last line. What is wrong?


    Sub LocalPrice()
    Dim u As Double
    Dim w As Double
    u = 3
    thisProject.Variables.Item("Spotpris3[1]").Value = u
    w = thisProject.Variables.Item("Spotpris3[1]").Value
    End Sub

    I also wonder if I can "add watch" when debugging to a variable in the project? How do I do that?

    Best,
    Jonas

  2. #2
    Join Date
    03.11.2014
    Posts
    10

    Default Re: Setting value to variable in VBA from variable in project

    Ok I realized that for this to work i need to initialize thisProject.Variables.Item("Spotpris3[1]").Value somewhere on the screen.

    If I add a "numerical value" to the screen showing Spotpris3[1] then it works.

    Is there someway of getting around that if I dont want to show the value?

    Best,
    Jonas

  3. #3
    martins Gast

    Default Re: Setting value to variable in VBA from variable in project

    hi,

    The reason for this is that variables are not constantly read from the PLC - just when they are "needed". There are several conditions that need to be fulfilled so a value is requested from the PLC - e.g.:
    - shown in a screen right now
    - has a limit
    - has HDD storage set
    - has setting "permanently read variable" set
    - ...

    When reading a variable over the API, zenon doesn't know about this in advance so it cannot advise it - this means, no value is available when the API requests it. This however means: we have to tell zenon first which variables we would like to read from the PLC before we try to access their values. This is done with the OnlineVariable object.

    you can find an example how to read values from a variable in the manual under Manual - VBA - OnlineVariable

    You can also find threads here in the forum that are dealing with this - just search for OnlineVariable here in the forum.

    best regards,
    Martin

  4. #4

    Default Re: Setting value to variable in VBA from variable in project

    Hello

    I am looking for example on forum for this access to online variable, but i didnt find it. 
    Basically I need to read variable which is coming from PLC (s7-400) and to read local variable from zenon and compare it, & also to set one bool variable so i can signalize result of comparison.
    I have found how to make container, but I didnt found how to use this online variables later on in macro. (I am not expert in VBA syntax). Some simple example on how you use Online Variables in makro would do a lot for me... 

    I am using Zenon 7.50.
    Thanks in advance  

  5. #5

    Default Re: Setting value to variable in VBA from variable in project

    Hi Nedic,

    Using the API for this type of functionality is not necessary. Potentially you make the project more complex and less transparent.

    Have a look at the Mathematics driver or at zenon logic, where such comparisons can be performed easily.

    Best regards,
    Mark

Similar Threads

  1. VSTA read variable value's another project!
    By dvangenderen in forum VSTA
    Replies: 5
    Last Post: 1st December 2011, 10:04
  2. Variable setting
    By whitetaru in forum Drivers
    Replies: 2
    Last Post: 27th April 2011, 01:15
  3. Replies: 12
    Last Post: 25th November 2010, 10:54
  4. "variable image remanent" setting is not saved
    By markclemens in forum zenon Supervisor
    Replies: 0
    Last Post: 28th March 2008, 09:13

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •