This is the final code that has resolved the problem. I’ve used the InStr and Mid functions:
[code] Dim modelNumber As String
If Serial1.Open Then
modelNumber = Trim(Serial1.ReadAll(encodings.ASCII))
End If
Dim location As Integer
location = InStr(1, modelNumber, “SRS”)
If location <> 0 Then // It’s a valid SRS Device
SRSvalidModel = True
modelNumber = Mid(modelNumber, location, location + 13)
deviceName = modelNumber
btnConnect.Caption = deviceName // display the device/model number
Else
SRSvalidModel = False
modelNumber = “GENERIC”
deviceName = modelNumber
btnConnect.Caption = deviceName //display the device/model number
End If
PreferencesWRITE[/code]
This works perfectly to what I need. There’s always more than way to remove the dermal tissue from a feline - my apologies to cat lovers
An important thing to mention, which threw me out for a bit, was the “location” number (ie. the beginning of where “SRS” was located). Looking at the example below, you could be forgiven for thinking that the location is 6. Well, no it’s not, It’s 12.
The reason is that there are line feeds/carriage returns that take up 2 characters.
1
-0
-2
SRS40KG080
Anyway, in my case it was more important to have the conditional construct working, than how I got there. I know my programming style is very verbose, but it’s important to me that I can can come back to this code later and understand what it means.
RegEx is overkill with this situation. With another application where I have to change things with a whole pile of text, then yes, sure, i’d be looking into RegEx.
I’ve settled on 13 characters as the fixed number for the model number (eg. SRSX040KG0080). I’m building the hardware device, therefore I can decide and make the rules.
@Kem
If you have the time, It may be worthwhile for me and others to take my above final code and make it more concise in any way you like - rip it to shreds. I’m not saying that I’m going to use it now, but definitely worth knowing about for future apps.
@Markus
No no no, on the contraire Markus.
It’s like saying “I AM good at using Xojo, but I don’t understand the finer points”. That doesn’t stop me from using Xojo. I just need to learn more. When It suits me