Author Topic: Variables  (Read 12684 times)

Lorne Van Dusen

  • Jr. Member
  • Posts: 93
  • I'm a old guy
    • View Profile
Variables
« on: February 22, 2017, 01:58:34 PM »
While I was viewing all the resent posts I figured I should ask the one question that has been confusing me when it comes to the variables in the TRi PLC
You have A to Z, you have A# to Z# and you have A$ to Z$
I am confused about A to Z
If I understand correctly  A# to Z# are for storing floating point numbers
and A$ to Z$ are mainly for storing ASCII strings

Do they take up the same memory locations?
Can you use A to Z as well as A# to Z# and A$ to Z$ within the same program or would there be a conflict ?

Lorne

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Variables
« Reply #1 on: February 22, 2017, 10:21:04 PM »
A to Z, A# to Z# and A$ to Z$ are different variables and they occupy different memory space inside the PLC. Yes they can appear in the same program and within the same custom function without any conflict.

Note that TBASIC does not automatically convert string type to numeric type (integer and floating points are both numeric). But there are functions that allow you to convert from one variable type to another variable type. E.g. STR$(n), HEX$(n), VAL(n) HEXVAL(n).  A# to Z# can be assigned to A to Z with some loss of precision.

E.g.   A = Z#*1.2345/A#   ' the floating point computation result is converted to integer and assigned to A.
« Last Edit: February 22, 2017, 10:22:48 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Lorne Van Dusen

  • Jr. Member
  • Posts: 93
  • I'm a old guy
    • View Profile
Re:Variables
« Reply #2 on: February 23, 2017, 06:50:08 AM »
Thanks I now understand.
I actually thought that A$ & A# were in the same memory area and that the $ or the # just told the program what format to use.