AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

dynamic form creation from a ini file

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
eagle00789



Joined: 27 Nov 2006
Posts: 52
Location: Heerlen Country: Netherlands

PostPosted: Fri Sep 21, 2007 9:16 am    Post subject: dynamic form creation from a ini file Reply with quote

I have the following small inifile
Code:

[bus]
aantal=10
1=SCC
2=Emma
3=ABB (boschstraat)
4=Intratuin Heerlen (In de Kramer)
5=Intratuin Kerkrade (Wiebachstraat)
6=Groen
7=Schoonmaak
8=Facilitair
9=Metaal
10=J. Defauwese
11=Emma P-Functie

[2]
aantal=25
1=4410100
2=4410230
3=4410240
4=4410510
5=4410250
6=4410300
7=4410410
8=4410420
9=4410430
10=4410600
11=4410610
12=4410620
13=4410800
14=4410810
15=4410820
16=4411010
17=4411020
18=4411021
19=4411030
20=4411040
21=4411050
22=4411060
23=4430230
24=4430240
25=4509700

[4]
aantal=4
1=4431112
2=4431134
3=4431161
4=4431162

[5]
aantal=7
1=4431222
2=4431234
3=4431238
4=4431239
5=4431241
6=4431250
7=4431262

[10]
aantal=1
1=4431152

[11]
aantal=3
1=4430230
2=4430240
3=4509700

