 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Fri Nov 27, 2009 9:57 am Post subject: To get contents before = sign in INI file |
|
|
with the below code i am able to read the contents of the ini file after the = sign...now what i want is to read the contents of the ini file before the sign and use this content for my next step like opening a file
my test.ini file is like this:-
[Production]
C:\Programfiles\Mywork\=Hello
C:\Programfiles\Exwork\=Welcome
| Code: | loop, read, C:\Documents and Settings\Devil\Desktop\test.ini
{
if a_loopreadline contains =
{
StringSplit, buttonname, a_loopreadline, =
Gui, Add, Button,w200 h50, %buttonname2%
}
}
gui show
|
so from the above code i am able to display hello and welcome on gui but i am not getting any idea of extracting the content before the = sign in the test.ini file like C:\Programfiles\Mywork |
|
| Back to top |
|
 |
hd0202
Joined: 13 Aug 2006 Posts: 174 Location: Germany
|
Posted: Fri Nov 27, 2009 10:08 am Post subject: Re: To get contents before = sign in INI file |
|
|
after the StringSplit, you will find it in buttonname1
Hubert |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 27, 2009 10:15 am Post subject: |
|
|
| sorry to say but i didnt got want you mean to say i am still confused can tell me where to make changes so tht i will get both the contents (C:\Programfiles\Mywork & C:\Programfiles\Exwork) displayed after the GUI displays Hello and Welcome |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 27, 2009 10:17 am Post subject: |
|
|
thanks a lot for the reply....but sorry to say that i didnt got want you mean to say i am still confused can tell me where to make changes so tht i will get both the contents (C:\Programfiles\Mywork & C:\Programfiles\Exwork) displayed after the GUI displays Hello and Welcome
as one of our ahk member helped me with this read function so i am bit confused with button1,2.....and why it is mentioned as %buttonname2% |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 27, 2009 10:21 am Post subject: |
|
|
| sorry to disturb again but by putting buttonname1 i got for the first button as C:\Programfiles\Mywork but for the next button i got Welcome why not C:\Programfiles\Exwork ??? |
|
| Back to top |
|
 |
hd0202
Joined: 13 Aug 2006 Posts: 174 Location: Germany
|
Posted: Fri Nov 27, 2009 10:35 am Post subject: |
|
|
please show your changed script, so that we can help
Hubert |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 27, 2009 10:40 am Post subject: |
|
|
hey cool its working now i mean all before the = sign.....thanks a lot man
so the for now the script is like this
| Code: |
Loop, read, C:\Documentsand settings\Devil\Desktop\test.ini
{
if a_loopreadline contains =
{
StringSplit, buttonname, a_loopreadline, =
Gui, Add, Button,buttonname w200 h50, %buttonname1%
}
}
gui show
Return
Button%buttonname1%:
run notepad.exe
|
so is it possible to define actions for this button like if i press first button it should run notepad.exe and if i press second it should run calc.exe ???
because in the above code i added this but it didnt worked and i dont know how to identity the button 1 is pressed or 2??? |
|
| Back to top |
|
 |
hd0202
Joined: 13 Aug 2006 Posts: 174 Location: Germany
|
Posted: Fri Nov 27, 2009 10:54 am Post subject: |
|
|
here is my solution. hava a look at the parts marked in red:
| Code: | Loop, read, C:\Documentsand settings\Devil\Desktop\test.ini
{
if a_loopreadline contains =
{
ind++
StringSplit, buttonname, a_loopreadline, =
Gui, Add, Button, gbuttonname%ind% w200 h50, %buttonname1%
}
}
gui show
Return
buttonname1:
run notepad.exe
return
buttonname2:
run calc.exe
return |
Hubert |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 27, 2009 10:59 am Post subject: |
|
|
ok i will try to explain it more clearly
I want to create my project more generic so that anyone who wants to make changes then he has to do it only in .ini file not in the autohotkey script....
so what i am doing is if i make a ini file with two buttons as Paint and Notepad...if the user clicks paint it should open paint and also when he clicks Notepad it should open notepad....i know we can do it in a simple way as:-
| Code: |
Gui, Add, Button, w186 h49,Paint
Gui, Add, Button, w186 h49,Notepad
Gui,show
Return
ButtonPaint:
run mspaint.exe
return
ButtonNotepad:
run notepad.exe
return
|
but as i said i want to do it at runtime that is when the user makes changes in the .ini file and adds one more button as Word the gui should show this update(and with all your help i am able to do this) but how to execute the function related to that button i.e. word.exe that is their should be some loop like
| Code: |
Button%button%: ; paint,word,calculator
run ..... ; this should know that which button is pressed and for that button what action is defined in .ini file.....
that is if he press paint then mspaint.exe should run or if word is pressed then word.exe should run
Sorry for irritating but i am in desperate need of it
Thanks a lot for reading and your concerns
|
|
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 27, 2009 11:07 am Post subject: |
|
|
well brother its giving error at
Gui, Add, Button, gbuttonname%ind% w200 h50, %buttonname1%
specifically the error is at:-gbuttonname1 |
|
| Back to top |
|
 |
