+ Reply to Thread
Results 1 to 14 of 14

Option Buttons and If statement

Hybrid View

Imperial Option Buttons and If... 06-29-2013, 04:36 PM
Leith Ross Re: Option Buttons and If... 06-29-2013, 05:40 PM
john456852 Re: Option Buttons and If... 06-29-2013, 05:58 PM
john456852 Re: Option Buttons and If... 06-29-2013, 06:00 PM
john456852 Re: Option Buttons and If... 06-29-2013, 05:57 PM
Imperial Re: Option Buttons and If... 06-29-2013, 06:08 PM
john456852 Re: Option Buttons and If... 06-29-2013, 06:10 PM
Imperial Re: Option Buttons and If... 06-29-2013, 06:25 PM
mehmetcik Re: Option Buttons and If... 06-29-2013, 07:03 PM
Imperial Re: Option Buttons and If... 06-30-2013, 04:10 AM
Leith Ross Re: Option Buttons and If... 06-29-2013, 07:18 PM
Imperial Re: Option Buttons and If... 06-30-2013, 04:12 AM
john456852 Re: Option Buttons and If... 07-03-2013, 10:29 PM
Imperial Re: Option Buttons and If... 07-04-2013, 02:17 PM
  1. #1
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Option Buttons and If statement

    Try using the case statement to simplify your code

    Dim Pointer As Integer
    
    Private Sub CommandButton1_Click()
    
    Select Case Pointer
    
    Case 0
    Dietstate = "Dieting"
    Case 1
    Dietstate = "Diet Ruined"
    Case 2
    Dietstate = "Diet Not Ruined"
    Case 10
    Dietstate = "Starving"
    Case 11
    Dietstate = "Fasting"
    Case 12
    Dietstate = "Eating"
    Case 20
    Dietstate = "Dying"
    Case 21
    Dietstate = "Last Legs"
    Case 22
    Dietstate = "Deceased"
    Case Else
    Dietstate = "Dunno"
    End Select
    
    TextBox2.Value = Dietstate
    End Sub
    
    Private Sub OptionButton1_Click()
    UpdatePointer
    End Sub
    Private Sub OptionButton2_Click()
    UpdatePointer
    End Sub
    Private Sub OptionButton3_Click()
    UpdatePointer
    End Sub
    Private Sub OptionButton4_Click()
    UpdatePointer
    End Sub
    
    Private Sub UpdatePointer()
    Pointer = 0
    If OptionButton1 = True Then Pointer = Pointer + 1
    If OptionButton2 = True Then Pointer = Pointer + 2
    If OptionButton3 = True Then Pointer = Pointer + 10
    If OptionButton4 = True Then Pointer = Pointer + 20
    TextBox1.Text = "Pointer Value = " & Pointer
    End Sub
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    05-04-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Option Buttons and If statement

    Interesting point mehmetcik, but would not be suitable for the particular project I am using.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1