Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

problem with string / function

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
snipsnip

Bascom Member



Joined: 10 Feb 2014
Posts: 74
Location: Melbourne

australia.gif
PostPosted: Thu Feb 26, 2015 6:49 am    Post subject: problem with string / function Reply with quote

Hi all,
I've got a problem with a function that returns a string of 21 characters. Works ok with 20 characters.
For some reason when the string is 21 chrs long an extra (null) "thingy" is added to it which prints out as a white square after the actual string.

I thought it was a problem with the GLCD library (ssd1289), but no, it works ok when I give it a 21+ chr variable in the main loop (global)

I've disabled all other functions - in case it was an external problem, but still the same
I've commented out all code in the function below, but still the same - nothing to do with the contained code in the function.
Trimming the string makes no difference either?

Got me stuffed, Any ideas?

cheers


Code:

, Declare Function Timestamp(byval Timezone As Word , Byval Plusneg As Byte) As String * 23  
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Function Timestamp(timezone As Word , Plusneg As Byte)as String
'Local X As Byte
'Local Timez As String * 8 : Local Datez As String * 8 : Local Dayz As String * 4
'Local Tmp As String * 2 : Local Tmp1 As String * 2 : Local Tmp2 As String * 2 : Local Tmp3 As String * 23
'Local Sissec As Long

' Timez = Commapos(1 , "GPRMC")
' Timez = Left(timez , 6)
'  Tmp = Left(timez , 2)
'  Tmp1 = Mid(timez , 3 , 2)
'  Tmp2 = Right(timez , 2)
'  Timez = Tmp + ":" + Tmp1 + ":" + Tmp2

' Datez = Commapos(9 , "GPRMC")
'  Datez = Left(datez , 6)
'  Tmp = Left(datez , 2)
'  Tmp1 = Mid(datez , 3 , 2)
'  Tmp2 = Right(datez , 2)
' Datez = Tmp + "/" + Tmp1 + "/" + Tmp2

' Sissec = Syssec(timez , Datez)
' Timezone = Timezone * 3600
' If Plusneg = 0 Then Sissec = Sissec - Timezone
' If Plusneg = 1 Then Sissec = Sissec + Timezone

'   Datez = Date(sissec)
'   Timez = Time(sissec)
'    X = Dayofweek(sissec)

'Dayz = Lookupstr(x , Weekdays)
'Timestamp = Dayz + Timez + " " + Datez
 Timestamp = "123456789012345678901"
 End Function
 


(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5916
Location: Holland

blank.gif
PostPosted: Thu Feb 26, 2015 9:45 am    Post subject: Reply with quote

Best to show a complete sample : include $regfile, $hwstack,$swstack and $framesize. And how it is used.
But my guess :
- check if the string you assign it to is long enough to hold that result.
- check if $framesize is big enough to hold a temp string (depends on how you use the function)
In any case, it works for me.

_________________
Mark
Back to top
View user's profile Visit poster's website
snipsnip

Bascom Member



Joined: 10 Feb 2014
Posts: 74
Location: Melbourne

australia.gif
PostPosted: Thu Feb 26, 2015 10:04 am    Post subject: Reply with quote

Thanks,
Yep My bad Had a temp variable too small to accept the return. Embarassed

I seriously spent MANY MANY hours checking the program, I knew to look for this problem as the #1 culprit.
and its not like its a massive / complex beast of a program.


Think I might have lysdexia.


Cheers.
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri Feb 27, 2015 10:49 am    Post subject: Reply with quote

this forum is a friendly corner, and when you spend to much time when you turn crazy it is the place to ask help of the friends

I did it , I do it, and I will do it again !
Wink
jp
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum