PopupMenu.AddRow and concatenated string

Good afternoon (o;

When I use this for adding a row on a popup menu:

USBMenu.AddRow("BATTLAB-ONE 403:6001")

the result is as expected:

Bildschirmfoto 2022-04-06 um 15.47.05

But when using with a concatenated string the whole string is only displayed when the popup menu is selected.

s = s.Trim + " " + Hex(desc.VendorID) + ":" + Hex(desc.ProductID)
USBMenu.AddRow(s)

Unselected:

Bildschirmfoto 2022-04-06 um 15.49.38

And when the popup menu is selected the whole string is displayed:

Bildschirmfoto 2022-04-06 um 15.49.45

But if I use for example:

s = "BATTLAB-ONE" + " " + Hex(desc.VendorID) + ":" + Hex(desc.ProductID)
USBMenu.AddRow(s)

Then it is as expected as well…so somehow String s causes this…

Whole snippet:

if device.IsOpen then
  dim s as string = device.GetStringDescriptor(desc.IndexProduct, 0)
  if s <> "" then
    s = s.Trim + " " + Hex(desc.VendorID) + ":" + Hex(desc.ProductID)
    USBMenu.AddRow(s)
  else
    s = device.GetStringDescriptorAscii(desc.IndexProduct)
    s = s.Trim + " " + Hex(desc.ProductID) + "/" + Hex(desc.VendorID)
    USBMenu.AddRow(s)
  end if
  
  USBMenu.RowTagAt(c) = device
  c = c + 1
  
  device.Close
end if

Check what S contains in the debugger (hex view)… does it end in a tab character or anything with an ASCII value of less than 32?

1 Like

I tested this code and behaves the same as you describe:

dim s as string
s = "BATTLAB-ONE" + EndOfLine + " " + "403:6001"
me.AddRow(s)
me.SelectedRowIndex = 0

image

image

Hope this helps.

Hmmm…shouldn’t s.Trim get rid of EOL or is this on php only?

I guess PHP only. You need to do

s = s.Trim.ReplaceLineEndings("")

or something like that.

@Richard_Klingler Which version(s) does the issue occur ?

That’s with 2021r3.1 and 2022r1 on macOS 12.3.1…

Couldn’t test on Linux as I didn’t figure out how to load the USB plugin…example only shows Win/macOS…but that’s MBS…no real documentation :wink:

The hex string is probably nil encoded
put it in a variable, convertEncoding or defineEncoding and it may work.

Nope…not the Hex string…but the string returned from the MBS USB plugin…

This works now:

dim s as string = device.GetStringDescriptor(desc.IndexProduct, 0)
if s <> "" then
  s = s.ReplaceAll(chr(0), "") + " " + Hex(desc.VendorID) + ":" + Hex(desc.ProductID)
  USBMenu.AddRow(s)
else
  s = device.GetStringDescriptorAscii(desc.IndexProduct)
  s = s.ReplaceAll(chr(0), "") + " " + Hex(desc.VendorID) + ":" + Hex(desc.ProductID)
  USBMenu.AddRow(s)
end if

Bildschirmfoto 2022-04-06 um 22.33.11

So I need to remove chr(0) from the MBS USB method returning the device name.

3 Likes