Jump to content

Recommended Posts

:D

I have created a script that reads in a text file containing simple lines of text. Of course each line of text has an index number associated with it. The script creates a GUI with a listbox containing the lines of data from the text file. When I click on a line in the listbox, the script returns the index number of that line and closes the GUI. I can then test that number and branch the script as required. This is the behavior I want. The only problem I have is that the listbox INSISTS on doing an ASCII sort on the contents of the box. Since I am using the listbox to display a selection menu that can be easily created on the fly, it makes it difficult to create a formatted menu. How do I keep the box from sorting the contents?

The code I use is included below:

The wait until a 254 is received just keeps the script looping until an allowed exit code is received.

Any help would be gratefully appreciated.

****** The include file **********************8

#include-once

Func MenuSelect($Title)

#include "GUIConstants.au3"

Local $file

Local $line

Local $menudata

Local $lstItems

Local $n

Local $t

Local $cmdClose

Local $cmdExit

Local $ctr1

local $ctr2

Local $text1

Local $select

local $MenuLen

local $testchar

local $holdpos

local $IndexNum

$menudata=""

If $Title = "" Then $Title = "Select Menu"

$file = FileOpen(@Scriptdir & "\Menu.dat", 0)

;Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open menu file.")

Return 254

EndIf

$ctr1 = 0

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

if $ctr1 > 0 then $menudata = $menudata & "|"

$menudata = $menudata & $line

$ctr1=$ctr1 + 1

Wend

FileClose($file)

GUICreate($Title,390,230); will create a dialog box that when displayed is centered

$lstItems= GUISetControl("list", "$text1", 5,5,381,160,)

GuiSetControlData($lstItems,$menudata)

$cmdClose = GUISetControl("button", "Select", 100,170,175,20)

GUISetControlNotify($cmdClose)

$cmdExit = GUISetControl("button", "Exit", 100,200,175,20)

GUISetControlNotify($cmdExit)

GUISetControlNotify($lstItems)

$n=0

While GUIMsg() > 0

$n=$n+1

$t = GUIRead()

$menulen = StringLen($menudata)

$indexnum = 0

for $ctr2 = 1 to $menulen

$testchar = StringMid($menudata,$ctr2,1)

Select

Case $testchar = "|"

$indexnum = $indexnum + 1

Case Else

EndSelect

next

if $indexnum = 0 then return(255)

if $indexnum > 0 then $indexnum = $indexnum + 1

local $IndexList[$indexnum]

Select

Case $t = $cmdClose

$ctr2 = 0

$IndexList[0] = ""

for $ctr1 = 1 to $menulen

$testchar = StringMid($menudata,$ctr1,1)

select

Case $testchar = "|"

$ctr2=$ctr2 + 1

$indexlist[$ctr2] = ""

Case Else

$indexlist[$ctr2] = $indexlist[$ctr2] & $testchar

EndSelect

next

$select = GUIRead( $lstItems)

local $result

for $ctr2 = 0 to ubound($indexlist)-1

if $indexlist[$ctr2] = $select then $result = $ctr2 + 1

next

Return($result)

Case $t = $cmdExit

Return(254)

Case $lstItems

$ctr2 = 0

$IndexList[0] = ""

for $ctr1 = 1 to $menulen

$testchar = StringMid($menudata,$ctr1,1)

select

Case $testchar = "|"

$ctr2=$ctr2 + 1

$indexlist[$ctr2] = ""

Case Else

$indexlist[$ctr2] = $indexlist[$ctr2] & $testchar

EndSelect

next

$select = GUIRead( $lstItems)

local $result

for $ctr2 = 0 to ubound($indexlist)-1

if $indexlist[$ctr2] = $select then $result = $ctr2 + 1

next

Return($result)

Case Else

EndSelect

Wend

EndFunc

****************** Now the actual script code **************************

AutoItSetOption("MustDeclareVars", 1)

#include "John's.au3"

Dim $SelectVal

Dim $CDRoot

Dim $MenuFile

Dim $RunMe

Dim $passwd

Dim $PassMess

$passmess = "This will install the F-Secure registry key fix for the F-Nimda Virus. "

$passmess = $passmess & "Unintentional registry modification is something to avoid "

$passmess = $passmess & "if at all possible. "

$passmess = $passmess & "Are you sure you want to install the registry fix? "

$passmess = $passmess & "Type 'RUN' to continue, or click 'Cancel' to quit."

Do

$selectval = menuselect("F-Nimda Stuff")

Select

Case $SelectVal = 1

GuiHide()

RunWait(@ComSpec & " /c " & 'shellfix.txt', @ScriptDir, @SW_HIDE)

GuiShow()

WinActivate("Select Menu")

Case $SelectVal = 2

GuiHide()

$passwd = InputBox("Final chance to quit!", $passmess, "", "*")

Select

Case $passwd = ""

GuiShow()

WinActivate("Select Menu")

Case StringUpper($passwd) = "RUN"

RunWait(@ComSpec & " /c " & 'shellfix.reg', @ScriptDir, @SW_HIDE)

GuiShow()

WinActivate("Select Menu")

Case Else

EndSelect

Case $SelectVal = 3

Exit

EndSelect

Until $SelectVal = 254

Link to post
Share on other sites

Feel free to "vote" here: http://www.autoitscript.com/forum/index.php?showtopic=3021

$lstItems= GUISetControl("list", "$text1", 5,5,381,160,0xA30001)

; Style was determined as follows:

; Technically these should be BitOR'ed together...

; $LBS_NOTIFY + $WS_VSCROLL + $WS_BORDER + $WS_TABSTOP + $WS_GROUP

; 0x1 + 0x200000 + 0x800000 + 0x10000 + 0x20000

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...