From the section bus is the section where i get the info to create some radiobuttons on my form.
this is my ahk-file
Code:
;zet de inifile variable goed.
Inifile = bus.ini
;krijg het huidige weeknummer
StringRight, Week, A_YWeek, 2
;verspring naar de volgende week
Week++
;Verkrijg een lijst met alle beschikbare geinstalleerde printers
InstalledPrinters := GetInstalledPrinters()
;maak een dialoogvenster
;voeg tekst aan het dialoogvenster toe
Gui, Add, Text,, Kies uw Business Unit...
;voeg radioknoppen toe aan het dialoogvenster
;Zet een herhaalwaarde voor de gegevens uit de bus.ini
Looping=1
;Haal de gegevens voor welke bu's uit de bus.ini
IniRead, RepTimesBus, %Inifile%, bus, aantal
;Herhaal het volgende gedeelte een X aantal maal. X staat gelijk aan aantal uit de bus.ini
Loop %RepTimesBus%
{
;Lees de BU
IniRead, Bus, %Inifile%, bus, %Looping%
;Als de BU de eerste is die gelezen wordt
if %RepTimesBus% = 1
{
;Dan moet er iets meer aan de radioknop worden toegevoegd.
Gui, Add, Radio, group vBU gBusinessUnit, %Bus%
}
else
{
;anders is een gewone radioknop voldoende
Gui, Add, Radio, gBusinessUnit, %Bus%
}
;Verhoog de herhaalwaarde met 1
Looping++
}
Gui, Add, Text,,Weeknummer
;Hoogteberekening voor het onderstaande textvak
;Hoogte=(aantal bu's maal 19) plus 22
Hoogte=%RepTimesBus%
Hoogte*=19
Hoogte+=22
;voeg een textvak aan het dialoogvenster toe (-19)
Gui, Add, Edit, w155 x85 y%Hoogte% vWeekNummer, %Week%
;begin een nieuwe radioknoppen groep
Gui, Add, Radio, group x10 vPerPagina Checked, Per Persoon Per pagina
Gui, Add, Radio,, Meerdere Personen Per pagina
Gui, Add, Text,,Printer
;Maak een dropdownlist met daarin alle beschikbare printers. de standaard printer zal ook hier reeds als keuze ingesteld staan.
Gui, Add, DropDownList, w230 vPrinterChoice, %InstalledPrinters%
;Hoogteberekening voor de onderstaande knoppen OK en Annuleren
;Hoogte=(aantal bu's maal 19) plus 132
Hoogte=%RepTimesBus%
Hoogte*=19
Hoogte+=132
;zet de standaard ok en annuleren knoppen op het formulier
Gui, Add, Button, w100 x25 y%Hoogte% Disabled gOK, OK
Gui, Add, Button, Default x130 y%Hoogte% w100 gAnnuleren, Annuleren
;laat het formulier zien
Gui, Show, w250, Business Unit
Gui +LastFoundExist  ;Zet de GUI window als laatst gevonden
GUIhWnd := WinExist()  ;Verkrijg Laatst gevonden Window Handle
SC_MyMenuItem1 = 0x1001  ;Extra Info
sMyMenuCaption1=Info...  ;Extra Info
hSysMenu := DllCall("GetSystemMenu", "Int", GUIhWnd, "Int", False)  ;Systeemmenu oproepen
DllCall("AppendMenu", "Int", hSysMenu, "Int", MF_SEPARATOR, "Int", 0, "Int", "")  ;Item aan systeemmenu toevoegen
DllCall("AppendMenu", "Int", hSysMenu, "Int", MF_STRING, "Int", SC_MyMenuItem1, "Str", sMyMenuCaption1)  ;Item aan systeemmenu toevoegen
DllCall("DrawMenuBar", "Int", GUIhWnd)  ;Toegevoegde items aan systeemmenu weergeven
OnMessage(0x112, "ManageSysCommand")   ; WM_SYSCOMMAND

ManageSysCommand(wParam, lParam)
{
   global
   If (wParam = SC_MyMenuItem1)
      ShowAbout()
}
Return

ShowAbout()
{
Gui, 2:+owner1
Gui +Disabled
Gui, 2:Font, w700 s16,
Gui, 2:Add, Text,, Weekstaten
Gui, 2:Font,,
Gui, 2:Font, w700,
Gui, 2:Add, Text,,Naar een idee van:
Gui, 2:Font,,
Gui, 2:Add, Text, x20 y75,René Simon
Gui, 2:Font, w700,
Gui, 2:Add, Text,,Gemaakt en getest door:
Gui, 2:Font,,
Gui, 2:Add, Text, x20 y125,Chris Simon
Gui, 2:Add, Text, x20 y140,René Simon
Gui, 2:Add, Button, w50 x60 Default, OK
Gui, 2:Show,, Info...
}
return

2ButtonOK:  ; This section is used by the "about box" above.
2GuiClose:
2GuiEscape:
Gui, 1:-Disabled  ; Re-enable the main window (must be done prior to the next step).
Gui Destroy  ; Destroy the about box.
return

;indien een keuze wordt gemaakt uit de eerste groep met radioknoppen (de BU's) wordt de onderstaande code uitgevoerd
BusinessUnit:
;stuur alle waardes van het formulier door naar de betreffende variabelen
Gui, Submit, nohide
;maak de OK knop beschikbaar
GuiControl, Enable, OK
;lees het aantal waardes uit de bijbehorende inifile voor de geselecteerde BU
IniRead, RepTimes, %Inifile%, %BU%, aantal
;keer terug
Return

;als er op de ok-knop gedrukt wordt
OK:
msgbox, %BU%::%Inifile%
;stuur alle waardes van het formulier door naar de betreffende variabelen
Gui, Submit, nohide
;verberg het dialoogvenster
Gui, Hide
;Standaard printer verkrijgen
DefaultPrinter := GetDefaultPrinter()
;Standaard Printer veranderen (tijdelijk)
SetDefaultPrinter(PrinterChoice)
;Printer instellen op dubbelzijdig afdrukken
PrinterDubbelzijdig(PrinterChoice)
;zet een variabele in verband met het wachtvenster
Looper = 1
;maak een wachtvenster
;Progress,b WM700 Y0 w650 R0-%RepTimes%, Even geduld a.u.b..., Uw opdracht wordt verwerkt. Tijdens de verwerking mag de computer NIET gebruikt worden
Gui, 3:Font, w700 s16,
Gui, 3:Add, Text,, Even geduld a.u.b...
Gui, 3:Add, Text,, Uw opdracht wordt verwerkt. Tijdens de verwerking mag de computer NIET gebruikt worden
Gui, 3:Add, Progress,w960 h20 cBlue vMyProgress Range0-%RepTimes%
Gui, 3:Font,,
Gui, 3:Add, Button, x500 Default gAnnuleren, Annuleren
Gui, 3:Show, x10 y0 h135, Info...
Gui, 3:+AlwaysOnTop -Caption

;loop net zovaak door de volgende code heen als de waarde die gezet is hierboven (bij de INIRead)
Loop %RepTimes%
{
;update de waarde van het wachtvenster
GuiControl,, MyProgress, +1
;wacht op het venster van de urenbriefjes
IniRead, Numbers, %IniFile%, %BU%, %A_Index%
MsgBox, %IniFile%, %BU%, %A_Index%
WinWait, Naamloos - Kladblok,
IfWinNotActive, Naamloos - Kladblok, , WinActivate, Naamloos - Kladblok,
WinWaitActive, Naamloos - Kladblok,
;Klik met de muis op de aangegeven coordinaten
Send, Nummer: %Numbers%; Weeknummer: %WeekNummer%
Sleep, 100
;verhoog de waarde in het wachtvenster
Looper++
}
;Printer weer op standaard instellingen zetten
PrinterDubbelzijdigUit(PrinterChoice)
;Standaard Printer veranderen naar waar hij eerst op stond
SetDefaultPrinter(DefaultPrinter)
;vernietig het dialoogvenster
Gui, Destroy
;sluit het programma
ExitApp

;de onderstaande code mag alleen als er op het kruisje op op annuleren is geklikt
3Annuleren:
Annuleren:
GuiClose:
ExitApp

;Printer op dubbelzijdig afdrukken zetten.
PrinterDubbelzijdig(PrinterChoice)
{
Run, ::{2227a280-3aea-1069-a2de-08002b30309d}
WinWait, Printers en faxapparaten, FolderView
IfWinNotActive, Printers en faxapparaten, FolderView, WinActivate, Printers en faxapparaten, FolderView
WinWaitActive, Printers en faxapparaten, FolderView
Send, %PrinterChoice%
Sleep, 100
Send, {AppsKey}v
WinWait, %PrinterChoice%
IfWinNotActive, %PrinterChoice% , WinActivate, %PrinterChoice%
WinWaitActive, %PrinterChoice%
MouseClick, left,  540,  241
Sleep, 100
MouseClick, left,  505,  270
Sleep, 100
MouseClick, left,  455,  438
Sleep, 100
MouseClick, left,  292,  440
Sleep, 100
WinWait, Printers en faxapparaten, FolderView
IfWinNotActive, Printers en faxapparaten, FolderView, WinActivate, Printers en faxapparaten, FolderView
WinWaitActive, Printers en faxapparaten, FolderView
MouseClick, left,  785,  13
Sleep, 100
}
Return
;Einde Dubbelzijdige printerinstellingen

;printer terug zetten op standaard
PrinterDubbelzijdigUit(PrinterChoice)
{
Run, ::{2227a280-3aea-1069-a2de-08002b30309d}
WinWait, Printers en faxapparaten, FolderView
IfWinNotActive, Printers en faxapparaten, FolderView, WinActivate, Printers en faxapparaten, FolderView
WinWaitActive, Printers en faxapparaten, FolderView
Send, %PrinterChoice%
Sleep, 100
Send, {AppsKey}v
WinWait, %PrinterChoice%
IfWinNotActive, %PrinterChoice% , WinActivate, %PrinterChoice%
WinWaitActive, %PrinterChoice%
MouseClick, left,  544,  236
Sleep, 100
MouseClick, left,  508,  257
Sleep, 100
MouseClick, left,  445,  447
Sleep, 100
MouseClick, left,  322,  441
Sleep, 100
WinWait, Printers en faxapparaten, FolderView
IfWinNotActive, Printers en faxapparaten, FolderView, WinActivate, Printers en faxapparaten, FolderView
WinWaitActive, Printers en faxapparaten, FolderView
MouseClick, left,  788,  13
Sleep, 100
SetDefaultPrinter(DefaultPrinter)
}
Return
;Einde printer op standaard instellingen zetten

;welke printer staat nu als standaard ingesteld
GetDefaultPrinter()
   {
         nSize := VarSetCapacity(gPrinter, 256)
         DllCall(A_WinDir . "\system\winspool.drv\GetDefaultPrinterA", "str", gPrinter, "UintP", nSize)
         Return gprinter
   }
Return

;zet de gekoze printer op standaard (tijdelijk) en na afloop ook de standaard weer terug zetten.
SetDefaultPrinter(sPrinter)
   {
      DllCall(A_WinDir . "\system\winspool.drv\SetDefaultPrinterA", "str", sPrinter)
   }
Return

GetInstalledPrinters()
{
   regread,defaultPrinter,HKCU,Software\Microsoft\Windows NT\CurrentVersion\Windows,device
   stringsplit,defaultName,defaultPrinter,`,
   defaultName := defaultName1
   SplitPath, defaultName , DefaultPrinterName
   printerlist =
   loop,HKCU,Software\Microsoft\Windows NT\CurrentVersion\devices
   {
      SplitPath, A_LoopRegName , PrinterName
      if (PrinterName = DefaultPrinterName)
      printerlist = %printerlist%%PrinterName%||
      else printerlist = %printerlist%%PrinterName%|
   }
   return %printerlist%
}
return

In the above ahk-code, i read the inifile to create some radiobuttons on my form. THis works, but the problem is that when i choose a radiobutton to continu with the program, the remaining info also needs to be pulled out of the same ini-file based on the id-number of the chosen radiobutton. This is where the problem arises. The id-number of the chosen radiobutton stays empty while it should contain any number between 1 and the number of radiobuttons.

you would be a hero if you could solve this problem for me.

p.s. i removed some code in the ahk file for testing purposes. i now temporarily use notepad to test if it is working, because this ahk-file needs to connect to a special program.
_________________
Before asking a question try to read the manual
Always use the code sections when you paste some code
Back to top
View user's profile Send private message
BoBo¨
Guest





PostPosted: Fri Sep 21, 2007 11:43 am    Post subject: Reply with quote

Code:
Loop %RepTimesBus%
{
   IniRead, Bus, %Inifile%, bus, %A_Index%
      Gui, Add, Radio, vBU%A_Index% gBusinessUnit, %Bus%
   }

   .
   .
   .

BusinessUnit:
   Gui, Submit, nohide
   MsgBox % PerPagina
   GuiControl, Enable, OK
   IniRead, RepTimes, %Inifile%, %BU%, aantal
   Return

OK:
   Gui, Submit, nohide
   Loop
   {
      If InStr(BU%A_Index%,"1")
      {
         BU := A_Index
         Break
         }
      }
   MsgBox % BU   
   Return

You've realized that creating "Radios" dynamically using a Loop isn't possible,as that would be rejected using the same variable multiple times.
The way you tried it (using if/else) seems to have 'isolate' the first radio from its group members. Might be caused by that rule: "or simply add a non-radio control in between, since that automatically starts a new group.". So it looks like, that that behaviour isn't restricted with using controls (?).

Hope that helps.
Gruss nach Holland. Cool
Back to top
BoBo¨
Guest





PostPosted: Fri Sep 21, 2007 12:06 pm    Post subject: Reply with quote

Replace this:
Code:
;Herhaal het volgende gedeelte een X aantal maal. X staat gelijk aan aantal uit de bus.ini
Loop %RepTimesBus%
{
;Lees de BU
IniRead, Bus, %Inifile%, bus, %Looping%
;Als de BU de eerste is die gelezen wordt
if %RepTimesBus% = 1 ; BY THE WAY: WRONG SYNTAX
{
;Dan moet er iets meer aan de radioknop worden toegevoegd.
Gui, Add, Radio, group vBU gBusinessUnit, %Bus%
}
else
{
;anders is een gewone radioknop voldoende
Gui, Add, Radio, gBusinessUnit, %Bus%
}
;Verhoog de herhaalwaarde met 1
Looping++
}
with that ...
Code:
Loop %RepTimesBus%
{
   IniRead, Bus, %Inifile%, bus, %A_Index%
   If A_Index = 1
      Var = Group vBU
   Else
      Var =
   Gui, Add, Radio, %Var% gBusinessUnit, %Bus%
   }
Tested. Nochmal nen Gruss nach Holland. Smile
Back to top
eagle00789



Joined: 27 Nov 2006
Posts: 52
Location: Heerlen Country: Netherlands

PostPosted: Fri Sep 21, 2007 7:08 pm    Post subject: Reply with quote

i will try this when i get back to work on monday. Thanks already for the tips mate Very Happy

And greetings from the Netherlands to you to Very Happy Razz
_________________
Before asking a question try to read the manual
Always use the code sections when you paste some code
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group