Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    GoTo Depending (all)

    I considered logging on under a pseudonym before posting this question.
    I'd like to write a cascading GoTo, which in COBOL was GO TO DEPENDING
    I am given a series of values and want to assign those values to controls on a GUI.
    The controls are command controls: cmd01, cmd02, cmd03 etc up to cmd16.
    If I am given 10 values I want to assign them to cmd01, cmd02 through cmd10.
    The "obvious' method is to GoTo the tenth assignment, and drop through to the 9th, 8th etc, like this<pre> Go To Depending On UBound(lngAr)
    Case16:
    Me.cmd16.BackColor = lngAr(15)
    Case15:
    Me.cmd15.BackColor = lngAr(14)
    Case14:
    Me.cmd14.BackColor = lngAr(13)
    Case13:
    Me.cmd13.BackColor = lngAr(12)
    Case12:
    Me.cmd12.BackColor = lngAr(11)
    Case11:
    Me.cmd11.BackColor = lngAr(10)
    Case10:
    Me.cmd10.BackColor = lngAr(9)
    Case9:
    Me.cmd09.BackColor = lngAr(8)
    Case8:
    Me.cmd08.BackColor = lngAr(7)
    Case7:
    Me.cmd07.BackColor = lngAr(6)
    Case6:
    Me.cmd06.BackColor = lngAr(5)
    Case5:
    Me.cmd05.BackColor = lngAr(4)
    Case4:
    Me.cmd04.BackColor = lngAr(3)
    Case3:
    Me.cmd03.BackColor = lngAr(2)
    Case2:
    Me.cmd02.BackColor = lngAr(1)
    Case1:
    Me.cmd01.BackColor = lngAr(0)</pre>

    but I can find no built-in test in WordVBA, at any rate, to satisfy this.
    I'v examined all tracks "See Also" leading from the Select statement.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: GoTo Depending (all)

    How about

    Dim i As Integer
    For i = LBound(lngAr) To UBound(lngAr)
    Me.Controls("cmd" & Format(lngAr(i), "00")).BackColor = lngAr(i)
    Next i

    Note: the highest numbered element of lngAr has index UBound(lngAr).

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GoTo Depending (all)

    Yeah. That'll do it.
    Except I decided to write an awful-looking GoTo depending in <post:=668,728>post 668,728</post:>

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GoTo Depending (all)

    Minor <font color=ff8c00>correction</font color=ff8c00> & <font color=448800>enhancement</font color=448800><pre> For i = 1 To 16
    If UBound(lngAr) < i Then
    Me.Controls("cmd" & Format(i, "00")).BackColor = <font color=448800>-2147483633</font color=448800>
    Else
    Me.Controls("cmd" & <font color=ff8c00>Format(i,</font color=ff8c00> "00")).BackColor = lngAr(i)
    End If
    Next i
    </pre>


  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: GoTo Depending (all)

    I'd use the symbolic constant vb3DFace instead of the literal value -2147483633. (vb3DFace is part of the SystemColorConstants enum defined in VBA)

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GoTo Depending (all)

    > I'd use the symbolic constant vb3DFace

    So'dve I, had I known; but I will from now on, THANKS!

    Another meber of the "The SystemColorConstants module contains constants that identify various parts of the graphical user interface. These constants can be used anywhere in your code.", obtained merely by tapping the F2 key.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •