XY=(var1),(var2) does not read var, only numeric values seems read

Hello,
my VBA does not seem to read the variables on the xy= command/ key-in. So xy=100,200 works ok but xy=(var1),(var2) does not work. the VBA reads value zero by default. I have a msgbox (var1), so the values are really filled in. There is no syntax error either.
Thank you very much for any clue
Nico

  • my VBA does not seem to read the variables on the xy= command/ key-in

    What VBA? Share your code. Otherwise there is nothing to be discussed, because it is not clear what code you use to read the values.

    Also, please respect the best practices and define what product and version you use.

    Regards,

      Jan

  • Many thanks Jan, 

    sorry for the lack of info. 

    It is fixed now. Bentley Support, Arthur Goldsweer helped me out. 

    2023-06-23 01:29:46 PDT - Artur Goldsweer Additional comments

    Hello Nicolas,

    from your problem description it is not clear what the problem in detail is.
    In general there are no issue with using variables with keyin commands.

    I just mad a quick test with VBA and using x,y values as double and this example works fine:

    Sub xytest()
    Dim x As Double
    Dim y As Double
        x = 2.12345
        y = 3.23456
        
        Dim sCmd As String
        sCmd = "xy=" & CStr(x) & "," & CStr(y)
        
        CadInputQueue.SendKeyin "place line"
        CadInputQueue.SendDataPoint Point3dZero
        CadInputQueue.SendKeyin sCmd
        CadInputQueue.SendReset
    End Sub

    If this code example does not help to fix the issue, please provide a code example to allow us to reproduce the issue - thanks

    Best regards,

    Artur Goldsweer
    BDN Technical Support

    I had 

    Dim point_X0 As Double
    Dim point_Y0 As Double

    point_X0 = 0 - L
    point_Y0 = 0
    CadInputQueue.SendCommand "Place Line;xy=0,0;xy=(point_X0),(point_Y0);reset"

    Sorry again, I am an occasional VBA clumsy user.

    Best regards,

    Nico

  • The issue here is that you need to assemble the command string (sCmd) out of your variables.
    That is what

    sCMD = "xy=" & CStr(x) & "," & CStr(y) does.

    "xy=" and "," are text. Cstr(x) and CStr(y) convert the double values to strings for use in the command, and & is the symbol to concatenate the entire line into a single string. That string is then used to the keyin sent to MicroStation.

    You have example code right in front of you, but you have strayed significantly from it. Rewrite your code to follow the steps as shown in the example. Learn what each step does. Once you understand how the code works, you can adjust it if you like, but if you don't understand what your example is doing, your success at rewriting it is going to be nil.

    Dim Point_X0 as Double
    Dim Point_Y0 as Double
    
    ' define coordinates
    Point_X0 = 1234
    Point_Y0 = 5678
    
    'create command string
    Dim sCmd as String
    sCmd = "xy=" & CStr(Point_X0) & "," CStr(Point_Y0)
    
    'Start the Place Line command
    CadInputQueue.SendKyin "place line"
    
    'place the first data point at zero
    CadInputQueue.SendDataPoint Point3DZero
    
    ' send the previously defined command string
    CadInputQueue.SendKeyin sCmd
    
    'reset to end the line
    CadInputQueue.SendReset

    There are other things amiss in your code. I have no idea what "L" is or where that is defined, so that's an obvious problem as well.

    MaryB

    Power GeoPak 08.11.09.918
    Power InRoads 08.11.09.918
    OpenRoads Designer 2021 R2