hd0202
Joined: 13 Aug 2006 Posts: 174 Location: Germany
|
Posted: Fri Nov 27, 2009 11:25 am Post subject: |
|
|
| Anonymous wrote: | | well brother its giving error |
well brother, but sorry again, please show your changed script and the given error message, so that we can help
we are no clairvoyants (in german: Hellseher)
Hubert |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 27, 2009 11:31 am Post subject: |
|
|
ok no problem here is the script
| Code: |
Loop, read, C:\Documents and Settings\Devil\Desktop\test.ini
{
if a_loopreadline contains =
{
ind++
StringSplit, buttonname, a_loopreadline, =
Gui, Add, Button,gbuttonname%ind% w200 h50, %buttonname1%
}
}
gui show
Return
buttonname1:
run notepad.exe
|
and the error is
Specifically: gbuttonname1
008: Gui, Add, Button,gbuttonname%ind% w200 h50, %buttonname1% |
|
| Back to top |
|
 |
hd0202
Joined: 13 Aug 2006 Posts: 174 Location: Germany
|
Posted: Fri Nov 27, 2009 11:45 am Post subject: |
|
|
sorry, but when I use your code mentioned above, I get:
| Code: |
Error: Target label does not exist. The current thread will exit.
Specifically: gbuttonname2 | and that is totally understandable, as you create 2 buttons and therefor you must have 2 labels too.
Hubert |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 27, 2009 11:53 am Post subject: |
|
|
ya thats right because with one button it runs successfully but two posting before you can see what i expect like if there are two buttons like paint and word and if the user press button 1 then it should execute the information mentioned in the ini file
for example:-
test.ini
[Production]
Paint=run paint.exe
Word=run word.exe
on gui it displays Paint and Word but how to append the action related to each button or in other case to display paint.exe or word.exe if i press paint and word respectively |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 27, 2009 12:10 pm Post subject: |
|
|
well if you see the test runs successfully with one entry in the ini and one button display on the Gui and i can send the information related to that button which is mentioned in the inifile but when i want to add one more button on the gui and want to follow the same procedure then do i have to write the code twice or their is some way of settingup a variable which will montior which button and then append the action....i think this is the last step and then i will succeed
| Code: |
Run Notepad.exe
WinWaitActive Untitled - Notepad
Loop, read, C:\Documents and Settings\Devil\Desktop\test.ini
{
if a_loopreadline contains =
{
ind++
StringSplit, buttonname, a_loopreadline, =
Gui, Add, Button,gbuttonname%ind% w200 h50, %buttonname1%
}
}
gui show
Return
buttonname1:
run notepad.exe
Untitled - Notepad
sleep 500
Loop, read, C:\Documents and Settings\Devil\Desktop\test.ini
{
if a_loopreadline contains =
{
ind++
StringSplit, buttonname, a_loopreadline, =
Send %buttonname2%
}
}
sleep 500
Return
|
test.ini
[Production]
Notepad=Hi how are you
and if i add one more
test.ini
[Production]
Notepad=Hi how are you
Word=Welcome
then do i have to write a separatecode for this button??? |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|