Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:32 09 Jul 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 : Newie got a few questions

     Page 8 of 25    
Author Message
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:00am 04 Sep 2016
Copy link to clipboard 
Print this post

Which values is printed by this statement?
[code]
PRINT  FieldArray$(2)
[/code]
I think it might contain a wrong value as that would be possible if none of the IF statements are executed

Microblocks. Build with logic.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:10am 04 Sep 2016
Copy link to clipboard 
Print this post

I actually made a mistake which I spotted then Jean
I had forgotten to include the statement that said what happens if the serial port has data so it was probably empty because none of the IF statements were executed as you guessed.

This is the correct code with all the bits in the right place, but now I'm back to the [quote]
N = GetFieldArray(F$)
Error: Expected a number
[/quote]

[code]Open "COM1:19200" As #1 'Open port for HC-12 TX/RX
OPEN "COM3:9200" AS #3 'Open port for ESP8266
IF LOC(#1) > 1 THEN SERIAL1
END IF
IF LOC(#3) > 1 THEN SERIAL3
END IF

SUB SERIAL3
Local F$
LOCAL N as INTEGER
LOCAL arg$
F$ = Input$(254, #3) 'Suck everything in buffer out
N = GetFieldArray(F$)
IF FieldArray$(0) = "Today" THEN T1
ELSE
IF FieldArray$(0) = "Day2" THEN T2
ELSE
IF FieldArray$(0) = "Day3" THEN T3
ELSE
IF FieldArray$(0) = "Day4" THEN T4
ELSE
IF FieldArray$(0) = "Day5" THEN T5
END IF
CLOSE #3
pause 200
OPEN "COM3:9200" AS #3 'Open port for ESP8266
End Sub

SUB T1

IF FieldArray$(2) = "01d" THEN FieldArray$(2) = "01d.ppm"
ELSE
IF FieldArray$(2) = "01n" THEN FieldArray$(2) = "01n.ppm"
ELSE
IF FieldArray$(2) = "02d" THEN FieldArray$(2) = "02d.ppm"
ELSE
IF FieldArray$(2) = "02n" THEN FieldArray$(2) = "02n.ppm"
ELSE
IF FieldArray$(2) = "03d" THEN FieldArray$(2) = "03d.ppm"
ELSE
IF FieldArray$(2) = "03n" THEN FieldArray$(2) = "03n.ppm"
ELSE
IF FieldArray$(2) = "04d" THEN FieldArray$(2) = "04d.ppm"
ELSE
IF FieldArray$(2) = "04n" THEN FieldArray$(2) = "04n.ppm"
ELSE
IF FieldArray$(2) = "09d" THEN FieldArray$(2) = "09d.ppm"
ELSE
IF FieldArray$(2) = "09n" THEN FieldArray$(2) = "09n.ppm"
ELSE
IF FieldArray$(2) = "10d" THEN FieldArray$(2) = "10d.ppm"
ELSE
IF FieldArray$(2) = "10n" THEN FieldArray$(2) = "10n.ppm"
ELSE
IF FieldArray$(2) = "11d" THEN FieldArray$(2) = "11d.ppm"
ELSE
IF FieldArray$(2) = "11n" THEN FieldArray$(2) = "11n.ppm"
ELSE
IF FieldArray$(2) = "13d" THEN FieldArray$(2) = "13d.ppm"
ELSE
IF FieldArray$(2) = "13d" THEN FieldArray$(2) = "13n.ppm"
ELSE
IF FieldArray$(2) = "13d" THEN FieldArray$(2) = "50d.ppm"
ELSE
IF FieldArray$(2) = "50d" THEN FieldArray$(2) = "50n.ppm"
END IF
PRINT FieldArray$(2)
DisplayPicture FieldArray$(2) , 392 , 185
END SUB[/code]Edited by lew247 2016-09-05
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 09:27am 04 Sep 2016
Copy link to clipboard 
Print this post

Hi
N needs to be a String
As you already have the first part of the name why not just add the exetension



SUB T1
FieldArray$(2) = FieldArray$(2) + ".ppm"
PRINT FieldArray$(2)
DisplayPicture FieldArray$(2) , 392 , 185
END SUB


Regards
Jman
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 09:42am 04 Sep 2016
Copy link to clipboard 
Print this post

@jman: If you look at Lewis' last three 'values' in the IF...ELSEIF, you will see he can't just add ".ppm" ALTHOUGH THIS MAY BE A TYPO as there are two IF...= "13d"

@Lew247 Is there a TYPO error in your above code. If so then go with man's post. Also it is more 'compact' to use SELECT CASE

Also, should it not be ELSEIF (I thought you could only have a single ELSE in a IF..THEN...ENDIIF


 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:45am 04 Sep 2016
Copy link to clipboard 
Print this post

Whoops well spotted Phil
Your correct the 3 X 13d's were typos
Not certain about the elseif or else and if on a seperate line tbh
Jman I'm about to try your suggestion

Edit just tried it [quote]N = GetFieldArray(F$)
Error: Expected a number[/quote]

Brilliant idea though, saves all those if then else statements
Thanks Edited by lew247 2016-09-05
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 09:54am 04 Sep 2016
Copy link to clipboard 
Print this post

jman's suggestion is what you need and WILL work. Your issue is with your above quote.

Can you post your all your code and we can see where/why you are getting this error. There have been errors in other peoples code too which hasn't helped but we will get you there. Post your most recent version (or email it to me if you prefer)
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:36pm 04 Sep 2016
Copy link to clipboard 
Print this post

Thanks guys
I actually found the error I'd somehow deleted the Function that parsed the string from the serial port

 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 08:46pm 04 Sep 2016
Copy link to clipboard 
Print this post

So is everything working in code properly now, and as you expect it to?
Or are you still getting error message(s) which are giving you issues?

WW
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:56pm 04 Sep 2016
Copy link to clipboard 
Print this post

Yes and NO
For some reason PRINT FieldArray$(0) is printing the LAST item sent by the serial port and not the 1st
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:06pm 04 Sep 2016
Copy link to clipboard 
Print this post

Here's the full program (so far)
Phil I "think" the one I sent you last still had a bit missing, use this one if you want to look at it, it's a direct copy from MMEdit - just remember to rem out the rtc section

I didn't include the .ppm files as they go over the 500K upload limit2016-09-05_070655_Clock.zip

The problem now is no matter what I do - PRINT FieldArray$(0) or FieldArray$(1) always prints the last item received by the com port
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 09:07pm 04 Sep 2016
Copy link to clipboard 
Print this post

Are you sure it s not actually returning the last element of the PREVIOUS message?

Is FieldArray$(1) retuning the first element, and ........ FieldArray$(x) returning the last element where x = number of elements expected?

EDIT: This is a question for your question two posts back!
Edited by WhiteWizzard 2016-09-06
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:14pm 04 Sep 2016
Copy link to clipboard 
Print this post

It seems so - but no idea how to fix it
Got to pop out now for a bit, I'll come back to it when I get home again

Edit: spotted one mistake, I had OPEN "COM3:9200" AS #3 instead of OPEN "COM3:9600" AS #3
Didn't fix the problem though Edited by lew247 2016-09-06
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 09:19pm 04 Sep 2016
Copy link to clipboard 
Print this post

I am curious/confused by the following code:
IF FieldArray$(0) = "Today" THEN T1
ELSE
IF FieldArray$(0) = "Day2" THEN T2
ELSE
IF FieldArray$(0) = "Day3" THEN T3
ELSE
IF FieldArray$(0) = "Day4" THEN T4
ELSE
IF FieldArray$(0) = "Day5" THEN T5
END IF


Your first line is a single line IF...THEN statement as you have put the 'calculation' immediately after the THEN.

But your next line is ELSE
The third line is once more a single IF..THEN


Not by a MM to try at moment but could be some issues here. Give me an hour and I will be able to try/confirm Edited by WhiteWizzard 2016-09-06
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:49pm 04 Sep 2016
Copy link to clipboard 
Print this post

Your correct with the ELSE IF being on one line, I just checked the manual
BUT I don't think it makes any difference if it's one line or 2 as the results are the same (just tried it)

What I'm trying to do is check the first field received by the serial port then depending on what that word is - selects which SUB the program jumps to

EDIT: I just tried printing FieldElement(5) and it still prints the last field....

[code]SUB SERIAL3
Local F$
LOCAL N as INTEGER
F$ = Input$(254, #3) 'Suck everything in buffer out
N = GetFieldArray(F$)
PRINT FieldArray$(5)
IF FieldArray$(0) = "Today" THEN T1
ELSE IF FieldArray$(0) = "Day2" THEN T2
ELSE IF FieldArray$(0) = "Day3" THEN T3
ELSE IF FieldArray$(0) = "Day4" THEN T4
ELSE IF FieldArray$(0) = "Day5" THEN T5
END IF
PRINT F$
CLOSE #3
pause 200
OPEN "COM3:9200" AS #3 'Open port for ESP8266
End Sub [/code]Edited by lew247 2016-09-06
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:42am 05 Sep 2016
Copy link to clipboard 
Print this post

I went back to stage 1 with the fieldarray and made it as simple as possible

the FULL code now is [code]DIM FIELDARRAY$
OPEN "COM3:9600" AS #3 'Open port for ESP8266
Do
cls
IF LOC(#3) > 0 THEN
F$ = Input$(100, #3) 'Suck everything in buffer out
N = GetFieldArray(F$)
PRINT FieldArray$(0)
PRINT F$
END IF
Loop
END

Function GetFieldArray( Record$, Delimiter$, KeepQuotes ) AS INTEGER
Local Index, Char, InQuote, Count
InQuote = 0
Count = 0
FieldArray$(Count) = ""
If Delimiter$ = "" Then Delimiter$ = ","
For Index = 1 To Len(Record$)
Char = Asc(Mid$(Record$, Index, 1))
If Char = 34 Then InQuote = Not InQuote
If Not InQuote And Instr(Delimiter$, Chr$(char)) >= 1 Then
Count = Count + 1
FieldArray$(Count) = ""
Else
If Char <> 34 Or KeepQuotes Then
FieldArray$(Count) = FieldArray$(Count) + Chr$(char)
EndIf
EndIf
Next
GetFieldArray = Count + 1
End Function [/code]

The result once I type "RUN" is

[quote]run
1
Today,shower rain,09d,16.63,1
87

016,5.7,170,87

shower
Today,shower
87

rain,09d,16.91,1016,5.7,170,87[/quote]
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 01:11am 05 Sep 2016
Copy link to clipboard 
Print this post

Lew I am pretty sure you need a Goto or Gosub after the
Else If <Exp> then Goto/Gosub and also each statement must be on a line of its own.

I am puzzled, If you are having problems with the FieldArray$ function why don't you use the function I gave you?
Codenquilts
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:59am 05 Sep 2016
Copy link to clipboard 
Print this post

The first statement is wrong
it should be:
[code]
DIM FieldArray$(20)
[/code]
Now it is just a single string instead of an array.
Also adjust the size of the array to the maximum number of fields that you can get.

Microblocks. Build with logic.
 
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 02:59am 05 Sep 2016
Copy link to clipboard 
Print this post

@ lew247
You would have to DIMension an array before you use it. Change the first line to

DIM FieldArray$(20)

Should work ok now, and populate the array. Just kept truncating the subsequent fields, onto the end of FieldArray$(0)
  lew247 said  [code]DIM FIELDARRAY$
OPEN "COM3:9600" AS #3 'Open port for ESP8266
Do
cls
IF LOC(#3) > 0 THEN
F$ = Input$(100, #3) 'Suck everything in buffer out
[/code]



MMWombat
Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
MM_Wombat
Senior Member

Joined: 12/12/2011
Location: Australia
Posts: 139
Posted: 03:00am 05 Sep 2016
Copy link to clipboard 
Print this post

@MicroBlocks

Beaten to the punch

MMWombat
Keep plugging away, it is fun learning
But can be expensive (if you keep blowing things up).

Maximite, ColourMaximite, MM+
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 03:16am 05 Sep 2016
Copy link to clipboard 
Print this post

Yeah. :)

I would also change the line
[code]
IF LOC(#3) > 0 THEN
[/code]
Because why continue when there is only a single character in the buffer
into
[code]
IF LOC(#3) > 50 THEN
[/code]
(Change the 50 into the number of characters you will at a minimum need)

Better yet as you have control about the format you send, make your life simple and use.
[code]
INPUT$ #3, Day$, Description$, Icon$, Timestamp$, Temp, etc....
[/code]
Edited by MicroBlocks 2016-09-06
Microblocks. Build with logic.
 
     Page 8 of 25    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025