Can Oshonsoft use 'byref' in a FUNCTION? (Plus examples of CHAR MATCHING CODE)

camerart

Well-Known Member
Hi,
Here is a PROCEDURE from one of my programs:
'These extract characters from the raw RX buffer array to OSH string types
===================================
'AddChar: adds passed character to passed string at
'passed StrIx. Terminates result with 0 to keep it a string
Proc Addchar(ByRef str As String, ByRef StrIX As Byte, char As Byte)
str(StrIX) = char
StrIX = StrIX + 1
str(StrIX) = 0
End Proc
===================================
it uses 'byref'

I would like to know if 'byref' can also be used in an Oshonsoft FUNCTION please?
Camerart
 
Hi D,
I notice that your CODE uses POINTER, but the OSH 18 series hasn't got them yet.
My mate will check your CODE along with the earlier version, and choose what to do.
Thanks. C.
 
Can save memory by setting the length of the variables. But you have to keep in mind that you cannot assign a longer variable to a shorter one. The system will not give you an error but the program will not work properly. You have to assign it using "LeftStr" to adapt the lengths.

'***********************************************************************
'Funciones String
'Pic18F26k22, OshonSoft Pic18 Basic Compiler v5.32
'***********************************************************************
#define STRING_MAX_LENGTH = 75
UART1_Init 115200
main:
Dim String0 As String 'Maximum length established with the directive.
Dim String1[6] As String 'Length set by user.
Dim String2[6] As String
Dim String3[6] As String

String0 = "$GNRMC,000000.00,A,3723.02837,N,00150.39853,W,0.820,188.36,110706,,,A*74"

'Copy of a higher variable to a lower variable must be limited to the length of the lower variable.
String1 = LeftStr(String0, 6)
String2 = "GNRMC"

If match(String1, 1, String2) = 1 Then
UART_Write "Ok", CrLf
Else
UART_Write "No match", CrLf
Endif

End
'The corresponding match function (IDE Pic18 v5.32).
Function match(input_str[6] As String, str_ix As Byte, match_str[5] As String) As Byte 'variable names can be changes
Dim position_counter As Byte
Dim shortposition As Byte
position_counter = str_ix
shortposition = 0
While match_str(shortposition) > 0
If input_str(position_counter) = match_str(shortposition) Then
ReturnValue 1 'set the match indicator to valid
shortposition++ 'increment the short string position counter
Else
ReturnValue 0 'set the match indicator To Not valid
Exit 'jump out of the function
Endif
position_counter++
Wend
End Function 'the corresponding match function
 
Last edited:
Hi D,
Thanks for that.
Since #74, I updated Oshonsoft, and it looks like POINTERS have been added.
I'll send this to my mate who's doing the MATCH, while I carry on with the main programs, without MATCH. He will be busy for a while thought.
I think some of the CODE is in C or something, as I'm, not sure if Oshonsoft does '++' or [] type brckets?
C
 
Yes, many of the abbreviations used in C have been added to the Ide. I imagine that Ide users have requested it. It doesn't particularly bother me, in fact once you get used to it they have many advantages.
 
Yes, many of the abbreviations used in C have been added to the Ide. I imagine that Ide users have requested it. It doesn't particularly bother me, in fact once you get used to it they have many advantages.
Hi D,
I leant what '++' means earlier today.
Waht's the difference between () and []?
Actually, I'm not good at changes, as much of this project programs, were written for me with new bits in that I have to get used to, and why I stay with BASIC.
C
 
Applying it particularly to the declaration of arrays, with () is used to indicate the number of elements of a numeric array, and [] are used to declare the number of elements of a string array.

For example:
Dim sum(10) as byte '(Word and Long) Declares an array of 10 elements and each element has a length of 1Byte, the elements are named from 0 to 9 (index).
Accessing the first element of the array:
sum(0) = 20

Dim char[20] as string 'Declares an array of type string that will contain Ascii characters, with a length of 20 elements and each element with a length of one byte. There are a series of special functions to work with strings. You can also access each element of the string by treating it as if it were a normal array.
For example:
char(0) = "A"
 
Last edited:
Hi D,
Interesting! Recently, an array of BYTES, was changed to an array of CHARS in some CODE.
Trouble is, that I simply don't remember, I have to save mini sections of CODE, that I look up and kept in a folder.
If I use some CODE for a while, 'say' months, I do get used to it.
Cheers, c.
 
Sometimes by reading the manual we can find simpler ways to do something.

Match version:

#define STRING_MAX_LENGTH = 75
UART_Init 4800
Dim string1 As String
Dim string2[5] As String
Dim String3[5] As String

string1 = "!AIVDM,1,1,,B,4028jJivO;AJPOhKSNE4QQgP2<3j,0*5B"
string2 = MidStr(string1, 2, 5)
String3 = "AIVDM"

If String3 = string2 Then
UART_Write "Ok", CrLf
Else
UART_Write "No Match", CrLf
Endif

If string3 = MidStr(string1, 2, 5) Then
UART_Write "Ok", CrLf
Else
UART_Write "No Match", CrLf
Endif

While True
Wend

End
 
Hi D,
Well, on first sight that looks creative, I don't think you'll beat this one
Thanks.
C
 
Hi D,
At the moment I'm working on Shift registers and PWM, but when I come back to this thread, I'll see your note.
Thanks for the update!
C
Now yes, with the new update when "By Ref" is used to pass an argument or data type string by reference it does work as a pointer, if you want to use it with string and work with the individual elements of the string you have no choice but to learn how use pointers.
 
Hi D,
Ok, thanks.
Before POINTERS was implemented, I carried on adding the shift register SERVO control, and it's now working without them.
I tried to learn POINTERS, and almost got it, but then moved on.
C.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…