Determining VAR lenths


+ Reply to Thread
Results 1 to 7 of 7

Thread: Determining VAR lenths327 days old

  1. #1
    xtal
    Guest xtal's Avatar

    0 Not allowed!

    Default Determining VAR lenths

    Is there a easy way to determine var lengths beside LEN...
    Just for the heck of it I tried......

    Len("ABCDE") yeilded 5 as expected
    Len(Byte) yeilded 1 - probably not reliable
    Len(Word) yeilded 0
    Len(Dword) yeilded AF

    I'm trying to code a LCD DispHex Proc that will work on most vars

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,701
    Thumbs Up
    Received: 361
    Given: 173
    Total Downloaded
    2.08 GB

    0 Not allowed!

    Default Re: Determining VAR lenths

    Take a look at the SizeOf function in the manual.

    Len is for String type variables or character strings or a byte array that terminates with a null because it creates a routine to count the elements until a null (0) is found and this is the value it returns.

    The compiler will give an error message with variable types not supported with it. For example:

    ByteIn = Len(MyByte)
    ByteIn = Len(MyWord)
    ByteIn = Len(MyDword)
    ByteIn = Len(MyFloat)


    Will give error 4 messages: "Invalid variable type for String Source"

    But the compiler's internal casting takes care of assigning one variable type to another, so the SizeOf function is rather redundant in most programs.

    Future updates of the compiler will allow Word or Dword variables to be palced within the Len function, but these will be used as an address to an array or String variable. i.e. Indirect access.
    Last edited by top204; 27th October 2019 at 09:50.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    xtal
    Guest xtal's Avatar

    0 Not allowed!

    Default Re: Determining VAR lenths

    I tried sizeof -- results were not good , or I'm doing something wrong.....
    Looks like SizeOf AND HRSOUT might have issue??

    Code:
    using 3.7.2.9 
    
    
    chip = 16F1827    
     
    Dim nb1 As Float
    Dim nb2 As Dword
    Dim nb3 As SDword
    Dim nb4 As Word                       '
    Dim nb5 As SWord
    Dim nb6 As Byte
    Dim nb7 As SByte
    
    
    I had to add HEX2  in order to see value, otherwise asc chr  **********************
    
    
    nb1=1:nb2=1:nb3=1:nb4=1:nb5=1:nb6=1:nb7=1     ' added this, but same result 
    
    
    HRSOut "Len = ",Hex2 SizeOf(nb1),13       ' float = 4 but get Len = 02
    HRSOut "Len = ",Hex2 SizeOf(nb2),13       ' dword = 4 but get Len = 02
    HRSOut "Len = ",Hex2 SizeOf(nb3),13       ' sdword= 4 but get Len = 02
    HRSOut "Len = ",Hex2 SizeOf(nb4),13       ' word  = 2 but get Len = 02
    HRSOut "Len = ",Hex2 SizeOf(nb5),13       ' sword = 2 but get Len = 02
    HRSOut "Len = ",Hex2 SizeOf(nb6),13       ' byte  = 1 but get Len = 02
    HRSOut "Len = ",Hex2 SizeOf(nb7),13       ' sbyte = 1 but get Len = 02
    HRSOut "Len = ",Hex2 SizeOf("ABCDEF"),13  ' string= 6 but get Len = 02
    HRSOut "Len = ",Hex2 Len("ABCDEF"),13     ' string= 6 but get Len = 02
    XXX = Len("ABCDEF")
    HRSOut "Len = ",XXX,13                    ' string= 6 but get asc chr ************
    HRSOut "Len = ",Hex2 XXX,13               ' string= 6 -- shows 06

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    xtal
    Guest xtal's Avatar

    0 Not allowed!

    Default Re: Determining VAR lenths

    HRSout may be OK, if char output is default ie need to use modifier

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    xtal
    Guest xtal's Avatar

    0 Not allowed!

    Default Re: Determining VAR lenths

    This works, looks like HRSOUT doesn't like embedded SizeOF with a non string VAR ....

    NOW how can I pass different size VARs to a PROC ?? Is it possible ??

    Sizeof VARString gives size of defined string , not the actual size of string , must use Len.....



    Code:
    XXX = SizeOf(nb1)
    YYY = SizeOf(nb2)
    NNN = SizeOf(nb3)
    N01 = SizeOf(nb4)
    HiBusy = SizeOf(nb5)
    LoBusy = SizeOf(nb6)
    Spos = SizeOf(nb7)
    TEMP = "zxczxczxc"
    HRSOut "Len = ",Dec XXX,13       ' float = 4  
    HRSOut "Len = ",Dec YYY,13       ' dword = 4  
    HRSOut "Len = ",Dec NNN,13       ' sdword= 4  
    HRSOut "Len = ",Dec N01,13       ' word  = 2  
    HRSOut "Len = ",Dec HiBusy,13       ' sword = 2  
    HRSOut "Len = ",Dec LoBusy,13       ' byte  = 1  
    HRSOut "Len = ",Dec Spos,13       ' sbyte = 1  
    HRSOut "Len = ",Dec SizeOf("ABCDEF"),13  ' string= 6  
    HRSOut "Len = ",Dec Len("ABCDEF"),13     ' string= 6 
    HRSOut "Len = ",Dec SizeOf(TEMP),13       ' 9
    Last edited by xtal; 28th October 2019 at 23:10. Reason: clarify

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,374
    Thumbs Up
    Received: 87
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: Determining VAR lenths

    NOW how can I pass different size VARs to a PROC ?? Is it possible ??
    You want to use variants?
    George.

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    xtal
    Guest xtal's Avatar

    0 Not allowed!

    Default Re: Determining VAR lenths

    George

    Can you explain more on variants, I can't find in Proton manual.

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. How to decrement /increment a var
    By C_Moore in forum The Lounge
    Replies: 2
    Last Post: 11th October 2016, 10:43
  2. Replies: 7
    Last Post: 22nd September 2012, 10:22
  3. [SOLVED !] VAR used not reflected
    By PICnewbie1 in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 4th October 2009, 21:51
  4. [SOLVED !] Compare PORTB to var question
    By Marcel in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 24th December 2007, 16:03
  5. [SOLVED !] Rounding a Float Var ....
    By Quickeye in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 15th July 2005, 21:38

Posting Permissions

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