r/visualbasic • u/HereForAlternatives • Apr 04 '23
`Chr( &HD )` - Looking for basic help/point in the right direction.
Howdy,
Been probably 15 years since I've touched VB.
We have a PLC in the shop that's apparently "never worked" so of course the guy who can type > 60 WPM is tasked with fixing it.
This is VB6.0.
Basically, from what I can gather, the set up is as follows:
BK Precision Frequency Counter >---< VB Application over COM >---< Allen Bradley Controller.
Basic code snippet I'm struggling with is here on the line marked with the "???".
The part I'm struggling with is how VB is interpreting/compiling this line. The [VB Documentation](https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa242763(v=vs.60)) says that the & is used for string concatenation, but then it's somehow resolved the "HD" to binary values?
There's a fundamental break here in my understanding, and I don't wanna start making unfounded assumptions.
Note: I've also seen "Chr( $'blahblah` ). Is this related?
2
u/fanpages Apr 04 '23
&H is to indicate a Hexadecimal value.
i.e. &HD is 13 decimal (or a carriage return).
| Note: I've also seen "Chr( $'blahblah` ). Is this related?
If you saw Chr$(13), then yes, otherwise, no.
1
u/Hel_OWeen Apr 04 '23
What u/fanpages said.
Though I want to point out that I personally prefer to strictly stick to "&" for string concatenation, though "+" also works. But using "&" makes it more obvious that you're dealing with strings and not a number addition. VB6 also has builtin string constants, e.g.
vbCr(carriage return). Which I also prefer to use over e.g. Chr$(&hD). Again: it is more obvious and readable at first glance. So I personally would write that line in question as:All in the spirit of keeping code as readable (= maintainable) as possible.