Author Topic: Code Reference  (Read 322 times)

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Code Reference
« on: June 26, 2016, 11:08:45 am »
I will be the first to admit that I am inexperienced at coding. I can usually work my through things by referencing documentation on the functions available and their syntax or else finding code examples. I have read the scripting guide for the mcThings and have now got an idea of some of the functions. Is there any way of digging into how those functions work in mcStudio as far as variables etc? I know Ctrl + Space can give you a bit of a hint but doesn't really answer your questions. At the moment I am trying to truncate the temperature reading to 1 decimal place and am struggling to with the few functions that are implemented. A float has a lot of decimal places and if I convert to a string they come with. The trim functions won't do the job because as far as I can tell they will trim from a character array not a character index position. I tried the string format option and couldn't get that to output what I expected. That gave me some odd answer. Anyhow I will solve this issue but would love to see some reference material in addition to the mcScript guide.

Have tried a few different format options each one resulting in a different behaviour to expected and each resulting in the same format being something like ######.##### instead of ##.#
It also looks like ceil and floor are not implemented functions in regards to working with floats. On this I could be wrong as it mentions them in the mcScript guide.
« Last Edit: June 26, 2016, 11:39:00 am by plains203 »
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

Share on Facebook Share on Twitter


mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Code Reference
« Reply #1 on: June 26, 2016, 11:37:08 am »
First this is the code to make a float with one decimal place.
Code: [Select]
        Dim f As Float = 12.123
        f = (f * 10).ToInteger() / 10

Your question about reference documentation is a valid one but it hasn't been written yet because it is lower on the priority list and we have found that most documentation is ignored by the users. It is great that you read the user guide and it will help you a lot. Also if you have a question how to code a certain problem just google it and include VB.NET. mcScript is a subset of VB.NET and most of the problems are solved the same way. And you can always ask this forum.

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Code Reference
« Reply #2 on: June 26, 2016, 11:43:09 am »
Thanks for your response. I will try that out. I can see how that should work for me. I understand everything is a work in progress so I guess I will keep fumbling through. I have tried adapting VB.Net examples but find that a lot of the things I have tried with this issue are not implemented in mcStudio. I will get better over time at solving these issues as I learn more.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Code Reference
« Reply #3 on: June 26, 2016, 11:49:44 am »
That gives me a 26.50000 response but I should now be able to use the trim function to drop my zeros.
Thanks.

Found the substring function and was able to achieve what I wanted with that. The trim function didn't work as it does in other languages but the substring does so now I will be able to make a fancier chunk of code around substring and determine where the decimal is and if it is a negative number etc and make my 1decimal point temperature a thing.
« Last Edit: June 26, 2016, 12:01:45 pm by plains203 »
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894