S
Sekker
I am quite new to VBA so please bare with me. I am trying to figure ho
to build a label by concatenating strings using command buttons.
For example pressing command button 1 scrolls through a list of option
and displays them in the label
Command button 2 scrolls through choices applicable to displayed tex
from button1 to add to the label.
I have tried two methods using boolean and arrays but I have not bee
that successful.
Could someone look at the code below and let me know if I am on th
right track. Any suggestions or better methods would be greatl
appreciated
Thanks
Sekker
Version 1
Option Explicit
Dim garage As Boolean
Dim lights As Boolean
Dim temp As Boolean
Dim phone As Boolean
Dim security As Boolean
Dim ButtonOne As String
Dim ButtonTwo As String
Dim garageopt As Boolean
Dim lightsopt As Boolean
Dim tempopt As Boolean
Sub DisplayCaption()
' concatenate the caption with the two string
' variables.
Label1.Caption = ButtonOne & " " & ButtonTwo
End Sub
Private Sub CommandButton1_Click()
If garage Then
ButtonOne = "garage"
garage = False
lights = True
temp = False
' phone = False
' security = False
Call DisplayCaption
ElseIf lights Then
ButtonOne = "lights"
garage = False
lights = False
temp = True
' phone = False
' security = False
Call DisplayCaption
Else
ButtonOne = "temp"
garage = True
lights = False
Call DisplayCaption
End If
End Sub
Private Sub UserForm_Initialize()
garage = False
garageopt = False
End Sub
Private Sub CommandButton2_Click()
If garage And garageopt Then
ButtonTwo = "Open"
garageopt = False
ElseIf garage And garageopt = False Then
ButtonTwo = "Close"
garageopt = True
End If
End Sub
Private Sub CommandButton3_Click()
End Sub
Private Sub Label1_Click()
End Sub
Version 2
Option Explicit
Dim ArrayOption(1 To 5) As String
Dim Flag As Integer
Dim Index As Integer
Private Sub CmdOption_Click()
FillArray
DisplayArray
End Sub
Private Sub CmdSet_Click()
Flag = 0
End Sub
Private Sub FrmDisplay_Click()
TextBox1.SetFocus
End Sub
Private Sub mdReset_Click()
'clear the textbox
TextBox1.Text = ""
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub UserForm_Click()
End Sub
Public Sub DisplayArray()
Dim Counter As Integer
Counter = 1
Flag = 1
Do While DoEvents()
If Flag = 1 Then
TextBox1.Text = ArrayOption(Counter)
Counter = Counter + 1
If Counter = 5 Then
Counter = 1
End If
End If
Loop
End Sub
Public Sub FillArray()
ArrayOption(1) = "Garage"
ArrayOption(2) = "Lights"
ArrayOption(3) = "Security"
ArrayOption(4) = "Temp"
ArrayOption(5) = "Messages"
End Su
to build a label by concatenating strings using command buttons.
For example pressing command button 1 scrolls through a list of option
and displays them in the label
Command button 2 scrolls through choices applicable to displayed tex
from button1 to add to the label.
I have tried two methods using boolean and arrays but I have not bee
that successful.
Could someone look at the code below and let me know if I am on th
right track. Any suggestions or better methods would be greatl
appreciated
Thanks
Sekker
Version 1
Option Explicit
Dim garage As Boolean
Dim lights As Boolean
Dim temp As Boolean
Dim phone As Boolean
Dim security As Boolean
Dim ButtonOne As String
Dim ButtonTwo As String
Dim garageopt As Boolean
Dim lightsopt As Boolean
Dim tempopt As Boolean
Sub DisplayCaption()
' concatenate the caption with the two string
' variables.
Label1.Caption = ButtonOne & " " & ButtonTwo
End Sub
Private Sub CommandButton1_Click()
If garage Then
ButtonOne = "garage"
garage = False
lights = True
temp = False
' phone = False
' security = False
Call DisplayCaption
ElseIf lights Then
ButtonOne = "lights"
garage = False
lights = False
temp = True
' phone = False
' security = False
Call DisplayCaption
Else
ButtonOne = "temp"
garage = True
lights = False
Call DisplayCaption
End If
End Sub
Private Sub UserForm_Initialize()
garage = False
garageopt = False
End Sub
Private Sub CommandButton2_Click()
If garage And garageopt Then
ButtonTwo = "Open"
garageopt = False
ElseIf garage And garageopt = False Then
ButtonTwo = "Close"
garageopt = True
End If
End Sub
Private Sub CommandButton3_Click()
End Sub
Private Sub Label1_Click()
End Sub
Version 2
Option Explicit
Dim ArrayOption(1 To 5) As String
Dim Flag As Integer
Dim Index As Integer
Private Sub CmdOption_Click()
FillArray
DisplayArray
End Sub
Private Sub CmdSet_Click()
Flag = 0
End Sub
Private Sub FrmDisplay_Click()
TextBox1.SetFocus
End Sub
Private Sub mdReset_Click()
'clear the textbox
TextBox1.Text = ""
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub UserForm_Click()
End Sub
Public Sub DisplayArray()
Dim Counter As Integer
Counter = 1
Flag = 1
Do While DoEvents()
If Flag = 1 Then
TextBox1.Text = ArrayOption(Counter)
Counter = Counter + 1
If Counter = 5 Then
Counter = 1
End If
End If
Loop
End Sub
Public Sub FillArray()
ArrayOption(1) = "Garage"
ArrayOption(2) = "Lights"
ArrayOption(3) = "Security"
ArrayOption(4) = "Temp"
ArrayOption(5) = "Messages"
End Su