Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Option
VB Tutorial
Push Button
Database
Navigate To
Home
Tutorials
Source Code Samples
VB.NET Tutorials
Level:
Guides
Beginner Guide
Controls Guide
Understanding forms
Timer control
Multiple Forms
Everything Images
Control arrays
Option Buttons
Check Boxes
Math Game
(o) Hangman
(o) Tic Tac Toe
(o) Calculator
(o) Cryptogram
(o) Concentration
Database Guide
User login
Username: *
Password: *
Log in
Create new account
Request new password
Next, code was written for the Click event of each of the option
buttons. The code causes the background color of the form to
change to the appropriate color when one of the option buttons is
clicked:
Private Sub optRed_Click()
Form1.BackColor = vbRed
End Sub
Private Sub optGreen_Click()
Form1.BackColor = vbGreen
End Sub
Private Sub optBlue_Click()
Form1.BackColor = vbBlue
End Sub
If the program was to be run at this point, you would get immediate
results when you clicked one of the option buttons as soon as
you clicked one of the option buttons, the form would change color.
To demonstrate the "delayed" action, let's say the above program
was modified as follows: First, a command button named
cmdChangeColor is placed on the form:
Second, all code from the option buttons' Click event (shown in the
previous example above) is removed.
Third, code for the cmdChangeColor_Click event is written as
follows:
Private Sub cmdChangeColor_Click()
If optRed.Value = True Then
Form1.BackColor = vbRed
ElseIf optGreen.Value = True Then
Form1.BackColor = vbGreen
Else
Form1.BackColor = vbBlue
End If
End Sub
If the program was to be run at this point, clicking on one of the
option buttons would not cause an immediate result it would
simply set the Value of the clicked button to True. Only when you
clicked the "Change Color" button would the background color of
the form change, based on the code above.
Syntax Notes:
The Value property is the default property of the option button and
can therefore be dropped when coding, as in:
If optRed = True Then . . .
Since Value is a Boolean property, you can drop the "= True" from
the conditional expression, making it possible to cut the coding
down further to:
If optRed Then . . .
Coding an Option Button Control Array
Using the same scenarios as in the examples above, suppose we
used a control array for the set of three option buttons (a control
Value
&H0
&HFF
&HFF00
&HFFFF
&HFF0000
&HFF00FF
&HFFFF00
&HFFFFFF
Description
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
System Colors
Constant
vbScrollBars
vbDesktop
vbActiveTitleBar
Value
&H80000000
&H80000001
&H80000002
vbInactiveTitleBar
&H80000003
vbMenuBar
&H80000004
vbWindowBackground
&H80000005
vbWindowFrame
&H80000006
vbMenuText
&H80000007
vbWindowText
&H80000008
vbTitleBarText
&H80000009
vbActiveBorder
&H8000000A
vbInactiveBorder
&H8000000B
vbApplicationWorkspace
&H8000000C
vbHighlight
&H8000000D
vbHighlightText
&H8000000E
vbButtonFace
&H8000000F
vbButtonShadow
&H80000010
vbGrayText
&H80000011
Description
Scroll bar color
Desktop color
Color of the title bar
for the active
window
Color of the title bar
for the inactive
window
Menu background
color
Window
background color
Window frame
color
Color of text on
menus
Color of text in
windows
Color of text in
caption, size box,
and scroll arrow
Border color of
active window
Border color of
inactive window
Background color
of multipledocument interface
(MDI) applications
Background color
of items selected in
a control
Text color of items
selected in a
control
Color of shading on
the face of
command buttons
Color of shading on
the edge of
command buttons
Grayed (disabled)
text
vbButtonText
&H80000012
vbInactiveCaptionText
&H80000013
vb3DHighlight
&H80000014
vb3DDKShadow
&H80000015
vb3DLight
&H80000016
vb3DFace
vb3Dshadow
&H8000000F
&H80000010
vbInfoText
&H80000017
vbInfoBackground
&H80000018
Similar links
Database Access with the Data Control
Using ADO and the ListView control
Visual Basic Power Pack
SQL Databases Create, Update, and Query
VB6 Animated Charts (With FusionCharts)
VB6 Downloads
Common Dialogs Allow A professional VB app
Using Toolbars in Visual Basic Tutorial
Working with Menus in VB6
Creating your own Drag and Drop apps in VB6
Subscribe
option button
What is the code for inserting a color e.g green in an option button such that when you
click on the button,the color changes into green instead of remaining black.
reply
Radio Button
If you have created a calculator and have used radio buttons such as "Calculate" and
"Exit". How do I create the operator in order to be able to use the button?
reply
I have 10 option controls refer to a cell, result a number of which option selected.
I want to reorder this option control, but how?
Thanks for your help
reply
Radio buttons
I have to put together an evaluation instrument using Word 2007. I am not a code
specialist, so can you help me write code for the buttons?
example
1. Employee is punctual 4 3 2 1 0
2. Employee is professional 4 3 2 1 0
3. Employee is courteous 4 3 2 1 0
Each numeric option needs to correspond to a radio button and I will need to create
this in chart form.
If you could help me with this code, I think I could copy/paste/modify to complete all
sections of the survey.
Any time and assistance that you can give me will be very much appreciated.
Thank you,
Rich
reply
Option if then
Hi, i need to know how could i code for an if then with an option and a textbox!
What i want? Code or ideas for code to do this:
if opt1.enabled = true then opt2.enabled = false
if opt1.enabled = True then txt1.text = "V-"
I try it on VB6 but the syntax is invalid, second, i need in the textbox after V- appears the
cursor but it disappear, how can i get the cursor right after opt1 is selected it appears
after text V- in the textbox??
and last, i have a combobox, i put the list and locked is false, how can i capture what i
select from the list in my databse?
Im a beginner and i have to do this for my class!!
reply
haii!! im an IT student ..
haii!! im an IT student .. could someone please help me do some coding about a voting
system ?? i badly need ur help
reply
there are 5 group box in each group box there are 5 check box and each of them has a
equivalent value if ordered. How can i create a code for those ones. Example: 1st
groupbox i chose button 3 which is equivalent to $500 then in groupbox2 i checked
button 1 which is equivalent to $900 and last Groupbox3 i checked button 5 which is
equivalent to $50. What will i put to compute button to input in the textbox1 the total
amount of charge.
reply
helppp!
Hey there! I am new to visual studio, and i have a project that is due and i need help to
get it started i have some coding and can get the insults to the message box but that is it.
1. The interface must include:
A textbox for the user to enter the name of the victim
A control that allows the user to select the number of adjectives to be included in the
insult (1-3)
A button to generate the insult
An output textbox where the insult will be displayed to the user
A button to clear the application so you can generate new insults with a new victim
A button that will display about information in a popup
2. The output textbox should display all insults generated, separated by a carriage
return; every time the user clicks the generate button a new insult is added to the textbox
3. An error message box should appear if the user tries to generate insults without
entering a victim's name first and not produce an insult as a result
4. The generator must randomly select each adjective and the single noun from a
possible set of adjectives and nouns; there must be at least 10 possible adjectives and 6
possible nouns; repeated adjectives are allowed
5. After randomly selecting the adjectives and noun, the generator then builds an insult
including the victim's name entered and displays in the output textbox. Every newly
generated insult must be displayed at the top of the textbox not the bottom!
6. This application must include some custom visual design (size, button size, fonts, form
icons, colors, etc) as well as be user-friendly!
7. All controls must be logically named
8. You should not have any large blocks of code that are repeated. This is known as
redundant code...however, handling multiple insult adjectives in this project tends to take
beginners down this route. Can you use loops to avoid this?
9. In the past, some students have explored Arrays when developing a solution for this
project. Although they do provide an efficient solution to the problem, this project
requires that NO ARRAYS are used.
this is the information! i got the form all layed out and trying to get the victims to go with
the radio button, but when i do that and typ my victim in and click the radio button only
the insults show up..
reply
Hi,
Can anyone help me with setting up a push button to create and execute a push button
that replaces old values with new values.
Example:
Old New
2.5 3.0
1.5 3.5
2.0 2.5
Then RESET button pressed.
Old New
3.0
3.5
2.5
So then, I can enter the new values.
Thanking you in advance for your time.
reply
help!!
how can I do option button works?? because I use the code but is failed,I don't know :S
reply
Do what....
for example:
if user are check in..
> click radio button and system will save the time when are the user check in..same goes
to the check out method..
anyone out there..can you help me..
reply
hellow world
ahm.. i would like ask some vb codes about option button..and check button connecting
to database..if you can help me pls.. send me some example codes for that..tnx
reply
HI!!!
Can anyone tell me how to fix this problem I have with my Radio Button: rad = radio btn =
button
Dim txtNameEmp, txtworkdone, radbtnJ, radbtnA, radbtnT As String
Dim txtHours, lblPay As Double
If radbtnJ = True Then
lblPay = txtHour * 12 (<- Money they are suppose to earn for each hour)
ElseIf radbtnA = True Then
lblPay = txtHours * 10
ElseIf radbtnT = True Then
lblPay = txtHours * 8
End If
End Sub
I need to calculate how much an employee will earn if he works as: "J" = Permanent
worker $12, "A" = apprentice workers $10 and "T" = Temporary workers $8. I putted the 3
radio buttons in a Panel (container) and kept trying to figure out what is the problem here
but I don"t know... It keeps saying: "Variable 'radbtnJ' is used before it has been assigned
a value. A null reference exception could result at runtime" Can anyone help please!!!
reply
Variables
I believe the problem is at the way you have declared your variables.
You have only declared the "radbtny" as string and lblPay as Double. All the rest
variables have been declared as variant and the program doesn't know what type is
going to be used for. So when you try the "If radbtnJ = True Then" is a run-time error
because the variable radbtnJ is empty and it hasn't been assigned any value to it
yet.
Try this instead:
Dim txtNameEmp as String, txtworkdone as String, radbtnJ as String, radbtnA as
String, radbtnT As String
Dim txtHours as Double, lblPay As Double
I hope I helped you!
reply
how can a make a program wherein there are 5 option buttons w/ diffrent pictures each
behind it, and when i click 1 opt button the picture behind it will appear and so on.. pls
answer.. tnxmuch.. and give me also the codes..
reply
Two control arrays (one with 5 option buttons and one more with 5 images) will help
you enough.
Here is what I have in mind:
Private Sub Option1_Click(Index As Integer)
for I = 0 to 4
Image1(I).visible = iif(I <> Index, False, True)
next
End Sub
If you need anything else, please tell me!
reply
hey!
Can you help me with my problem please! I posted it under my name Carla ...
It seems like you could really help!!
reply
hey guys,
I have a problem in visual basic about in pizza ordering system
Can you send me a codes ..
Please reply ..
reply
check box...
hey...
v are making a project name quiz....
v are making a form in which v are providing 8 check boxes for options to the question...
my query is...if user select any check how v store d value of check box and which text box
user select it
displayed on text box...that user selects option no1,2,3 like that...
please send me the code....
reply
You should make an array of checkboxes. Here is what you have to do:
Create a checkbox, copy it and paste it. Answer yes to the question so VB can make
an array of checkboxes. Paste it as many times as you need. Place them at the order
you want. After this, go and correct the Index property of each checkbox. This is the
value you need. Double click any checkbox and the code should be something like
this:
Private Sub Check1_Click(Index As Integer)
If Check1(Index).Value Then Text1.Text = Index
End Sub
reply
check box...
hey...
v are making a project name movie ticket booking....
v are making a form in which v are providing 140 check boxes for selecting the seat...
question is...if user select any check how v store d value of check box and which text box
user select it
displayed on text box...that user select seat no1,2,3 like tha...
plese send me the code....
reply
please i need a code on how to use the savesettings and getsettings, with option buttons
i need it seriously for an upcoming test, please help me out
reply
vb10
hey i hv vb 10..
i m doin a projct on hospital mangmnt in vb..i hv created forms as per my design of front
end...i hv created database in vb 10 only wich is available...the problm is dat wen i run
the form,and insert values and save dem,dey donot get actuly saved in d database...in
short how to connect my database to my values...i hav add ,del ,edit ,save buttons on
forms rest all labels n text boxes..the four buttons are not helpn me in connectng my
database,pls help
reply
using operation
hello i just want to learn option button using the operation please help me to know that...
reply
option button
olivera
how to select 2 option button in 1 form??
expamle
i got 5 option button .. i want to select 2 or 3... how to do this??
reply
option button
Use check boxes -- the user can make multiple selections; don't use option buttons
since the user can only make one selection
reply
you can..
i think you cant do that...why not use checkboxes for that? ^_^
reply
It cancels my form
I'm using the radio controls to select either player one or two for a score board.
When im using the code Total1 = 1 + Total1 and run the program, it ends my form.
RadioButton1.Checked = True
TextBox4.Text = Total1
On the button Total1 is my integer and when the radiobutton1 is selected i wanted the
counter "1" to be displayed in text box 4 but it just close's everything down and dosen't
show any error's.
Is there a tutoral i could look at or any idea's round this?
reply
how can i count all the radio buttons that are checked? please reply asap.
reply
hi , in my form i have three frames each containing some option buttons, by default i have
to keep the fist option clicked(value="true") in each frame, but when i put the value say
option1 in fram1 as TRUE and then put value say option6 in frame2 as TRUE then the
1st one becomes False, when i put again TRUE for value in next optionbutton in fram3
this second one becomes false.
Please suggest how to keep one option in each fram selected at one time(By Default
Option.Value should be TRUE for first option Button in each frame.).
reply
spouses I've got 2 group of RadioButton how i can connect between them i mean by
using (IF .. Then)
For example If RadioButton1 & RadioButton2 = true then (blah...blah)
reply
Supposed to be, when i click the checkbox, the 3 option button should be in true value,
meaning all 3 have dot value. the problem is
only the 3rd option button has the true value. Can you give me the program of this one.
just send your replay to my email address. Thanks
reply
Try this:
If OptionButton1.Value = True Then
MsgBox "You chose Option 1"
ElseIf OptionButton2.Value = True Then
MsgBox "You chose Option 2"
End If
reply
option button
try, if optionbutton1.value
try,
if optionbutton1.value = true then
reply
option Botton
This is good artical.I get lot of things about op. botton.Thanks .Wish U all the best
reply
thx
Thanks! I couldn't figure out how to use these "radio buttons" before I read this tutorial! I
used to think it was something like...
If Option1.Selected = True Then ...
LOL
reply
excellent!!!!
Option buttons
Im doing a game with option buttons, but an option button at the top left hand corner get
selected by default and stuffs it up. How do I stop that? Plz i relly need help!!
reply
modify the option button property value = false. You can do it with all your option
buttons. To choose default, in declarations- general insert line with "option
button".value = true
reply
Very Helpful...
Wow, honestly, I never understood Radio buttons untill i just read that. I knew how they
worked, but I couldn't get them to work.
Thanks a lot for this explanation, it really helped me.
Mac --- 17 Years Old from NewYork.
Current Project - A TextBased RPG, One Player and Offline.
Completed Projects - 41.
Future Projects - Probably some simple games, such as Minesweeper, Memory games,
etc.
reply
vb Optionbox
radio button
When the form loads, an option button gets selected by default? I don't want any of them
to be selected by default.....how do i do that?????
reply
answer
i think u can set the option button enable propity to false then it will not be selected :)
reply
option buttons
how can i add an option buttons in a different groups wherein in that different group of
option buttons is i can choose one option in that particular group and also i can choose
another option in a different group.... how to do this in visual basic????
reply
Option button by
groups
Null
How can an option button be made to work in an excel spreadsheet, this code does not
perform the function for me. any HELP?
reply
Just today I found a method to use radio buttons to plug values into excel cells.
I used the cell method.
For an example, create four radio buttons and make sure they are in the same
group. Then code:
Trying to set an option button for a YES and No option. can't simply relate the code to
this.. any HELP?
reply
Setting an option
For you to set a no and a yes option you use the if statement and on the form there
must be two option boxes. For example if you have one of the option boxes as
optyes and the other as optno. Double click the two option boxes eg if you click the
yes option box the code will be as follow
if optyes.value = 1 then
here you write what you want to be displayed when the yes option box is clicked.
else
here you write what you want to be displayed if the yes option box is not clicked.
end if
You also do the same for the No option box only this time you replace the yes word
with no
I hope i've helped.
reply
suppose if i change the background to red and want to change back to the previous
default setting then what i have to do..
reply
you first need a command button after clicking on the new command button in the
code section write
BackColor=vbButtonFace
reply
Okay as far as it goes, but it doesn't say anything about how to set one of a set of buttons
as the default (i.e. that which is selected when a program starts. That looks like pretty
basic information to me, yet I can't find anything about it here!
reply
Okay as far as it goes, but it doesn't say anything about how to set one of a set of
buttons as the default (i.e. that which is selected when a program starts. That looks
like pretty basic information to me, yet I can't find anything about it here!
The TabIndex property decides order the objects are selected in the form. You can
see this, when the user press the Tab key. That means, the object with the TabIndex
set to 0 will be the "default" selected. You can either assign the 0 TabIndex to
another object (like a CommandButton or a TextBox) or to a new object and hide it
(Visible property set to False).
reply
After reading this tutorial i learnt how option buttons using control arrays work for
delayed action ie via a command button which i failed to do earlier. This tutorial taught
that extra to me excellently.
reply
Homepage:
Subject:
Comment: *
Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
Lines and paragraphs break automatically.
You can enable syntax highlighting of source code with the following tags: <code>,
<blockcode>. The supported tag styles are: <foo>, [foo].
Preview
MS Access VB Code
OpenGateSw.net/UI-Builder
Web 2.0 Menu Look & Feel in MS Access, Free Demo!
Unless otherwise noted, all content on this site and in the source samples is Copyrighted
2011 by the owner of vb6.us. All rights reserved - Contact Information