Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:15 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Using Bin2Str$ in function.

Author Message
Greg Fordyce
Senior Member

Joined: 16/09/2011
Location: United Kingdom
Posts: 153
Posted: 10:41pm 30 Oct 2019
Copy link to clipboard 
Print this post

Is it possible to use Bin2Str$ in a function? Sample code and console output showing syntax error. Cheers, Greg.

> list
 Option default integer
 Print Bin2Str$(uint16, 12345)

 a = crc("uint16", 12345)

Function crc(parm$, x)
Print parm$, x
 crc = x * 2
   Print Bin2Str$(parm$, x)
End Function

> run
90
uint16 12345
[10] Print Bin2Str$(parm$, x)
Error: Syntax
>
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1882
Posted: 01:07am 31 Oct 2019
Copy link to clipboard 
Print this post

The first call to Bin2Str$: Print Bin2Str$(uint16, 12345) uses the predefined value unit16 as the type qualifier.

The second call appears to use the string "uint16" as the type qualifier.

I haven't used the Bin2Str$ function before, I may be having a seniors moment with this post

Mike.
NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 05:05am 31 Oct 2019
Copy link to clipboard 
Print this post

I don't think the function evaluates the first paramater

Do something like this
  Quote    OPTION DEFAULT INTEGER
 
PRINT Bin2Str$(uint16, 12345)
 
 a = crc(
1, 12345)
 
FUNCTION crc(p, x)
 
 crc = x *
2
 
SELECT CASE p
   
CASE 1
     
PRINT Bin2Str$(uint16, x)
   
CASE 2
     
'etc
 END SELECT
 
END FUNCTION


You only need to code for the options you are likely to use.

Jim
VK7JH
MMedit
 
Greg Fordyce
Senior Member

Joined: 16/09/2011
Location: United Kingdom
Posts: 153
Posted: 09:50am 31 Oct 2019
Copy link to clipboard 
Print this post

Thanks Jim, I hadn't thought of using the case statement, that solution will work for me. Cheers, Greg
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025