CheckBox Value not in True/False but in Text - vba

Have a Code which aims to change to display a Text rather than a True/False Statement - And this with a Checkbox, I want to set the Value to something like
Checkbox is on -> Instead of True -> On!
Checkbox is on -> Instead of False-> Not On!
I tried to "hardcore it", but not sure how this would work...
Call UpdateBookmark("Bookmark1", Me.Checkbox1."On!")
Tried this...
If Me.Checkbox1.Value = True Then
Me.Checkbox1.Value = "On!"
End If

This should do:
Call UpdateBookmark("Bookmark1", IIf(Me!Checkbox1Value, "On!", "Not On!"))

Related

How to set a checkbox status as True / False within a IF-THEN statement using vb.net

I am trying to automate a scenario using silk test and am very new to coding using vb.net. Basically i have a checkbox identified and want to set it to either true or false based on a string value being passed.
for e.g.
Dim tfnSigned As String
tfnSigned = "Yes"
If tfnSigned = "Yes"
Then .CheckBox("SED_TFNSignedCheckBox").Check
End If
In this case, i get a compiler error as .CheckBox is not identified as a class and hence cannot use the Check method
Kindly help
Cheers
Checkboxes accepts only Boolean values which is either True or False.
The syntax is pretty much straightforward and can be easily found on Google
Here I assume that SED_TFNSignedCheckBox is the name of your checkbox control.
Dim tfnSigned As String
tfnSigned = "Yes"
If tfnSigned = "Yes" Then
SED_TFNSignedCheckBox.Checked = True
End If
To use the .Checkbox() method you need to be in the correct context, i.e. it should appear in a With..End With statement. the best way to get the syntax correct is to use the Silk Test Recorder to record a checking the checkbox, this will generate something like this.
With _desktop.Dialog("locator of dialog")
.CheckBox("SED_TFNSignedCheckBox").Check
End With
So your complete code would look something like this ...
Dim tfnSigned As String
tfnSigned = "Yes"
If tfnSigned = "Yes" Then
With _desktop.Dialog("locator of dialog")
.CheckBox("SED_TFNSignedCheckBox").Check
End With
End If
Hope that helps.

How to insert a conditional combobox?

I'm working with VBA, and I'm struggling to get a combobox with two options:
First option: the textbox next to it must appear one "-", like if is supposed to be empty or disabled.
Second option: the same texbox must must be able to receive an input, like numbers.
Like: "Do you have an ID?" if no, don't fill the texbox. If yes, fill it with your number.
Thanks!
I'm assuming C# implementation but this would work essentially for any .net or WINFORMS project.
if(cbo.selectedindex = 0)
tbFoo.text = "-";
else if(cbo.selectedindex == 1)
tbFoo.text = "filltextwithID";
Check if the selectedindex of your combobox is the first or second options in the list and do your first option with the first selectedindex, else if it is the second, fill your textbox with whatever you need to fill it with(textwise).
Use your conditional if statement(naturally, I know) to check your conditions that you want your combobox to do to your textbox.
Otherwise another way to do this is with a selectedindexchanged event and do your switch statement or if statement based on which selectedindex you are talking about. 0 is the first item....all the way up to n items.
I got it! Here's the code:
Private Sub ComboBox_Change()
If ComboBox = "I don't have an ID" Then
IdTextBox.Visible = False 'Hidden
IdLabel.Visible = False
Else
IdTextBox.Visible = True 'Unhidden
IdLabel.Visible = True
End If
End Sub

rad menu , check if item text exists

Using telerik and the radmenu, do you know how to check if the item exists by text
my menu contains the text "menu1"
If I use menu.FindItemByText("menu1").Enabled = False this will disable the button
BUT
If I use menu.FindItemByText("menuTEST").Enabled = False then I get an exception as this button does not exist.
How do I stop the error?
I tried this below but it say it cant return booloen
If menu.FindItemByText("menuTEST") then
'do this
End If
Try this:
If Not(menu.FindItemByText("menuTEST") Is Nothing) then
'do this
End If

if combo box selected item is null how do I assign an empty string to it instead? vb.net

I have a property called ReplacementTo
and I set a value to it based on the selecteditem from the combobox, like this:
classEquipmentItem.ReplacementTo = cmbReplcmnt.SelectedItem.ToString
Now I can't use cmbReplcmnt.Text because what I actually need is the value of that SelectedItem
So problem is, if the user leaves the combobox as blank, it throws a null exception.
I decided to use the IIf function then:
classEquipmentItem.ReplacementTo = IIf(IsNothing(cmbReplcmnt.SelectedItem.ToString), classEquipmentItem.ReplacementTo = "", cmbReplcmnt.SelectedItem.ToString)
Unfortunately I still get the error
I tried using a Try-Catch for it and it worked, but I don't want to rely on the Try-Catch, so I was wondering is there a another way to work this through?
You can try SelectedValue instead of SelectedItem property.
IF IsNothing(cmbReplcmnt.SelectedItem) Then
classEquipmentItem.ReplacementTo=String.Empty
Else
classEquipmentItem.ReplacementTo=cmbReplcmnt.SelectedItem.ToString
'OR
'classEquipmentItem.ReplacementTo=cmbReplcmnt.SelectedValue.ToString
End If
Or, you can use IF or IIF
classEquipmentItem.ReplacementTo=IF(IsNothing(cmbReplcmnt.SelectedItem),
String.Empty,cmbReplcmnt.SelectedValue.ToString())
Your problem is IsNothing(cmbReplcmnt.SelectedItem.ToString)
The .ToString can't be evaluated in the case where the SelectedItem is Nothing so the IsNothing function fails
Your fixed code should be as follows:
classEquipmentItem.ReplacementTo = If(IsNothing(cmbReplcmnt.SelectedItem), "", cmbReplcmnt.SelectedItem.ToString)
Even easier than that though is this:
classEquipmentItem.ReplacementTo = CStr(cmbReplcmnt.SelectedItem)

Help assigning Gridview check box to a variable

This line of code references a checkbox in a Gridview, how can I assign the value of the check box 1 or -1, I think it is for checked or unchecked, to a variable so that I can run an if statement against it, and change it to True or False?
dt.Rows(row.DataItemIndex)("DisplayString") = (CType((row.Cells(3).Controls(0)), CheckBox)).Checked
Try this:
Dim checkBox1 as CheckBox = CType((row.Cells(3).Controls(0)), CheckBox)
checkBox1.Checked = True
Edit
I'm not sure I completely understand what it is you are trying to do?
Are are you are attempting to check/uncheck the CheckBox based on the values 1 or -1?
Could you elaborate please?
Here is the solution that worked for me. I need to read the condition/status of the check box and use an if statement on the result....
dt.Rows(row.DataItemIndex)("DisplayString") = (CType((row.Cells(1).Controls(0)), CheckBox)).Checked
Dim CB As CheckBox = CType((row.Cells(1).Controls(0)), CheckBox)
value = CB.Checked
Now I can use 'value' in my if statements.