Page 1 of 1 1
Topic Options
#92615 - 2003-08-15 02:24 AM KixForms Question - ListBox Problem
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Hi Everyone

I am going mad trying to get this basic script to work.

Ok here is the problem, I have a Listview and have inserted the following objects: PC1, PC2, PC3.

Now say I want to have a 'Insert Box' that enters data into the Listview, and in this insert box I type PC1.

I want it to check that PC1 is not already in the Listview already.

I have tried a loop on the ListCount and then Additem if Insert.Text is not the same as List($Loop), but it just repeast it self and I get 20 odd additems.

code:
Function sExcludedListAdd_Click()

If $sExcludedInput.Text = ""
$= $FORM.MsgBox("Invalid Netbios Name","Error")
Else
$x = $sExcludedList.ListCount -1
For $Loop = 0 to $x
If $sExcludedInput.Text = $sExcludedList.List($Loop)
$= $FORM.MsgBox("("+$sExcludedInput.Text") is already in the Excluded List","Error")
Else
$sExcludedList.AddItem($sExcludedInput.Text)
EndIf
Next
EndIf


EndFunction

I just don't know how to do this. ???

Any Ideas.

Thanks

[ 15. August 2003, 12:13: Message edited by: Richard Farthing ]

Top
#92616 - 2003-08-15 02:32 AM Re: KixForms Question - ListBox Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
listview is little complex...
you could do a array in the listviews .tag

this way, all you need to do is:
code:
if 0>ascan($listview.tag)
"not in list yet"
else
"in da list"
endif

_________________________
!

download KiXnet

Top
#92617 - 2003-08-16 12:07 AM Re: KixForms Question - ListBox Problem
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Sorry I am so dumb, I meant ListBox [Big Grin] .

How would I put the contents of a Listbox into an array. ??.

So then I can do something like this:

code:
	If AScan($sExcludedList,$sExcludedInput.Text) = 1
$= $FORM.MsgBox("("+$sExcludedInput.Text") is already in the Excluded List","Error")
Else
$sExcludedList.AddItem($sExcludedInput.Text)
EndIf


Top
#92618 - 2003-08-16 12:38 AM Re: KixForms Question - ListBox Problem
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
for each $item in $listbox.items
if $item.text=" "

endif
next
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#92619 - 2003-08-16 12:51 AM Re: KixForms Question - ListBox Problem
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
It don't like that, as soon as I do that it just bombs out the script no error.

code:
For Each $Item In $sExcludedList.Items
? $Item.Text
Next


Top
#92620 - 2003-08-16 12:55 AM Re: KixForms Question - ListBox Problem
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
You could achieve this easily if only the .List property was already readable; Silly enough it's still write-only [Frown]

So you need to workaround that by evaluating the items using the .ListCount property and setting the ListIndex for each Item ... errr just like :


;...
dim $list
for $i = 0 to $lst.ListCount-1
$lst.ListIndex = $i
$list = $list + $lst.Text
if $i < $lst.ListCount - 1
$list = $list + ","
endif
next
$list = split($list)
;...


[ 15. August 2003, 13:01: Message edited by: Jochen ]
_________________________



Top
#92621 - 2003-08-15 01:00 PM Re: KixForms Question - ListBox Problem
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Rad,

the items collection is not available for ListBoxes, only for ListViews [Frown]
_________________________



Top
#92622 - 2003-08-15 01:13 PM Re: KixForms Question - ListBox Problem
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Thanks Jochen your bit works like a dream, just the AS part now, does that look right as it is not finding the PC-01 in the array?

code:
	Dim $List	

For $Loop = 0 to $sExcludedList.ListCount-1

$sExcludedList.ListIndex = $Loop
$List = $List + $sExcludedList.Text
If $Loop < $sExcludedList.ListCount - 1
$List = $List + ","
EndIf
Next

$xArray = Split($List,",")

If AScan($xArray,$sExcludedInput.Text) = 1
? $sExcludedInput.Text + ' is Present.'
Else
? $sExcludedInput.Text + ' is NOT Present.'
EndIf


Top
#92623 - 2003-08-15 01:18 PM Re: KixForms Question - ListBox Problem
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
ascan() returns the ArrayIndex of the found item or -1 if not in array [Wink]

so your line should be :

If AScan($xArray,$sExcludedInput.Text) > 0

[ 15. August 2003, 13:20: Message edited by: Jochen ]
_________________________



Top
#92624 - 2003-08-15 01:29 PM Re: KixForms Question - ListBox Problem
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Thank You Everyone all working.

code:
If $sExcludedInput.Text = ""
$= $FORM.MsgBox("Invalid Netbios Name","Error")
Else
Dim $List

