Full Momentum Episode 37: All Things Gates
Gates play a crucial role in hydraulic modeling, impacting water flow, flood control, and dam operations.
Are you an HEC-RAS user? Yes? OK, try this out:
1. If you haven’t already done so, install the HEC-RAS example projects to the default location.
2. Open up a blank workbook in Excel.
3. Press Alt-F11. When the Visual Basic Editor Window opens up, select Tools…References…
4. Scroll down until you see HEC River Analysis System. If you see more than one “HEC River Analysis System”, that means you have more than one version of HEC-RAS installed on your computer. That’s okay, just select the one for the version of HEC-RAS you want to use. Check the box and click OK.
5. Click Insert…Module. Then in the module editor that pops up type (or copy and paste) the following code. In the line that starts with strRASProject = “C:Users…, make sure to use your User Name, not cgoodell. The directory path should match where you’ve installed the HEC-RAS example projects. Also, only include the last line, HRC.QuitRAS, if you are using HEC-RAS Version 5.0 or higher. If you are using Version 4.1 or lower, omit this line of code.
Sub RunRAS()
‘Instantiate a new HECRASController Class
Dim HRC As New HECRASController
‘Open a new project.
Dim strRASProject As String
strRASProject = “C:UserscgoodellDocumentsHEC DataHEC-RASSteady ExamplesBEAVCREK.prj”
HRC.Project_Open strRASProject
‘Run the HEC-RAS Project
Dim lngMessages As Long
Dim strMessages() As String
HRC.Compute_CurrentPlan lngMessages, strMessages()
‘Get water surface elevations at Node 5
Dim sngWSElev As Single
sngWSElev = HRC.Output_NodeOutput(1, 1, 5, 0, 1, 2)
MsgBox “The water surface elevation is ” & sngWSElev & “.”
‘Close HEC-RAS. The following line is only needed for HEC-RAS Version 5.0.
HRC.QuitRas
End Sub
6. Click Run…Run Sub/UserForm, or just press F5, and watch what happens. If you get the following error message (or similar), make sure you typed in the HEC-RAS project path and filename correctly and that you actually do have a project located there. Remember to replace “cgoodell” with your computer User name in the strRASProject definition in the code.
If you see HEC-RAS compute and then get the following message, then congratulations…it worked!
There. You’ve just run your first HECRASController application! Let me know in the Comments below if it worked for you. There is so much more you can do with the HECRASController. Automation of HEC-RAS projects, specific output data retrieval, batch mode simulations, real time modeling, Monte Carlo simulations, to name a few. As you’ve just found out, if you have HEC-RAS, you already have the HECRASController.
You can learn more about using the HECRASController in my new book, “Breaking the HEC-RAS Code.” Get your copy today!
.
![]()
Comments
The comments are closed.