Switch in VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jollywg
    New Member
    • Mar 2008
    • 158

    Switch in VBA

    I have a textbox that takes user input, and depending on what the user inputs i want to perform a formula. I know the code for Java, but not for VBA
    IE textbox1 = 0

    switch(Me.textb ox1)
    {
    case 1:
    a+b =c
    break;

    case 2:
    etc.
    }

    Thanks
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Jollywg
    I have a textbox that takes user input, and depending on what the user inputs i want to perform a formula. I know the code for Java, but not for VBA
    IE textbox1 = 0

    switch(Me.textb ox1)
    {
    case 1:
    a+b =c
    break;

    case 2:
    etc.
    }

    Thanks
    I've posted the general syntax in the AfterUpdate() Event of TextBox:
    [CODE=vb]
    Private Sub TextBox_AfterUp date()
    If Not IsNull(Me![TextBox]) Then
    'No Variables are declared
    Select Case Me![TextBox]
    Case Is < 0
    E = m * c ^ 2
    Case 0
    Pi = 4 * Atn(1#)
    Case 1 To 4
    j = -b + Sqr(453)
    Case 5, 6
    a = b + c
    Case 7
    R = Pi * R ^ 2
    Case 8
    P = 2 * (l + w)
    Case 9
    gr = Rnd()
    Case 10
    a = ((b1 + b2) / 2) * (a ^ 2)
    Case "..." 'etc., etc.
    Case Else
    'General Formula for all 'other' possibilities
    End Select
    End If
    End Sub[/CODE]

    Comment

    Working...