|
-
Nov 3rd, 2000, 06:54 PM
#1
Thread Starter
Frenzied Member
Hi,
I would like to reduce the following code:
Code:
If chkPrivate = 1 Then
ValuePrivate = "on"
Else
ValuePrivate = "off"
End If
I know it's not a lot of code to begin with but I have a whole bunch of these
to put into my program so it does add up and it's time consuming to maintain.
Basically, what I'm trying to do is to convert the check box values of 1 and 0 to
"on" or "off", respectively.
Any ideas would be greatly appreciated..
Dan
-
Nov 3rd, 2000, 06:59 PM
#2
Hyperactive Member
In school ?
Try
Code:
chkPrivate.Value = not chkPrive.value
[]P
Visual Basic 6 SP4 on win98se
QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!
-
Nov 3rd, 2000, 07:05 PM
#3
Hyperactive Member
would the select case statement make it shorter?
-
Nov 3rd, 2000, 07:14 PM
#4
Frenzied Member
You could use a boolean value (?)
Why don't you just make ValuePrivate Boolean and assign it the Boolean converted value of the checkbox?
Code:
ValuePrivate = CBool(chkPrivate)
ValuePrivate will be TRUE if chkPrivate is Checked or Greyed, and FALSE if chkPrivate is UnChecked
Hope that helps,
-
Nov 3rd, 2000, 07:19 PM
#5
New Member
What about this?
Code:
ValuePrivate = IIf(chkPrivate, "on", "off")
-
Nov 3rd, 2000, 07:19 PM
#6
Frenzied Member
You could use the Immediate If statement
Immediate if statements look cool but they run significantly slower than regular if/else statements. This also allows you to keep ValuePrivate as a string, which I assume was part of your requirement.
Code:
ValuePrivate = IIf(chkPrivate = 0, "off", "on")
' That is the shortest you can get...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|