Adding information to a combo box

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
noelhcar
Newbie
Posts: 4
Joined: Sat Jun 29, 2013 12:33 pm

Adding information to a combo box

Post by noelhcar » Wed Apr 22, 2015 4:57 pm

Dear All,

I want to extract info from an excel file and get a combo box to show the information. The code I wrote is not working as the combox show "<array>" which means it recognises it is an array but does not show the info needed. The code is below:

Any help would be appreciated
-------------------
//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

Dialog>Dialog1
object Dialog1: TForm
Left = 247
Top = 119
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 191
ClientWidth = 457
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object MSComboBox1: tMSComboBox
Left = 141
Top = 53
Width = 145
Height = 21
TabOrder = 0
end
object MSButton1: tMSButton
Left = 131
Top = 113
Width = 75
Height = 25
Caption = 'OK'
Default = True
ModalResult = 25
TabOrder = 1
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton2: tMSButton
Left = 216
Top = 112
Width = 75
Height = 25
Caption = 'Cancel'
ModalResult = 23
TabOrder = 2
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1

ArrayDim>cellinfo,5


XLOpen>C:\Documents and Settings\montoyan\Desktop\try.xls,1,tryhandle

let>xi=1
repeat>xi
XLGetCell>tryhandle,sheet1,%xi%,1,cellinfox
let>cellinfo_%xi%=cellinfox
if>cellinfo_%xi%=,outofloop
let>xi=%xi%+1
Until>xi=2000

label>outofloop

//MessageModal>%cellinfo_1% - %cellinfo_2% - %cellinfo_3% - %cellinfo_4% - %cellinfo_5%

SetDialogProperty>Dialog1,MSComboBox1,ListText,%cellinfo%

show>Dialog1,resp

XLQuit>tryhandle

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Adding information to a combo box

Post by Marcus Tettmar » Wed Apr 22, 2015 6:19 pm

Hi,

The ListText property requires a list delimited by line breaks. See:

https://www.mjtnet.com/manual/index.htm ... erties.htm

So you could do something like:

Code: Select all

Let>theList={""}
Let>xi=1
Repeat>xi
  XLGetCell>tryhandle,sheet1,%xi%,1,cellinfox
  If>cellinfox=,outofloop
  Let>theList=%theList%%cellinfox%CRLF%
  Let>xi=%xi%+1
Until>xi=2000
label>outofloop

Trim>theList,theList

SetDialogProperty>Dialog1,MSComboBox1,ListText,theList
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

noelhcar
Newbie
Posts: 4
Joined: Sat Jun 29, 2013 12:33 pm

Re: Adding information to a combo box

Post by noelhcar » Thu Apr 23, 2015 1:09 pm

Many thanks for your help. I tried and worked. Only one thing to correct:

In the line
Let>theList=%theList%%cellinfox%CRLF%

it must have another "%" before CRLF otherwise it will not work

Let>theList=%theList%%cellinfox%%CRLF%

Thanks Marcus. Alway great help

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts