Hi all,
I just started with vba. I have the "Learning Microstation VBA" book from Bently. I am running into a problem with an example in the book. I am posting the code below. The problem is when I go to run the macro there is no macro name displayed in the dialog (second screenshot). Can anyone tell me where the problem is?
Hi,
You sub is looking for three arguments to be passed to it (CenX CenY, & CenZ). Microstation is assuming that it will just start the routine without any arguments. So there are two possibilities...
1) use the keyin "vba run Module1.DrawTarget x y z" (Assuming the module name is module1...)
2) create a dummy sub to run the main routine... Sub StartThis() DrawTarget x, y, z End Sub
--Robert
Unknown said:When I go to run the macro there is no macro name displayed in the dialog
MicroStation provides several programming languages. VBA's predecessor, which is still supported in MicroStation V8i, was MicroStation BASIC. MicroStation's user interface makes it hard to distinguish one from the other, and that's what has gone wrong here.
You've opened the Macros dialog, which is a perfectly reasonable thing to do. Unfortunately that dialog shows MIcroStation BASIC macros, not VBA macros. You want the Utilities|Macro|Project Manager menu item, which opens the VBA Project Manager dialog.
Wouldn't it be so much clearer if that menu were labelled Utilities|Macro| VBA Project Manager?
Regards, Jon Summers LA Solutions
After going back through the book from the start of the chapter I found that I needed code from the previous step to make this code work. However, after re-creating this process and moving onto the next step I run across another issue. Building on the code developed up to this point I tried to add the next step and now I get an error (in the screenshot). Everything was working up to the point that I added the code highlighted in yellow below. I have double checked this with the book several times.
Sub Main() 'Declare Variables Dim MyLine As LineElement Dim MyCir As EllipseElement Dim CenPt As Point3d Dim LineSt As Point3d Dim LineEn As Point3d Dim RotMatrix As Matrix3d 'Create Horizontal Line LineSt.X = -1 LineEn.X = 1 Set MyLine = Application.CreateLineElement2(Nothing, LineSt, LineEn) Application.ActiveModelReference.AddElement MyLine 'Create Vertical Line LineSt.X = 0 LineSt.Y = 1 LineEn.X = 0 LineEn.Y = -1 Set MyLine = Application.CreateLineElement2(Nothing, LineSt, LineEn) Application.ActiveModelReference.AddElement MyLine 'Create Circles Set MyCir = Application.CreateEllipseElement2(Nothing, CenPt, 0.25, 0.25, RotMatrix) Application.ActiveModelReference.AddElement MyCir Set MyCir = Application.CreateEllipseElement2(Nothing, CenPt, 0.5, 0.5, RotMatrix) Application.ActiveModelReference.AddElement MyCirEnd SubSub DrawTargets(CenX As Double, CenY As Double, CenZ As Double) ' Declare Variables Dim MyLine As LineElement Dim MyCir As EllipseElement Dim CenPt As Point3d Dim LineSt As Point3d Dim LineEn As Point3d Dim RotMatrix As Matrix3d 'Create Horizontal Line LineSt.X = CenX - 1 LineSt.Y = CenY LineSt.Z = CenZ LineEn.X = CenX + 1 LineEn.Y = CenY LineEn.Z = CenZ Set MyLine = Application.CreateLineElement2(Nothing, LineSt, LineEn) Application.ActiveModelReference.AddElement MyLine 'Create Vertical Line LineSt.X = CenX LineSt.Y = CenY + 1 LineSt.Z = CenZ LineEn.X = CenX LineEn.Y = CenY + 1 LineEn.Z = CenZ Set MyLine = Application.CreateLineElement2(Nothing, LineSt, LineEn) Application.ActiveModelReference.AddElement MyLine 'Create Circles CenPt.X = CenX CenPt.Y = CenY CenPt.Z = CenZ Set MyCir = Application.CreateEllipseElement2(Nothing, CenPt, 0.25, 0.25, RotMatrix) Application.ActiveModelReference.AddElement MyCir Set MyCir = Application.CreateEllipseElement2(Nothing, CenPt, 0.5, 0.5, RotMatrix) Application.ActiveModelReference.AddElement MyCirEnd SubSub DrawTargets() 'Draw Targets DrawTarget 0, 0, 0 DrawTarget 3, 0, 0 DrawTarget -3, 0, 0 DrawTarget 0, 3, 0 DrawTarget 0, -3, 0End Sub
Microstation CONNECT - 10.17.2.61
ORD - 2021 R1 10.10.1.3
ORD 2022 R1.1 - 10.11.3.2
ORD 2022 R3 - 10.12.2.4
Microstation v8i SS 10 - 08.11.09.919
Power InRoads v8i - 08.11.09.615
ProjectWise - 10.0.3.453
The error message is literally true: you have two subroutines named DrawTargets. To fix this:
The second instance of DrawTargets (in yellow) wants to call the first with several different parameters.
Thanks for the help. I have it working now.