我想用下面的代码在Bascom中用比较功能比较两个字符串:
Dim Str1 As String * 10 , Str2 As String * 10
Dim Wnofb As Word , Res As Word
Str1 = "jack"
Str2 = "john"
Wnofb = Len(str1)
Res = Compare(Str1 , Str2 , Wnofb)
但是下面有一个错误:
错误:242“源变量与目标变量[0 | COMPARE(Str1,Str2,WNOFB)]不匹配”]
在最后一行。
您必须在编写函数或调用函数之前声明每个函数功能。并且声明必须与函数匹配。位是全局,不能传递给函数或子。
https://wiki.mcselec.com/bavr/DECLARE_FUNCTION
这是我的做法。您可以简单地在Bascom Simulator中测试示例。我不知道你为什么需要Len(...?
'-------------------------------------------------------------------------------
$sim
$regfile = "m8def.dat"
$crystal = 11059200
$baud = 9600
$hwstack = 64
$swstack = 0
$framesize = 64
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
Dim Str1 As String * 10 : Str1 = "jack"
Dim Str2 As String * 10 : Str2 = "john"
Dim Res As Byte
Declare Function Compare_ss(str1 As String , Str2 As String ) As Byte
Dim Temp As Byte
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
Wait 1
Print "---------------------------"
Print "Hello You"
Print "Str1= " ; Str1
Print "Str2= " ; Str2
Temp = Compare_ss(str1 , Str2 )
Print "Compare Result is: " ; Temp
Print "---------------------------"
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'*******************************************************************************
'*******************************************************************************
'*******************************************************************************
'-------------------------------------------------------------------------------
Do
Print "---------------------------"
Input "Enter your name: " , Str1
Input "Enter any name: " , Str2
Temp = Compare_ss(str1 , Str2 )
Print "Compare Result is: " ; Temp
Print "---------------------------"
Loop
'-------------------------------------------------------------------------------
'*******************************************************************************
'*******************************************************************************
'*******************************************************************************
'-------------------------------------------------------------------------------
Function Compare_ss(str1 As String , Str2 As String) As Byte
If Str1 = Str2 Then Res = 1 Else Res = 0
Compare_ss = Res
End Function