Sign in to follow this  
Followers 0
strate

Creating a menu

5 posts in this topic

Has anybody found a way to create a menu from a notepad list or any list for that matter?


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites



Yea, I'm sorry......

In a previous thread of mine I requested help with .INI files. Through the help received I finished that task and now want to create it so the user can remove a line of text.

Sample of file

[Path 1]

key=Zebra 140XI III on LPT2

[Path 2]

key=Zebra 140XI II on LPT1

[Path 3]

key=Zebra 170XI III on LPT3

[Path 4]

key=Zebra 170XI III on LPT4

IniDelete will delete the need path for me but the user needs to know what the path is either 1,2,3, or 4. The list is ever expanding (or decreasing) so hard code wouldn't work well. This is the code

$File = "G:\Projects\AutoIt V3\Prod. Recording\printers.ini"

$CP = 0

$C = 0

$RL = 1

While 1

$line = FileReadLine($file,$RL)

msgbox(1,"",$Line)

$RL = $RL + 1

If $Line = "" Then Exitloop

Wend

$NumofPaths = InputBox("Label Creation","How many paths would you like to create:")

Do

$C = $C + 1

$PrinterPath = InputBox("Label Creations","Please input printer path you would like to eliminate:")

;;;;;;;;;; Need to know Path (section) number;;;;;;;;;

IniDelete($file, $path,"key")

Until $C = $NumofPaths

I would like the menu to display with/inside the input box.

A solution like this:

$Path = InputBox("Label Creation"," Please choose from the following:"&@CR & @CR&"1. Zebra 140XI III on LPT2" & @CR&"2. Zebra 140XI II on LPT1"& @CR&"3. Zebra 170XI III on LPT3"& @CR&"4. Zebra 170XI III on LPT4"&@CR&@CR&"Enter Printer Path:","","",-1,260,-1,-1)

wouldn't be feasible.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

You can hard code it in, but just do it with a loop.

[Path 1]key=Zebra 140XI III on LPT2

[Path 2]

key=Zebra 140XI II on LPT1

[Path 3]

key=Zebra 170XI III on LPT3

[Path 4]

key=Zebra 170XI III on LPT4

This would grab all the keys, if you had missing ones in between, you could make a better test.

Dim $var[101]
$printertext=@crlf
for $i=1 to 100; you could do 1000 if you like, or read the amount of lines in the file.
$var[$i] = IniRead("C:\Temp\myfile.ini", "Path "& $i, "key", "NotFound")
if $var[$i]="NotFound" then continueloop
$count=$i-1
$printertext=$printertext&$i&" - "& $var[$i]& @crlf
next


$PrinterPath = InputBox("Label Creations","Please input printer path you would like to eliminate:"& $printertext)
IniDelete("C:\Temp\myfile.ini", "Path "& $PrinterPath,"key")

Just an adaption of your code and help file.

If you were only going to use this for printer lines, you could do the count, but try this out for removal. Think of diferent aproaches, one may really come in handy some day.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Oh, talking about InI files, I would have organised it more like this:

[PrinterPath]path1=Zebra 140XI III on LPT2

path2=Zebra 140XI II on LPT1

path3=Zebra 170XI III on LPT3

path4=Zebra 170XI III on LPT4

Sample code:

$x="Zebra 140XI III on LPT2|Zebra 140XI II on LPT1|Zebra 170XI III on LPT3|Zebra 170XI III on LPT4"
$xarray=Stringsplit($x,"|")

for $i = 1 to $xarray[0]
IniWrite("C:\Temp\myfile.ini", "PrinterPath", "Path"& $i, $xarray[$i])
next

Ini files can be great tools, with easy to read files in notepad or any other editor, but organising them helps a lot.

Ex file:

[PrinterPath]path1=Zebra 140XI III on LPT2

path2=Zebra 140XI II on LPT1

path3=Zebra 170XI III on LPT3

path4=Zebra 170XI III on LPT4

[users]

user1=bob

user2=fred

user3=strate

and changed code to show one way of retrival and elimination.

$var=""
$printertext=@crlf
for $i=1 to 100; you could do 1000 if you like, or read the amount of lines in the file.
$var= IniRead("C:\Temp\myfile.ini", "PrinterPath", "path"& $i, "NotFound")
if $var="NotFound" then continueloop
$count=$i-1
$printertext=$printertext&$i&" - "& $var& @crlf
next

$PrinterPath = InputBox("Label Creations","Please input printer path you would like to eliminate:"& $printertext)
IniDelete("C:\Temp\myfile.ini","PrinterPath", "Path"& $PrinterPath)
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

This is what I use for a menu system to reach my various hot files.

http://www.autoitscript.com/fileman/users/public/Condoman/LicenseLinkNG.jpg

The code is here: http://www.autoitscript.com/fileman/users/public/Condoman/LicenseLinkNG.au3

And yes I know some menu items are mispelled

:)

Share this post


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
Sign in to follow this  
Followers 0