For $Loop = 0 to $sExcludedList.ListCount-1

$sExcludedList.ListIndex = $Loop
$List = $List + $sExcludedList.Text
If $Loop < $sExcludedList.ListCount - 1
$List = $List + ","
EndIf
Next

$xArray = Split($List,",")

If NOT AScan($xArray,$sExcludedInput.Text) = "-1"
$= $FORM.MsgBox('('+$sExcludedInput.Text+') is already In the Excluded List','Error')
Else
$sExcludedInput.Text = Ucase($sExcludedInput.Text)
$sExcludedList.AddItem($sExcludedInput.Text)
EndIf

$sExcludedInput.Text = ""


Top
#92625 - 2003-08-15 01:34 PM Re: KixForms Question - ListBox Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
j, your line is wrong.
it actually should be:
code:
If not AScan($xArray,$sExcludedInput.Text) < 0

or shorter:
code:
If AScan($xArray,$sExcludedInput.Text) > -1

_________________________
!

download KiXnet

Top
#92626 - 2003-08-15 01:46 PM Re: KixForms Question - ListBox Problem
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
yep thanks sorted
Top
#92627 - 2003-08-15 01:48 PM Re: KixForms Question - ListBox Problem
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Here is a code snippet.

code:
			$lblServiceType = $frmServiceDetail.Label()
$lblServiceType.Text = "Service Type"
$lblServiceType.Location = $iMargin, $lblStartName.Bottom + $iMargin
$lblServiceType.Size = $ilblMediumWidth, $iHeight
$cboServiceType = $frmServiceDetail.ComboBox()
$cboServiceType.Location = $lblServiceType.Right + $iMargin, $lblServiceType.Top
$cboServiceType.Size = $itxtLargeWidth, $iHeight
$cboServiceType.Enabled = 0
$cboServiceType.Style = 1
$Nul = $cboServiceType.AddItem("Own Process")
$Nul = $cboServiceType.AddItem("Share Process")
$Nul = $cboServiceType.AddItem("Interactive Process")
$Nul = $cboServiceType.AddItem("Kernel Driver")
$Nul = $cboServiceType.AddItem("File System Driver")
$Nul = $cboServiceType.AddItem("Adapter")
$Nul = $cboServiceType.AddItem("Recognizer Driver")
FOR $Index = 0 TO $cboServiceType.ListCount - 1
$cboServiceType.ListIndex = $Index
IF $cboServiceType.Value = $objService.ServiceType
$Index = $cboServiceType.ListCount
ENDIF
NEXT

If I underestand the question, this is the part that will hopefully help. I use it to find the active value, but you could also use it for excluding aready entered values.
code:
			FOR $Index = 0 TO $cboServiceType.ListCount - 1
$cboServiceType.ListIndex = $Index
IF $cboServiceType.Value = $objService.ServiceType
$Index = $cboServiceType.ListCount
ENDIF
NEXT

_________________________
Kelly

Top
#92628 - 2003-08-15 01:51 PM Re: KixForms Question - ListBox Problem
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Jlo,

I must wonder :

quote:
j, your line is wrong.
it actually should be:

code:
--------------------------------------------------------------------------------

If not AScan($xArray,$sExcludedInput.Text) < 0

What is the difference (logical) between yours and mine ?

'not < 0' equals '> 0' If I am not completely lost in higher math [Confused]
_________________________



Top
#92629 - 2003-08-15 01:53 PM Re: KixForms Question - ListBox Problem
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Ah ok,

just forgot one little but vital thing ,

I meant of course '>= 0' [Roll Eyes]

[ 15. August 2003, 13:54: Message edited by: Jochen ]
_________________________



Top
#92630 - 2003-08-15 01:58 PM Re: KixForms Question - ListBox Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hehee [Big Grin]
got ya!

feels good to have something to note to the big captain [Wink]
_________________________
!

download KiXnet

Top
#92631 - 2003-08-15 02:00 PM Re: KixForms Question - ListBox Problem
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
lol!

Quite easy these days [Mad]

[Big Grin]
_________________________



Top
#92632 - 2003-08-15 02:11 PM Re: KixForms Question - ListBox Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I understand you.
they took away your coffee waitress at work and even the psychological breathing hole kforg BBS has been down...

no wonder you are totally messed up [Big Grin]
_________________________
!

download KiXnet

Top
#92633 - 2003-08-15 03:06 PM Re: KixForms Question - ListBox Problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I normally use
code:
IF AScan($xArray,$sExcludedInput.Text)+1
ENDIF

_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2175 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.076 seconds in which 0.044 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org