writetoashishp
Posts: 1
Joined: Sun Apr 28, 2013 9:43 pm

How to read the selected ComboBox "Text" and "value"

Hello Friends

After much searching, found the link to populate (with script) the combox for my project.

Problem:
However, after populating, i want to fetch the selected combox box "text" and "value" in two variables - Please let me know the sample code to do so?

Expecting a very quick reply.

Note: I am unable to use the custom action, Kindly provide the example or a sample project/script (code/attachement):
Session.DoAction("ExtractComboBoxData")


Thanking in Advance.
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How to read the selected ComboBox "Text" and "value"

Hello and welcome to Advanced Installer forums,

Thank you for your interest in Advanced Installer.

In order to achieve what you want you can use our "ExtractComboBoxData" predefined custom action to extract all combo box items (extracted in "AI_COMBOBOX_DATA" property). Then, you can create your own custom action wich will parse the "AI_COMBOBOX_DATA" property content and will extract selected item text and value. Also, please keep in mind that a combo box property is always set with its selected item value.

Here are the steps to proceed:
- Go to "Dialogs" page and add your combo box control (e.g. COMBO_PROP).
- Go to "Custom Actions" page and add our "Extract combo box data" custom action without sequence.
- Add a "Launch attached file" custom action without sequence (e.g. ExtractSelectedItem) using a VBS file like this:

Code: Select all

Dim comboBox
Dim selectedItemValue, selectedItemText
  
comboBox = Session.Property("AI_COMBOBOX_DATA")
selectedItemValue = Session.Property("COMBO_PROP")

itemsArray = Split(comboBox, "|", -1)

For Each item In itemsArray
	tempItem=Split(item,"#")
    If (tempItem(0) = selectedItemValue) Then
      selectedItemText = tempItem(1)   
    End if
Next

Session.Property("COMBO_VALUE") = selectedItemValue
Session.Property("COMBO_TEXT") = selectedItemText
which will save the selected item value and text in two installer properties (COMBO_VALUE and COMBO_TEXT).

- Go to "Dialogs" page and on [Next>] button (of your combo box dialog) add the following published events:
  • Event: [AI_COMBOBOX_DATA]
    Argument: COMBO_PROP

    Event: Execute custom action
    Argument: ExtractComboBoxData

    Event: Execute custom action
    Argument: ExtractSelectedItem
- Build and run your project.

Also, here's attached a sample, created with version 10.0 of Advanced Installer, which implements a similar scenario.
sample.zip
(4.13 KiB) Downloaded 848 times
If you have any questions let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
cpatterson
Posts: 11
Joined: Tue Feb 03, 2015 3:23 pm

Re: How to read the selected ComboBox "Text" and "value"

Hi, Daniel, I have Enterprise Edition 9.4, and I can't open this aip file. Is it possible for you to build this same aip file in an older AI version and upload it here? Thanks!
johnson5
Posts: 1
Joined: Wed Apr 08, 2015 11:07 am

Re: How to read the selected ComboBox "Text" and "value"

I do not know about how to Read the Selected Combo Box "Text" as well as "Value".
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How to read the selected ComboBox "Text" and "value"

Hello,

I've attached a sample created with AI 9.4 version.
sample.zip
(3.56 KiB) Downloaded 663 times
If you have any questions let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: How to read the selected ComboBox "Text" and "value"

You're welcome.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Abhinay
Posts: 36
Joined: Wed Feb 27, 2019 9:33 am

Re: How to read the selected ComboBox "Text" and "value"

Hi,

I Need a vb script so that i want to write the text entered in combo box by user during installation to the json file or a text file.

For example:
Dim comboBox
Dim selectedItemValue, selectedItemText

comboBox = Session.Property("AI_COMBOBOX_DATA")
selectedItemValue = Session.Property("COMBO_PROP")

itemsArray = Split(comboBox, "|", -1)

For Each item In itemsArray
tempItem=Split(item,"#")
If (tempItem(0) = selectedItemValue) Then
selectedItemText = tempItem(1)
End if
Next

Session.Property("COMBO_VALUE") = selectedItemValue
Session.Property("COMBO_TEXT") = selectedItemText

Set FSO=CreateObject("Scripting.FileSystemObject")
Set outFile = FSO.CreateTextFile(outfile,True)
for i=1 to 2
outFile="C:\Users\AppData\Roaming\"
outFile.WriteLine "COMBO_VALUE"
outFile.WriteLine "COMBO_TEXT"
Catalin
Posts: 7492
Joined: Wed Jun 13, 2018 7:49 am

Re: How to read the selected ComboBox "Text" and "value"

Hello Abhinay,

I have answered your main thread here:

viewtopic.php?f=2&t=36843&p=102964&sid= ... a2#p102964

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”