Hello Guest it is April 19, 2024, 01:57:38 PM

Author Topic: Doing something wrong  (Read 2122 times)

0 Members and 1 Guest are viewing this topic.

Doing something wrong
« on: January 25, 2016, 11:21:17 PM »
I have the following attached to a button...code seems like it should work, i created two dros, OEM1300 and OEM1302, get a data type mismatch. When I step thru with the debugger, I am getting the correct values into XPos and YPos...can't figure what I am doing wrong..

Sub Main
   XPos=GetOEMDRO(1300)
   YPos=GetOEMDRO(1302)

      Code "G0 X" + XPos + "Y" + YPos
 

End Sub

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Doing something wrong
« Reply #1 on: January 25, 2016, 11:30:09 PM »
Try this

Code "G0 X" & XPos & "Y" & YPos
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Doing something wrong
« Reply #2 on: January 26, 2016, 05:06:41 AM »
Ah the stupid overloading of the + op in VB and the like.

Here's the official word from MS

Quote
Differences Between the Two Concatenation Operators

The + Operator (Visual Basic) has the primary purpose of adding two numbers. However, it can also concatenate numeric operands with string operands. The + operator has a complex set of rules that determine whether to add, concatenate, signal a compiler error, or throw a run-time InvalidCastException exception.

The & Operator (Visual Basic) is defined only for String operands, and it always widens its operands to String, regardless of the setting of Option Strict. The & operator is recommended for string concatenation because it is defined exclusively for strings and reduces your chances of generating an unintended conversion.

Here's what that actually means:

Look - we screwed up - ok?. We made TWO concat operators because we're dumb. Worse we made one that works always and one that sometimes doesn't. Just use the & ok.
Re: Doing something wrong
« Reply #3 on: January 26, 2016, 06:55:26 AM »
Thanks! I should have known that from my previous programming experience!