Assigning port syntax

Could someone give me the correct syntax for assigning a port to the serial connection?

Var i As Integer
Var PortName as string

For i = 0 To System.SerialPortCount-1
if System.SerialPort(i).Name = “usbserial-A50285BI” then
CurrentPort = i 'Global Property
PortName = System.SerialPort(i).Name
end
Next
'Messagebox Str(currentport)
MainWindow.MainWindowSerial.device = SerialDevice.???

SerialDevice.At(someindex)

See here:
https://documentation.xojo.com/api/hardware/serialdevice.html

Thanks, Derk, I think I had it working but didn’t realize it was talking. I find some of these commands a lot more confusing to follow then the RB4.5 days. If they are trying to make XOJO easy for the average person they are going the wrong direction. Just my opinion.

1 Like

No thanks, if it helps you it could help others too.
you’ll have to get used to this… trust me.
Try following the release notes it brings alot of usefull knowledge with you to be prepared.

I’m sure there is a good reason for these changes. I’m just not there yet and I would not want to be a first time user.

It’s things like this that drive me nut:
RestartTimer.runmode = timer.runModes.Single

Compaired to something simple to follow in RB 4.5
RestartTimer.mode = single

yeah but reading is more clear.

Help me with that thought. I’m open to understanding but need to follow where your coming from. Remember I’m the person walking off the street wanting to learn how to program with XOJO.

for example arrays have .LastRowIndex and .FirstRowIndex
if you use those in loops, you instantly see what it’s doing.

Can you breakdown the timer example so it makes more sense to me?

RestartTimer.runmode = timer.runModes.Single

Nope sorry. this just shows you how it could be made hard to find the right thing but enums enforce values (compile time) so you can’t assign the wrong value.

Say it used to be an integer:

Timer.Mode = 1

You could do

Timer.Mode = 999

And it would compile but give you an exception at runtime. With enums you won’t have that, you’ll get a compile time error and fix it before it’s shipped with the wrong value.

The length of this line is long, i know but it’s readable and causes less (runtime) errors.
That’s about all i can say for this line.

What does the term enums mean?

https://documentation.xojo.com/api/data_types/enumeration.html
Enumeration (It’s an integer -in xojo- that has compiler enforced values)
see the docs.

Enumeration.

A list of names corresponding to valid values. And it’s all very well saying how wonderful ‘single’ used to be, but what do you do if ‘single’ were needed in another context. It’s already a data type, although that might be resolvable by context.

So in this case is runModes the EnumName and Single the EnumValue?

Yup :+1:

Thanks, I learn something. Better when you gurus think like teachers rather then programmers. It helps the underprivileged like us. :rofl:

1 Like