NilObjectException on Regex

My UDP Receive Data Available action, I am doing this:

[code]
Dim d As DataGram
Dim length as integer
Dim rg as RegEx
Dim MyMatch as RegExMatch

d = UDPReceive.Read

if App.UDPRxEnabled = False then
return
end if

'Make Sure we have a valid packet, If so copy the matched data without the brackets.
rg.SearchPattern = “\[(.*?)\]”
myMatch = rg.Search(d.data)
If myMatch <> Nil Then
stdout.writeline(App.UDPRxPacket)
App.UDPRxPacket = myMatch.SubExpressionString(1)
App.UDPPacketReceived = true
End If[/code]

Problem is, I keep getting the Exception of class NilObjectException.

It expects to receive strings like this: [0;1;2100;19;11;3;0;1;1;25;3;10;5;25;0]

But it will dump anything that is missing the brackets, and if it DOES have the brackets, it should return this: 0;1;2100;19;11;3;0;1;1;25;3;10;5;25;0

Well… when it works properly, its supposed to. Any thoughts?

[code]Dim rg as RegEx

[…]

rg.SearchPattern = “\[(.*?)\]” <— NilObjectException because rg=Nil
[/code]

RegEx is an object type, which means you must instantiate it with the New keyword before you try to reference its properties or invoke its methods. Until/unless you do this the rg variable will have the default value of all objects, which is Nil. Hence the NilObjectException when you try to reference the SearchPattern property:

Dim rg as NEW RegEx

Or

Dim rg as RegEx rg = NEW RegEx

Thanks. its hard to get used to that “new” thing since none of my other languages I currently use on a daily basis have that method.

So its strange to me so I always forget it.

what do you use on a daily basis ?

It’s necessary for OOP features, such as inheritance and polymorphism, which prevent the compiler from knowing ahead of time how much memory an instance will occupy. This is in contrast to primitive types like Integers and String literals, whose size in memory is known in advance and never changes.

I used to use VB6, but now I use Basic4Android, and Basic4Java, I dabbled in RealBASIC back in the old PowerPC Mac days, and it was VERY unstable crashing alot with Type 2 and Type 3 errors, so I never looked at it again until recently. I also use BASCOM-AVR for writing firmware for 8-bit AVR ICs, but all the memory management is handled by the programmer since there is no underlying OS. That gets real fun sometimes.

I just very recently started to dabble into the Raspberry Pi, and Beaglebone stuff. I only wrote a couple small things, and it was in B4J which worked fine for the application I dedicated a Pi to, which is controlling my front door access against a SQL database on my server. I also do a bit of PHP here and there, but the old Procedural style. the newer syntax with all these arrows pointed every which way might as well be japanese to me.

To be completely honest, I am a hardware engineer, alot more so than I am a software guy. I know just enough programming to perform the specific task I need to do with the hardware I develop, and that’s about it. My niche is control systems. Such as controllers for ovens, sequencers, etc… I do alot of that. The craziest thing I done was designed a control board, and wrote code to run a commercial ice machine when the mechanical timer and sequencer went bad. but my day job is static scoreboards controlled from mobile devices.