Sort text in Option Button - livecode

I have an option button with some values
Scotland
Switzerland
England
I would like to sort these lines alphabetically.
How can I do that?
sort the text of button btn_type ascending(each)
or some variation of that does not work.

Lose the word "the":
sort lines of btn "Your option button"
and you do not even need the "lines" since this is assumed unless explicitly modified, to, say, items.
sort btn "Your option button"

First get the text of the button, then sort it, then set the text of the button:
put the text of btn "Your option button" into myText
sort lines of myText
set the text of btn "Your option button" to myText
Probably you can also do it directly:
sort lines of btn "Your option button"
The sort function is ascending by default, so you don't need to include that.

Related

How to Start Cursor After 3rd character of text box in UserForm

I am fairly new to VBA so any help would be greatly appreciated.
I have a UserForm that contains 3 labels and 3 text boxes. 2 of the text boxes (including the first one that is activated upon the form's activation) are empty. The third has 3 characters pre-filled into it. When the userform starts, I would like to fill in the first text box as normal then when I tab into the second text box, I would like the cursor to automatically go to the end of that 3 letters instead of highlighting the entire text box. I have looked around but cannot seem to find anything that can do this easily. Could you please let me know where exactly (which sub) to enter this code into as well?
My UserForm is called 'GetBIInfo2' and my text box is called 'NBIDText'
Thanks!
Select the textbox.
Go to property (F4).
Scroll till you find EnterFieldBehavior property.
Change it to 1 - FmEnterFieldBehaviorRecallSelection.
The direct approach is via the textbox'es .SelStart property; possibly you might call it via a sub procedure like this:
Sub fillAnyTextBox(myTextBox As MSForms.TextBox, ByVal firstCharacters As String)
With myTextBox
.Value = firstCharacters
.SetFocus
.SelStart = Len(firstCharacters)
.SelLength = Len(.Text) - Len(firstCharacters)
End With
End Sub
A simple alternative would be to make another text box to hold the first three characters and have the user enter the following characters into a separate textbox. Then you can write code that will take the contents of both and append them into a single string like this:
Dim finalString As String
finalString = TextBox1.Value & TextBox2.Value

How to suppress a Text Object based on header value in Crystal Report?

How to suppress a Text Object field in Crystal Report based on Header Value.
I have 2 text object fields below the Header and I want to suppress one or other based on my header.
I.e. my header is dynamic and it gets different header value.
CASE 1. In certain case if the header is "ABC" then I want to suppress or hide the 1st text object.
CASE 2. If the header is "DEF" then I want to suppress or hide the 2nd text object.
To suppress just a field and not the entire header:
Right click on the first text object
Select Format Text from the menu
On the Common tab, find the checkbox labeled Suppress. Don't check it though.
Instead, click on the x+2 button on the right side.
Note: It is quite far away from the Suppress checkbox it belongs to. See screenshot below for help with finding the button.
In the formula box that appears, type your condition for suppressing the text box. For example, if you want to suppress the text field if the header is "ABC" then you may want to enter the following:
{#HeaderField} = "ABC"
Repeat for the next text field.
However, there may be an easier way for you to go about this. Instead of having two text objects, create one formula with an IF-THEN-ELSE statement within to determine which text is displayed.
For example:
If {groupname} = "ABC" then "first set of text"
Else if {groupname} = "DEF" then "second set of text"
Else "Error"
or
If {groupname} = "ABC" then "first set of text"
Else "second set of text"
or
Select {groupname}
Case "ABC": "first set of text"
Case "DEF": "second set of text"
Default: "Error"

Excel VBA: Making userform with dynamic comboboxes, content of which changes depending on data of parental combobox

The idea is to build a userform that have numerous "lines" of two comboboxes to choose from: one let choose a category (main filed) and the second one (dependent filed) let you choose subcategory for the category user have chosen in main field.
Number of this comboboxes pairs may be variable and chosen by user - for adding or deleting line of two comboboxes there are buttons on the top. When pressing "Add Field" button, userform adds new pair at the bottom and gives each combobox name with ordinal number at the end, e.g.:
Main_field_1, Dependent_field_2;
Main_field_2, Dependent_Field_2
and so on.
Visual example of userform
But there is a problem: if no name of combobox is predetermined, how can a code be written for them?
For example I want to register a change in Main_field to be able to run a code, that will fill in data for Dependent_field, based on Main_field value. But if this comboboxes were created by user with "Add field" button there was no code written for them like:
Private Sub Main_field_1_Change()
Select Case UserForm1.Main_field_1.Value
Case "Category1"
UserForm1.Dependent_field_1.AddItem "SubCategory_1"
UserForm1.Dependent_field_1.AddItem "SubCategory_2"
Case "Category2"
UserForm1.Dependent_field_1.AddItem "SubCategory_88"
UserForm1.Dependent_field_1.AddItem "SubCategory_99"
Case Else
End Select
End Sub
because name of main and dependent fields have variables in them, like Main_field_999 and Dependent_field_999 (the numbers at the end will be identical for each line) and as i understand there is code can exist like this:
Private Sub Main_field_XX_Change()
Select Case UserForm1.Main_field_XX.Value
Case "Category1"
UserForm1.Dependent_field_XX.AddItem "SubCategory_1"
UserForm1.Dependent_field_XX.AddItem "SubCategory_2"
Case "Category2"
UserForm1.Dependent_field_XX.AddItem "SubCategory_88"
UserForm1.Dependent_field_XX.AddItem "SubCategory_99"
Case Else
End Select
End Sub
The question is: how can a code be written to recognize a change in combobox, that have a variable name to then execute different piece of code, based on value in this combobox?

change TEXT to display in excel via vba

Is there a way to change the text to display of all the hyperlinks in a sheet?
All I want to do it is run a macro to trim the the existing TEXT to Display to 5 chrs only?
At the mo, my text to display is really big text string something like "21253.bla bla bla.wla wla wla. dah dah dah.jpg" and I only want to display 21253
Is this even possible?
Regards
Shei
Loop through the links on the sheets and use the left function to trim the text to display. Example below
Dim hl As Hyperlink
For Each hl In ActiveSheet.Hyperlinks
hl.TextToDisplay = Left(hl.TextToDisplay, 5)
Next

Focus Rectangle Appears on All Listbox Items in VBA

I've created a Userform in Excel VBA, on which there is an unbound Listbox that has its MultiSelect property set to Extended. When that listbox receives focus by any means other than clicking a list item, all items in that list appear with the dotted focus rectangle around them.
Here is some code that shows the phenomenon beside another listbox with MultiSelect set to Single for comparison. Create a Userform, put two Listboxes on it, and add the code to the form. When you launch the form, tab between listboxes to see what I've described.
Private Sub UserForm_Activate()
ListBox1.MultiSelect = fmMultiSelectSingle
ListBox2.MultiSelect = fmMultiSelectExtended
Dim i As Integer
For i = 1 To 15
ListBox1.AddItem String(i, Chr(i + 64))
ListBox2.AddItem String(i, Chr(i + 64))
Next
End Sub
Is there a way to remove the focus rectangles or prevent their appearing?
Thanks,
I have experimented with your code in Excel 2010 and confirm your observation. If I create two list boxes, enter the code provided, start the form and press tab to focus on ListBox2, the dotted lines appear around all rows.
If I create the two list boxes as before, manually set ListBox2/Properties/Multiselect to 2 - fmMultiSelectExtended, run and tab to ListBox2 the nasty lines disapperar.
For me this is rather stable, the form now survives multiple window activation changes, jumpng back/forth etc.
don't ask me why ...

Resources