Welcome to the RAS Solution Forums HECRAS Controller A VBA Function to list Geometry Storage Area names and types

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #8245
    gkiers
    Participant

    Hi all!

    Just started this week with the HEC-RAS Controller…. Since there is no way in to retrieve Storage Area names, I had to write a VBA Function to retrieve their names. This function also checks for the type of Storage Area (SA or 2D Flow). The list of Storage Areas is defined as a Dynamic Array with two rows, Names in Row 0, Type (“SA” or “2D”) in Row 1. The function does not produce output in Excel or something, it creates the array for use in your code.

    Since Chris asked us to share our code (and he certainly did! 🙂 ), here it is. Hope I haven’t overlooked something.

    The Sub-routine here only added to show how you can use it.

    Good luck, Gerrit

    Sub UseListStorageAreas()
    Dim SA() As String, lNumberTot As Long, lNumberSA As Long, lNumber2D As Long
    Dim i As Long

    ‘ Geometry File Program Version= 5.04
    SA = ListStorageAreas(“c:\HEC-RAS Examples\Example Data\” & _
    “2D Unsteady Flow Hydraulics\BaldEagleCrkMulti2D\BaldEagleDamBrk.g01”)
    ‘ Geometry File Program Version= 4.00
    ‘ SA = ListStorageAreas(“c:\AutomateHECRAS\Unsteady Examples\BEAV_STO_PROBLEM.g01”)

    lNumberTot = UBound(SA, 2) + 1
    lNumberSA = 0: lNumber2D = 0
    For i = LBound(SA, 2) To UBound(SA, 2)
    If SA(1, i) = “SA” Then
    lNumberSA = lNumberSA + 1
    Else
    lNumber2D = lNumber2D + 1
    End If
    Next i

    MsgBox “Found ” & lNumberTot & ” areas: ” & lNumberSA & ” storage areas, and ” & _
    lNumber2D & ” 2D Flow areas.”

    End Sub

    Function ListStorageAreas(strGeoFile As String) As String()
    ‘ The list of Storage Areas is defined as a Dynamic Array
    ‘ with two rows, Names in Row 0, Type (SA or 2D) in Row 1
    ‘ Arrays are 0-based. By Gerrit Kiers, License CC BY 4.0
    Dim strTemp As String, arTemp() As String
    Dim strTextLine As String, i As Long

    Open strGeoFile For Input As #1

    i = 0
    ReDim arTemp(1, 0)
    Do While Not EOF(1)
    Line Input #1, strTextLine
    ‘Search the geometry text file for the key “Storage Area=”
    If InStr(strTextLine, “Storage Area=”) Then
    ‘ Only process when there is no text ahead of “Storage Area=”
    If InStr(strTextLine, “=”) = 13 Then
    ReDim Preserve arTemp(1, i)
    strTemp = Right(strTextLine, Len(strTextLine) – 13)
    strTemp = Left(strTemp, InStr(strTemp, “,”) – 1)
    arTemp(0, i) = strTemp
    ‘Check on “Is2D=” later on, define SA for pre-5.0 Geometry
    arTemp(1, i) = “SA”
    i = i + 1
    End If
    End If
    ‘Now check if the area is 2D
    If InStr(strTextLine, “Storage Area Is2D=”) Then
    Select Case Right(strTextLine, 1)
    Case 0
    arTemp(1, i – 1) = “SA”
    Case Else
    arTemp(1, i – 1) = “2D”
    End Select
    End If
    Loop

    ‘Close the text file
    Close #1

    ListStorageAreas = arTemp

    End Function

    #13615
    Chris G.
    Keymaster

    Return-Path: Received: from compute1.internal (compute1.nyi.internal [10.202.2.41])
    by sloti1d2t14 (Cyrus 3.3.0-dev0-543-gda70334-fm-20200618.004-gda703345) with LMTPA;
    Wed, 24 Jun 2020 00:19:21 -0400
    X-Cyrus-Session-Id: sloti1d2t14-1592972361-2709773-2-14010834310264386019
    X-Sieve: CMU Sieve 3.0
    X-Spam-known-sender: no
    X-Spam-sender-reputation: 500 (none)
    X-Spam-score: 0.1
    X-Spam-hits: FREEMAIL_FROM 0.001, HTML_MESSAGE 0.001, ME_SENDERREP_NEUTRAL 0.001,
    MIME_QP_LONG_LINE 0.001, RCVD_IN_DNSWL_NONE -0.0001,
    RCVD_IN_MSPIKE_H3 0.001, RCVD_IN_MSPIKE_WL 0.001, SPF_HELO_NONE 0.001,
    SPF_PASS -0.001, URI_HEX 0.1, LANGUAGES en, BAYES_USED none,
    SA_VERSION 3.4.2
    X-Spam-source: IP=’209.85.216.54′, Host=’mail-pj1-f54.google.com’, Country=’US’,
    FromHeader=’com’, MailFrom=’com’
    X-Spam-charsets: plain=’utf-8′, html=’utf-8′
    X-Resolved-to: [email protected]
    X-Delivered-to: [email protected]
    X-Mail-from: [email protected]
    Received: from mx3 ([10.202.2.202])
    by compute1.internal (LMTPProxy); Wed, 24 Jun 2020 00:19:21 -0400
    Received: from mx3.messagingengine.com (localhost [127.0.0.1])
    by mailmx.nyi.internal (Postfix) with ESMTP id C23991960115
    for ; Wed, 24 Jun 2020 00:19:20 -0400 (EDT)
    Received: from mx3.messagingengine.com (localhost [127.0.0.1])
    by mx3.messagingengine.com (Authentication Milter) with ESMTP
    id E86513B0517;
    Wed, 24 Jun 2020 00:19:20 -0400
    ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=fm3; t=
    1592972360; b=hh6DUgJPkMdoJBnz5Mu87F2FlxbZApMMn6H0o9eiDXll/KCmC2
    sJ70Tbs/xDgehOgWZORsyesl30ZugCktVv8jwTBj+U32a9+LBIBkfH7PTDhcVzNY
    YD/Fe37KKf6koYPvlFVWuKr6amdq1A2bEJviLIdH3cvxNCJQ6ilWAsRExg8F2iSm
    kqvE8Jfaru5yJ1kRg2b9m3ySXCFBuXjaseGckmylm1uURr2R+pE6ZmR8TUdTTukV
    uybzF3W8T9xRpN2IP4fdtSnNkb1wGOU7IslXwxmCj3rNFq5ZuDkDzLH2Jlab3OHS
    8MnGxwcjFOH3rTx2Ld59s1rt9ushVJ1IaipA==
    ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=
    messagingengine.com; h=content-type:content-transfer-encoding
    :from:mime-version:subject:date:message-id:references
    :in-reply-to:to; s=fm3; t=1592972360; bh=w/UaStigCm8dgDKKHJsOMts
    gu8ykM30fNBB78088deU=; b=FaU9ibvxS2/A/B2zTLlf3CHFjfVrr0Yr6GF/dMF
    Ti2BGN6f+2nUNRGi7Az6RXeOnGjiTJjxnKZywSYKZxXRfqR4w/QXxE9xWGiZH4AL
    ugZMFY5KXnK8EuRBGzT6CfLuGNtJeluPDU9ooVY1y7Yl1jZ6FRZxBIecOOCHwIVL
    Ni1ymyiur0i+lES//l3l8kKkIE4AI+K/PFyVHpfvClutrrlTcXGRT4BiVdBg+hWX
    MoXLHjQDDeA/dCi/o0+SaW8uufdTcspI2cdz6gbkqEzUdpIN0T/oI9oK+HULQrF/
    T9XLZj3rTz+OYUOOFcd1O0xY++lmhJlPPWYwIXPyh/IoSoA==
    ARC-Authentication-Results: i=1; mx3.messagingengine.com; arc=none (no signatures found);
    bimi=none (Domain is not BIMI enabled);
    dkim=pass (2048-bit rsa key sha256) header.d=gmail.com
    [email protected] header.b=hq3BOOG3 header.a=rsa-sha256
    header.s=20161025 x-bits=2048;
    dmarc=pass policy.published-domain-policy=none
    policy.published-subdomain-policy=quarantine
    policy.applied-disposition=none policy.evaluated-disposition=none
    (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p
    header.from=gmail.com;
    iprev=pass smtp.remote-ip=209.85.216.54 (mail-pj1-f54.google.com);
    spf=pass [email protected]
    smtp.helo=mail-pj1-f54.google.com;
    x-aligned-from=pass (Address match);
    x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net
    [email protected] header.b=CCHFJmB8;
    x-ptr=pass smtp.helo=mail-pj1-f54.google.com
    policy.ptr=mail-pj1-f54.google.com;
    x-return-mx=pass header.domain=gmail.com policy.is_org=yes
    (MX Records found: alt4.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com);
    x-return-mx=pass smtp.domain=gmail.com policy.is_org=yes
    (MX Records found: alt4.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com);
    x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES128-GCM-SHA256
    smtp.bits=128/128;
    x-vs=clean score=0 state=0
    Authentication-Results: mx3.messagingengine.com;
    arc=none (no signatures found);
    bimi=none (Domain is not BIMI enabled);
    dkim=pass (2048-bit rsa key sha256) header.d=gmail.com
    [email protected] header.b=hq3BOOG3 header.a=rsa-sha256
    header.s=20161025 x-bits=2048;
    dmarc=pass policy.published-domain-policy=none
    policy.published-subdomain-policy=quarantine
    policy.applied-disposition=none policy.evaluated-disposition=none
    (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p
    header.from=gmail.com;
    iprev=pass smtp.remote-ip=209.85.216.54 (mail-pj1-f54.google.com);
    spf=pass [email protected]
    smtp.helo=mail-pj1-f54.google.com;
    x-aligned-from=pass (Address match);
    x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net
    [email protected] header.b=CCHFJmB8;
    x-ptr=pass smtp.helo=mail-pj1-f54.google.com
    policy.ptr=mail-pj1-f54.google.com;
    x-return-mx=pass header.domain=gmail.com policy.is_org=yes
    (MX Records found: alt4.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com);
    x-return-mx=pass smtp.domain=gmail.com policy.is_org=yes
    (MX Records found: alt4.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com);
    x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES128-GCM-SHA256
    smtp.bits=128/128;
    x-vs=clean score=0 state=0
    X-ME-VSSU: VW5zdWI9aHR0cDovL2hlYy1yYXMtaGVscC4xMDkxMTEyLm41Lm5hYmJsZS5jb20vdGVtcG
    xhdGUvTmFtbFNlcnZsZXQuanRwP21hY3JvPXVuc3Vic2NyaWJlX2J5X2NvZGUmbm9kZT0x
    MTg0JmNvZGU9ZEdobGNtRnpjMjlzZFhScGIyNUFaMjFoYVd3dVkyOXRmREV4T0RSOE1URT
    NORGc1TkRneE5RPT0
    X-ME-VSCause: gggruggvucftvghtrhhoucdtuddrgeduhedrudekiedgkedvucetufdoteggodetrfdotf
    fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu
    rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpegtgffhgg
    fufffkfhgjvffosegrjehmrehhtdejnecuhfhrohhmpefvhhgvucfttefuucfuohhluhht
    ihhonhcuoehthhgvrhgrshhsohhluhhtihhonhesghhmrghilhdrtghomheqnecuggftrf
    grthhtvghrnhepffeuvddvveduudeujeevieffffefueetffeileeguefhteejkeeftedt
    teekieefnecuffhomhgrihhnpehnrggssghlvgdrtghomhenucfkphepvddtledrkeehrd
    dvudeirdehgedpjedurdduleefrddvfeeirdduudefnecuvehluhhsthgvrhfuihiivgep
    tdenucfrrghrrghmpehinhgvthepvddtledrkeehrddvudeirdehgedphhgvlhhopehmrg
    hilhdqphhjuddqfhehgedrghhoohhglhgvrdgtohhmpdhmrghilhhfrhhomhepoehthhgv
    rhgrshhsohhluhhtihhonhesghhmrghilhdrtghomhequcfukfgkgfepuddujeelle
    X-ME-VSScore: 0
    X-ME-VSCategory: clean
    Received-SPF: pass
    (gmail.com … _spf.google.com: Sender is authorized to use ‘[email protected]’ in ‘mfrom’ identity (mechanism ‘include:_netblocks.google.com’ matched))
    receiver=mx3.messagingengine.com;
    identity=mailfrom;
    envelope-from=”[email protected]”;
    helo=mail-pj1-f54.google.com;
    client-ip=209.85.216.54
    Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54])
    (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
    (No client certificate requested)
    by mx3.messagingengine.com (Postfix) with ESMTPS
    for ; Wed, 24 Jun 2020 00:19:20 -0400 (EDT)
    Received: by mail-pj1-f54.google.com with SMTP id m2so556591pjv.2
    for ; Tue, 23 Jun 2020 21:19:20 -0700 (PDT)
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
    d=gmail.com; s=20161025;
    h=content-transfer-encoding:from:mime-version:subject:date:message-id
    :references:in-reply-to:to;
    bh=w/UaStigCm8dgDKKHJsOMtsgu8ykM30fNBB78088deU=;
    b=hq3BOOG3o3rGuv6ppheY1WQkfVzQi7P5hy/Y0OCPDHHuR3Fpr5Y9LDDM1XT0KkQ/xe
    sgQTxFqhmA8PqaxCsc5L8+nqtuskB/I+rmoWcXERwAamFLk4Er078yBasqofXI3k+UpJ
    GI2JUHK2lUuJfmx6DYgHVIleiVFC+TBr1mx4Vyjd4OEZlqDYzNVqmyAtdnU+lWiIl88P
    nj+45nOcV5aEx262txyBTbooPGYRrQWsojrYWDBKuUI66TJyNXc8GXmo0h27qeKRmOlA
    U4W1HdqL9K8XuGa4X9vg6RPY4kRw2Gd7Ee6ZX5qNIIhyUr6jgqPjoJJvZZipfKFlwRxH
    upQw==
    X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
    d=1e100.net; s=20161025;
    h=x-gm-message-state:content-transfer-encoding:from:mime-version
    :subject:date:message-id:references:in-reply-to:to;
    bh=w/UaStigCm8dgDKKHJsOMtsgu8ykM30fNBB78088deU=;
    b=CCHFJmB8s6ilviJzAOk2dlp8BzIdOxHB6vF9POajSyZNIorcFKaK7Eot9ww6eGOxd6
    U3BuVBFspJk5ezrwISqCmu8umAIc5tTCxH2cnrXnMnVkvJMFAgZOmfrpcJEYlevWLVdY
    PR6oztJEbAAmKepRO1B9Som0vmT9a/2gJzwXgmWKtWJnS3ud0wkkcBsxQC832GwoK1um
    4y94M1l4q2Fe9GPSKr1Ygpgxz0SGmUwud/ovrnfRnrEL7AGC9ugSSLUfEXHHPihXtYs+
    KZFwDpROANFzAN65ZhtOadjOJX+ho8zR9eRDQhgJ1SHTHm8mWm6m4wJMqtgFoee4kABb
    bKBw==
    X-Gm-Message-State: AOAM530mlvmTa1seFySYoDcH/ro047EjQTVLl0LFz9KIsMmMrDf8LhP/
    H2GfGBXORVYmcai9glwM/TuXqqoX
    X-Google-Smtp-Source: ABdhPJzVdF8KsIjCza0WBU3K7XjNawi0LYY6m9CLVoMq5kWcIw+PJInJboVohUjB+CPcJ+VVcJF62Q==
    X-Received: by 2002:a17:90b:4905:: with SMTP id kr5mr7199984pjb.100.1592972358134;
    Tue, 23 Jun 2020 21:19:18 -0700 (PDT)
    Received: from [192.168.1.12] (c-71-193-236-113.hsd1.or.comcast.net. [71.193.236.113])
    by smtp.gmail.com with ESMTPSA id s13sm19096826pfc.136.2020.06.23.21.19.16
    for
    (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
    Tue, 23 Jun 2020 21:19:17 -0700 (PDT)
    Content-Type: multipart/alternative; boundary=Apple-Mail-DD33FA7C-9795-4C3E-A89D-19746CC81007
    Content-Transfer-Encoding: 7bit
    From: The RAS Solution Mime-Version: 1.0 (1.0)
    Subject: Re: A VBA Function to list Geometry Storage Area names and types
    Date: Tue, 23 Jun 2020 21:19:15 -0700
    Message-Id: <[email protected]>
    References: <[email protected]>
    In-Reply-To: <[email protected]>
    To: “gkiers [via HEC-RAS Help]”
    X-Mailer: iPhone Mail (17F80)

    –Apple-Mail-DD33FA7C-9795-4C3E-A89D-19746CC81007
    Content-Type: text/plain;
    charset=utf-8
    Content-Transfer-Encoding: quoted-printable

    Thanks Gerrit!

    Sent from my iPhone

    > On Jun 20, 2020, at 4:35 AM, gkiers [via HEC-RAS Help] wrote:
    >=20
    > =EF=BB=BF Hi all! Just started this week with the HEC-RAS Controller…. S=
    ince there is no way in to retrieve Storage Area names, I had to write a VBA=
    Function to retrieve their names. This function also checks for the type of=
    Storage Area (SA or 2D Flow). The list of Storage Areas is defined as a Dyn=
    amic Array with two rows, Names in Row 0, Type (“SA” or “2D”) in Row 1. The f=
    unction does not produce output in Excel or something, it creates the array f=
    or use in your code. Since Chris asked us to share our code (and he certainl=
    y did! 🙂 ), here it is. Hope I haven=E2=80=99t overlooked something. The S=
    ub-routine here only added to show how you can use it. Good luck, Gerrit
    > Sub UseListStorageAreas()
    > Dim SA() As String, lNumberTot As Long, lNumberSA As Long, lNumber2D As L=
    ong
    > Dim i As Long
    > =20
    > ‘ Geometry File Program Version=3D 5.04
    > SA =3D ListStorageAreas(“c:\HEC-RAS Examples\Example Data\” & _
    > “2D Unsteady Flow Hydraulics\BaldEagleCrkMulti2D\BaldEagleDamBrk.g01=
    “)
    > ‘ Geometry File Program Version=3D 4.00
    > ‘ SA =3D ListStorageAreas(“c:\AutomateHECRAS\Unsteady Examples\BEAV_STO_=
    PROBLEM.g01”)
    >=20
    > lNumberTot =3D UBound(SA, 2) + 1
    > lNumberSA =3D 0: lNumber2D =3D 0
    > For i =3D LBound(SA, 2) To UBound(SA, 2)
    > If SA(1, i) =3D “SA” Then
    > lNumberSA =3D lNumberSA + 1
    > Else
    > lNumber2D =3D lNumber2D + 1
    > End If
    > Next i
    >=20
    > MsgBox “Found ” & lNumberTot & ” areas: ” & lNumberSA & ” storage areas,=
    and ” & _
    > lNumber2D & ” 2D Flow areas.”
    > =20
    >=20
    > End Sub
    >=20
    >=20
    > Function ListStorageAreas(strGeoFile As String) As String()
    > ‘ The list of Storage Areas is defined as a Dynamic Array
    > ‘ with two rows, Names in Row 0, Type (SA or 2D) in Row 1
    > ‘ Arrays are 0-based. By Gerrit Kiers, License CC BY 4.0
    > Dim strTemp As String, arTemp() As String
    > Dim strTextLine As String, i As Long
    > =20
    > Open strGeoFile For Input As #1
    > =20
    > i =3D 0
    > Do While Not EOF(1)
    > Line Input #1, strTextLine
    > ‘Search the geometry text file for the key “Storage Area=3D”
    > If InStr(strTextLine, “Storage Area=3D”) Then
    > ‘ Only process when there is no text ahead of “Storage Area=3D”
    > If InStr(strTextLine, “=3D”) =3D 13 Then
    > ReDim Preserve arTemp(1, i)
    > strTemp =3D Right(strTextLine, Len(strTextLine) – 13)
    > strTemp =3D Left(strTemp, InStr(strTemp, “,”) – 1)
    > arTemp(0, i) =3D strTemp
    > ‘Check on “Is2D=3D” later on, define SA for pre-5.0 Geometry
    > arTemp(1, i) =3D “SA”
    > i =3D i + 1
    > End If
    > End If
    > ‘Now check if the area is 2D
    > If InStr(strTextLine, “Storage Area Is2D=3D”) Then
    > Select Case Right(strTextLine, 1)
    > Case 0
    > arTemp(1, i – 1) =3D “SA”
    > Case Else
    > arTemp(1, i – 1) =3D “2D”
    > End Select
    > End If
    > Loop
    > =20
    > ‘Close the text file
    > Close #1
    >=20
    > ListStorageAreas =3D arTemp
    >=20
    > End Function
    >=20
    >=20
    > If you reply to this email, your message will be added to the discussion b=
    elow:
    > http://hec-ras-help.1091112.n5.nabble.com/A-VBA-Function-to-list-Geometry-=
    Storage-Area-names-and-types-tp8903.html
    > To start a new topic under HECRAS Controller, email ml+s1091112n1184h88@n5=
    .nabble.com=20
    > To unsubscribe from HECRAS Controller, click here.
    > NAML

    –Apple-Mail-DD33FA7C-9795-4C3E-A89D-19746CC81007
    Content-Type: text/html;
    charset=utf-8
    Content-Transfer-Encoding: quoted-printable

    Thanks Gerrit!

    Sent=
    from my iPhone

    On Jun 2=
    0, 2020, at 4:35 AM, gkiers [via HEC-RAS Help] <[email protected]=
    bble.com> wrote:

    =EF=BB=BF

    Hi all!

    Just started this week with the HEC-RAS Controller…. Since there is no way=
    in to retrieve Storage Area names, I had to write a VBA Function to retriev=
    e their names. This function also checks for the type of Storage Area (SA or=
    2D Flow). The list of Storage Areas is defined as a Dynamic Array with two r=
    ows, Names in Row 0, Type (“SA” or “2D”) in Row 1. The function does not pro=
    duce output in Excel or something, it creates the array for use in your code=
    .

    Since Chris asked us to share our code (and he certainly did! :-) ), here it=
    is. Hope I haven=E2=80=99t overlooked something.=20

    The Sub-routine here only added to show how you can use it.

    Good luck, Gerrit=20

    Sub UseListStorageAreas()
      Dim SA() As String, lNumberTot As Long, lNumberSA As Long, lNumber2D As Lo=
    ng
      Dim i As Long
     =20
      ' Geometry File Program Version=3D 5.04
       SA =3D ListStorageAreas("c:\HEC-RAS Examples\Example Data\" & _
          "2D Unsteady Flow Hydraulics\BaldEagleCrkMulti2D\BaldEagleDamBrk.g01")=
    
      ' Geometry File Program Version=3D 4.00
      ' SA =3D ListStorageAreas("c:\AutomateHECRAS\Unsteady Examples\BEAV_STO_PR=
    OBLEM.g01")
    
      lNumberTot =3D UBound(SA, 2) + 1
      lNumberSA =3D 0: lNumber2D =3D 0
      For i =3D LBound(SA, 2) To UBound(SA, 2)
        If SA(1, i) =3D "SA" Then
          lNumberSA =3D lNumberSA + 1
        Else
          lNumber2D =3D lNumber2D + 1
        End If
      Next i
    
      MsgBox "Found " & lNumberTot & " areas: " & lNumberSA & " s=
    torage areas, and " & _
          lNumber2D & " 2D Flow areas."
     =20
    
    End Sub
    
    
    Function ListStorageAreas(strGeoFile As String) As String()
      ' The list of Storage Areas is defined as a Dynamic Array
      ' with two rows, Names in Row 0, Type (SA or 2D) in Row 1
      ' Arrays are 0-based. By Gerrit Kiers, License CC BY 4.0
      Dim strTemp As String, arTemp() As String
      Dim strTextLine As String, i As Long
     =20
      Open strGeoFile For Input As #1
     =20
      i =3D 0
      Do While Not EOF(1)
        Line Input #1, strTextLine
        'Search the geometry text file for the key "Storage Area=3D"
        If InStr(strTextLine, "Storage Area=3D") Then
          ' Only process when there is no text ahead of "Storage Area=3D"
          If InStr(strTextLine, "=3D") =3D 13 Then
            ReDim Preserve arTemp(1, i)
            strTemp =3D Right(strTextLine, Len(strTextLine) - 13)
            strTemp =3D Left(strTemp, InStr(strTemp, ",") - 1)
            arTemp(0, i) =3D strTemp
            'Check on "Is2D=3D" later on, define SA for pre-5.0 Geometry
            arTemp(1, i) =3D "SA"
            i =3D i + 1
          End If
        End If
        'Now check if the area is 2D
        If InStr(strTextLine, "Storage Area Is2D=3D") Then
          Select Case Right(strTextLine, 1)
          Case 0
            arTemp(1, i - 1) =3D "SA"
          Case Else
            arTemp(1, i - 1) =3D "2D"
          End Select
        End If
      Loop
     =20
      'Close the text file
      Close #1
    
      ListStorageAreas =3D arTemp
    
    End Function

    =09
    =09
    =09


    If you reply to this email,=
    your message will be added to the discussion below:

    http://h=
    ec-ras-help.1091112.n5.nabble.com/A-VBA-Function-to-list-Geometry-Storage-Ar=
    ea-names-and-types-tp8903.html


    To start a new topic under HECRAS Controller, email ml+s109=
    [email protected]
    To unsubscribe from HECRAS Controller, click here.
    NAML

    =

    –Apple-Mail-DD33FA7C-9795-4C3E-A89D-19746CC81007–

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.