Jump to content
JOYE

String to Num

Recommended Posts

By the way, the answer to your question, @JOYE, is that FACTOR is how you deal with the decimal placement since you are converting the string representation to an integer. If the string looks like this: "123.45", then you would use a factor of 100 to result in an integer value of 12345. You can then display this integer number on the HMI screen and identify where to place the decimal. If you use the number in calculations, you would need to account for the fact that the number has been multiplied by 100 and deal with that properly.

Share this post


Link to post
Share on other sites

I had a crash course in UniLogic string to num conversions (formatting/handling). You have to remove leading spaces and trailing non numeric characters if I recall correctly. The Visilogic string to num FB is more flexible as to what it will convert. If your ASCII string is purely numeric characters you should be Okay. If you need a subroutine to strip off other characters let me know. I could share a snippet of code I used. 

  • Upvote 1

Share this post


Link to post
Share on other sites
On 16/2/2019 at 10:36, hotwires said:

Tuve un curso intensivo en la cadena UniLogic para numear las conversiones (formateo / manejo). Tienes que eliminar los espacios iniciales y los caracteres no numéricos finales si recuerdo correctamente. La cadena de Visilogic a num FB es más flexible en cuanto a lo que convertirá. Si su cadena ASCII tiene caracteres puramente numéricos, debería estar bien. Si necesita una subrutina para quitar otros caracteres, hágamelo saber. Podría compartir un fragmento de código que utilicé. 

Could you help me? I need to convert a string into a number. My string has a decimal point, for example, "34.123" and sign "-" when the reading is negative 

Share this post


Link to post
Share on other sites

If you are still needing help, I'll look through my files and see if I can post a snippet (photo) of the logic I used to convert ASCII string from a gram scale to an integer for comparison to a tolerance (window) and give an output if weighed part is "bad". Back when I worked on this the help section was sparse and (even though I would consider myself an intermediate programmer ((on a scale of: novice, intermediate, advanced, and expert)) it took me a considerable amount of time to reach an efficient solution. See photo below for a start. The - sign will need a little addition logic. Let me know if you need help with that part.

SnippetPLC.JPG

  • Upvote 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...