Hello, i'm Theo and i am using GC Basic now for a few months.
It's a great program and i would like to say thanks to all the people involved in developing and testing.
But now I have a small problem. Printing stringarray's goes wrong, the output is not as expected; the output is a number.
See listing:
A nice posting as you told us your versions. A great help. :-)
Let me try to help.
String definition is correct - 'dim test as string'. This creates a string. A string is typically 16 bytes long. To make shorter or longer use 'dim test as string * 2' or 'dim test as string * 32' are examples not the * n where n is the length of the string.
You assignment of values to a string needs to be changed. You are not using the string correctly. A string is essentially a type of array and you are addressing the elements of the string array but not using a valid method.
To assign a string, use
test = "AB"
To assign a specific character to a specific position in the string, use the ASCII value (two examples below, write to a specific position in the string the values shown).
test(1) = 65
test(2) = 98
So, if you want to test two strings you need to use two string definitions.
As Hugh would say 'that's not right'. We need to sort the root cause of the issue as the most simplest of program has the same error.
A workaround add this code to your program in the meanwhile.
#define mid midd
Function Midd(SysInString(), SysCharStart, Optional SysCharCount = 255) As String
'Empty input?
If SysInString(0) = 0 Then
Midd(0) = 0
Exit Function
End If
'Starting position too low?
If SysCharStart < 1 Then SysCharStart = 1
'Starting position too high?
If SysCharStart > SysInString(0) Then
Midd(0) = 0
Exit Function
End If
'Input length too high?
SysCharStart -= 1
SysStringTemp = SysInString(0) - SysCharStart 'Max number of characters
If SysCharCount > SysStringTemp Then
SysCharCount = SysStringTemp
End If
'Copy characters
For SysStringTemp = 1 To SysCharCount
Midd(SysStringTemp) = SysInString(SysCharStart + SysStringTemp)
Next
Midd(0) = SysCharCount
End Function
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, i'm Theo and i am using GC Basic now for a few months.
It's a great program and i would like to say thanks to all the people involved in developing and testing.
But now I have a small problem. Printing stringarray's goes wrong, the output is not as expected; the output is a number.
See listing:
;-------------------------------------------------
chip mega8,8
'Use LCD in 4 pin mode and define LCD pins
define LCD_IO 4
define LCD_DB4 PORTD.0 ; 11
define LCD_DB5 PORTD.1 ; 12
define LCD_DB6 PORTD.2 ; 13
define LCD_DB7 PORTD.3 ; 14
define LCD_RS PORTD.4 ; 4
define LCD_Enable PORTD.5 ; 6
define LCD_NO_RW
lcdcmd 1
wait 1 s
dim test as string
test(1) = "ab"
test(2) = "ab"
if test(1) = test(2) then
locate 0,0
print "Equal."
end if
locate 1,0
print test(1)
print " "
print test(2)
;--------------------------------------------
GCBasic version (0.9 11/5/2014)
lcd.h 08-17-2014, but also with older versions.
Is this a bug or am I doing something wrong?
Kind regards.
Welcome.
A nice posting as you told us your versions. A great help. :-)
Let me try to help.
String definition is correct - 'dim test as string'. This creates a string. A string is typically 16 bytes long. To make shorter or longer use 'dim test as string * 2' or 'dim test as string * 32' are examples not the * n where n is the length of the string.
You assignment of values to a string needs to be changed. You are not using the string correctly. A string is essentially a type of array and you are addressing the elements of the string array but not using a valid method.
To assign a string, use
test = "AB"
To assign a specific character to a specific position in the string, use the ASCII value (two examples below, write to a specific position in the string the values shown).
test(1) = 65
test(2) = 98
So, if you want to test two strings you need to use two string definitions.
Hope this helps.
Thank you for your support Anobium.
I was trying to create some shorter code by changing your program: DS1307 with LCD demonstration.
sub printDate
select case DOW
etc
into something like this:
weekday(1) = "Su"
weekday(2) = "Mo"
etc
sub printDate
print weekDay(DOW)
print ". "
It's clear to me now that string handling in GCbasic differs from other programming languages.
So I started with a new approach
Dim weekday as string * 15
weekday = "SuMoTuWeThFrSa"
Sub printDate
print mid(weekday,DOW,2)
print ". "
But using mid(or left/right) wasn't a success because the compiler started looping.
Maybe you can help me again.
Kind regards.
May I ask that you post your complete code? I need to see the complete code.
Thank you.
The program I am using is your program: DS1307 with LCD Demonstration.gcb
These 2 lines, added by
;----- Variables
dim weekday as string * 15
weekday = "SuMoTuWeThFrSa"
and these 2 lines and changes by
sub printDate
Started compiling; after 3 minutes this message.
20:55:34 G@Stool-COMPILE/ASSEMBLE, processing D:\GCB@Syn\G@Stools\makeHEX.bat
Source-File = D:\GCB@Syn_Demos\DS1307\DS1307 with LCD Demonstration.gcb
Aborting due to runtime error 12 ("segmentation violation" signal) in gcbasic.bas::MESSAGE()
176.0 Sec. <<< WARNINGs / ERRORs while compiling!
As Hugh would say 'that's not right'. We need to sort the root cause of the issue as the most simplest of program has the same error.
A workaround add this code to your program in the meanwhile.
Thanks for your fast response, compiling worked.
This will be fixed in the next release, so, please replace this workaround when you see the next release.