Post by Horizon on Jul 12, 2022 9:51:16 GMT
Hello,
I'm working on a program that extracts values from a serial device, which Just Basic is great for . The device has fixed labels within its output strings and for simplicity I've populated a couple of example strings. As we can see below the results associated with these 'labels' can vary so, utilising mid$ would probably not be the solution here.
first$ = "*START VARONE=10.7 VARTWO=56.789 VARTHREE=Quick fox VARFOUR=ABC-D VARFIVE=12 VARSIX=1 VARSEVEN=NO VAREIGHT=22.5"
second$ = "*START VARONE=12.34 VARTWO=75.23 VARTHREE=Lazy dog days VARFOUR=ABC-D2 VARFIVE=8 VARSIX=19 VARSEVEN=YES VAREIGHT=27.88"
So by using word$ we can extract string up to the next space. In this example print word$(first$, 2) would result in "VARONE=10.7". We can then create a new variable varone$ and for this we can use right$ to extract the wanted$ of value "10.7" but, this is only OK if we know its length in symbols.
If we replace first$ with second$ we would get an incorrect wanted$ value of "2.34"
When looking at VARTHREE this can be a short phrase with additional spaces so word$ may not be the best tool here resulting in:
VARTHREE=Quick from first$
or
VARTHREE=Lazy from second$
Where the next space prevents the capture of the whole phrase.
Thoughts on solutions:
Part 1 Numeric values
For the numeric values we can utilise right$ and somehow the "=" chr$(61) equals symbol to use this as a end of wanted string marker (reading from right to left), but this is where I'm struggling with the code to execute this kind of filtering.
Part 2 Phrase values (VARTHREE)
For the text values this is complicated by the spaces when they occur so word$ may not be appropriate here, perhaps the next variable label (which is a fixed value of VARFOUR=) would be useful here again reading backwards until the "=" chr$(61) symbol is encountered so that spaces are included in your wanted$. So, perhaps a method of grabbing the string between word$(first$, 4) and word$(first$, 5) would capture the whole phrase and enable easy filtering into the wanted$. Capturing the whole phrase is baking my noodle somewhat.
Any guidance on the above would be most welcome.
I'm working on a program that extracts values from a serial device, which Just Basic is great for . The device has fixed labels within its output strings and for simplicity I've populated a couple of example strings. As we can see below the results associated with these 'labels' can vary so, utilising mid$ would probably not be the solution here.
first$ = "*START VARONE=10.7 VARTWO=56.789 VARTHREE=Quick fox VARFOUR=ABC-D VARFIVE=12 VARSIX=1 VARSEVEN=NO VAREIGHT=22.5"
second$ = "*START VARONE=12.34 VARTWO=75.23 VARTHREE=Lazy dog days VARFOUR=ABC-D2 VARFIVE=8 VARSIX=19 VARSEVEN=YES VAREIGHT=27.88"
So by using word$ we can extract string up to the next space. In this example print word$(first$, 2) would result in "VARONE=10.7". We can then create a new variable varone$ and for this we can use right$ to extract the wanted$ of value "10.7" but, this is only OK if we know its length in symbols.
'Strings
first$ = "*START VARONE=10.7 VARTWO=56.789 VARTHREE=Quick fox VARFOUR=DVB-S2 VARFIVE=12 VARSIX=1 VARSEVEN=NO VAREIGHT=22.5"
second$ = "*START VARONE=12.34 VARTWO=75.23 VARTHREE=Lazy dog days VARFOUR=DVB-S2 VARFIVE=8 VARSIX=19 VARSEVEN=YES VAREIGHT=27.88"
print word$(first$, 2)
varone$ = word$(first$, 2)
wanted$ = right$(varone$, 4)
print wanted$
If we replace first$ with second$ we would get an incorrect wanted$ value of "2.34"
When looking at VARTHREE this can be a short phrase with additional spaces so word$ may not be the best tool here resulting in:
VARTHREE=Quick from first$
or
VARTHREE=Lazy from second$
Where the next space prevents the capture of the whole phrase.
Thoughts on solutions:
Part 1 Numeric values
For the numeric values we can utilise right$ and somehow the "=" chr$(61) equals symbol to use this as a end of wanted string marker (reading from right to left), but this is where I'm struggling with the code to execute this kind of filtering.
Part 2 Phrase values (VARTHREE)
For the text values this is complicated by the spaces when they occur so word$ may not be appropriate here, perhaps the next variable label (which is a fixed value of VARFOUR=) would be useful here again reading backwards until the "=" chr$(61) symbol is encountered so that spaces are included in your wanted$. So, perhaps a method of grabbing the string between word$(first$, 4) and word$(first$, 5) would capture the whole phrase and enable easy filtering into the wanted$. Capturing the whole phrase is baking my noodle somewhat.
Any guidance on the above would be most welcome.