# Assigning port syntax

**URL:** <https://forum.xojo.com/t/assigning-port-syntax/56742>\
**Category:** Getting Started\
**Created:** [September 5, 2020, 4:30pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742 "2020-09-05T16:30:09Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clifford\_Coulter](https://forum.xojo.com/user_avatar/forum.xojo.com/clifford_coulter/32/711_2.png) [@Clifford\_Coulter](https://forum.xojo.com/u/Clifford_Coulter)\
**Post date:** [September 5, 2020, 4:30pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/1 "2020-09-05T16:30:09Z")

</div>

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.???

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [September 5, 2020, 5:27pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/2 "2020-09-05T17:27:54Z")

</div>

SerialDevice.At(someindex)

See here:  
[https://documentation.xojo.com/api/hardware/serialdevice.html](https://documentation.xojo.com/api/hardware/serialdevice.html)

---

<div class="post-metadata">

**Author:** ![Clifford\_Coulter](https://forum.xojo.com/user_avatar/forum.xojo.com/clifford_coulter/32/711_2.png) [@Clifford\_Coulter](https://forum.xojo.com/u/Clifford_Coulter)\
**Post date:** [September 5, 2020, 6:51pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/3 "2020-09-05T18:51:50Z")

</div>

> [@DerkJ](#):
>
> At(someindex)

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.

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [September 5, 2020, 6:53pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/4 "2020-09-05T18:53:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Clifford\_Coulter](https://forum.xojo.com/user_avatar/forum.xojo.com/clifford_coulter/32/711_2.png) [@Clifford\_Coulter](https://forum.xojo.com/u/Clifford_Coulter)\
**Post date:** [September 5, 2020, 6:57pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/5 "2020-09-05T18:57:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [September 5, 2020, 7:43pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/6 "2020-09-05T19:43:15Z")

</div>

yeah but reading is more clear.

---

<div class="post-metadata">

**Author:** ![Clifford\_Coulter](https://forum.xojo.com/user_avatar/forum.xojo.com/clifford_coulter/32/711_2.png) [@Clifford\_Coulter](https://forum.xojo.com/u/Clifford_Coulter)\
**Post date:** [September 5, 2020, 7:47pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/7 "2020-09-05T19:47:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [September 5, 2020, 8:07pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/8 "2020-09-05T20:07:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Clifford\_Coulter](https://forum.xojo.com/user_avatar/forum.xojo.com/clifford_coulter/32/711_2.png) [@Clifford\_Coulter](https://forum.xojo.com/u/Clifford_Coulter)\
**Post date:** [September 5, 2020, 8:11pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/9 "2020-09-05T20:11:45Z")

</div>

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

RestartTimer.runmode = timer.runModes.Single

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [September 5, 2020, 8:16pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/10 "2020-09-05T20:16:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Clifford\_Coulter](https://forum.xojo.com/user_avatar/forum.xojo.com/clifford_coulter/32/711_2.png) [@Clifford\_Coulter](https://forum.xojo.com/u/Clifford_Coulter)\
**Post date:** [September 5, 2020, 8:19pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/11 "2020-09-05T20:19:39Z")

</div>

> [@DerkJ](#):
>
> enums

What does the term enums mean?

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [September 5, 2020, 8:21pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/12 "2020-09-05T20:21:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [September 5, 2020, 8:23pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/13 "2020-09-05T20:23:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Clifford\_Coulter](https://forum.xojo.com/user_avatar/forum.xojo.com/clifford_coulter/32/711_2.png) [@Clifford\_Coulter](https://forum.xojo.com/u/Clifford_Coulter)\
**Post date:** [September 5, 2020, 8:41pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/14 "2020-09-05T20:41:06Z")

</div>

> [@Clifford\_Coulter](#):
>
> runModes.Single

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

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [September 5, 2020, 9:14pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/15 "2020-09-05T21:14:02Z")

</div>

Yup 👍

---

<div class="post-metadata">

**Author:** ![Clifford\_Coulter](https://forum.xojo.com/user_avatar/forum.xojo.com/clifford_coulter/32/711_2.png) [@Clifford\_Coulter](https://forum.xojo.com/u/Clifford_Coulter)\
**Post date:** [September 5, 2020, 9:18pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/16 "2020-09-05T21:18:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:39pm UTC](https://forum.xojo.com/t/assigning-port-syntax/56742/17 "2021-04-29T16:39:59Z")

</div>


