Sign in to follow this  
Followers 0
sb1920alk

"Self Constructing" GUI?

17 posts in this topic

#1 ·  Posted (edited)

I'm working on my first GUI. It's going to be a list of people, and information that relates to them. When I click one of the buttons, it will do that button's task for that person.

I've gotten it to work for one person, but since the people and the number of people change, I'd like the script to simply read the ini file and make a new row for each person rather than use a copy/paste/find/replace method to reproduce the pieces many times.

When I use real information, the buttons work (for the one person), but one or two of the include scripts I'm using use "Exit" which causes the GUI to close too. How can I get around that?

I plan on each person having their own section in the ini, but that doesn't have to be the case. Here's a sample of the ini file that will work with the code:

[JohnDoe]

firstname=John

lastname=Doe

computer=johndoe

MACaddress=000000000000

email=jdoe@none.com

#include <GUIConstants.au3>

Dim $firstname1 = IniRead("people.ini","JohnDoe","firstname","")
Dim $lastname1 = IniRead("people.ini","JohnDoe","lastname","")
Dim $email1 = IniRead("people.ini","JohnDoe","email$firstname1 & " " & $lastname1","")
Dim $computer1 = IniRead("people.ini","JohnDoe","computer","")
Dim $MACaddress1 = IniRead("people.ini","JohnDoe","MACaddress","")

;Read the rest of the ini file and create similar variables for each section

GUICreate("Tool Box"); create the GUI.

GUICtrlCreateLabel ($firstname1 & " " & $lastname1,20,23,70,20)
$button1 = GUICtrlCreateButton ("Email1",90,20,70,20) ; button to display value when pressed.
$button2 = GUICtrlCreateButton ("Phone1",160,20,70,20) ; button to display value when pressed.
$button3 = GUICtrlCreateButton ("VNC1",230,20,70,20) ; button to display value when pressed.
$button4 = GUICtrlCreateButton ("WoL1",300,20,70,20) ; button to display value when pressed.

GUISetState()

$start=TimerInit() ; start a built-in timer Function.
Do ; the Do/Until loop, is similar to While/Wend loop.
  $n = GUIGetMsg () ; n = get the message
     
   If $n = $button1 Then ; if the message from n, is equal to the button then,
      Dim $recipient = $email1
      #include "New Email Message.au3"
      
   $start=TimerInit() ; starts the timer again.
   EndIf
   If $n = $button2 Then ; if the message from n, is equal to the button then,
      Dim $file = $firstname1 & " " & $lastname1
      #include "NewCall.au3"
      
   $start=TimerInit() ; starts the timer again.
   EndIf
   If $n = $button3 Then ; if the message from n, is equal to the button then,
      Dim $comm = $computer1
      #include "Run VNC Viewer.au3"
      
   $start=TimerInit() ; starts the timer again.
   EndIf   
   If $n = $button4 Then ; if the message from n, is equal to the button then,
      $MACAddress = $MACaddress1 
      #include "WakeOnLan.au3"
      
   $start=TimerInit() ; starts the timer again.
   EndIf  

Until $n = $GUI_EVENT_CLOSE ; Do Loop Until, the close event, then exit the loop.

; the Do/Until Loop is Very Important!!!

EDIT: I found the autoit tag

Edited by sb1920alk

Share this post


Link to post
Share on other sites



Hi,

your concept is a bit strange. You have includes instead of functions. Just put those includes into the main script as functions and then post again. Then we can have a look at the whole code.

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Hi,

your concept is a bit strange. You have includes instead of functions. Just put those includes into the main script as functions and then post again. Then we can have a look at the whole code.

Mega

I didn't think of using functions, that's a good idea. I think that will solve the problem of an included file having "Exit" in it...or would that be the equivalent of re-doing the scripts to contain no Exit?

Share this post


Link to post
Share on other sites

I didn't think of using functions, that's a good idea. I think that will solve the problem of an included file having "Exit" in it...or would that be the equivalent of re-doing the scripts to contain no Exit?

We can't tell if we don't know what's in the scripts, but in AutoIt exit will exit the whole script not just the function. Maybe what you need is Return which ends execution of the function so the script continues from where the function was called. See the help for Return.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

We can't tell if we don't know what's in the scripts, but in AutoIt exit will exit the whole script not just the function. Maybe what you need is Return which ends execution of the function so the script continues from where the function was called. See the help for Return.

Ok, here are the included scripts. I haven't had a chance to re-write them as functions. I haven't written any functions yet, but it doesn't look like it will be that difficult (I know there's a HotKey function in the VNC script, but I just copied and pasted it out of the help file). All of these scriptlets work for me right now. What I'm trying to do with the GUI is have a "Tool Box" that I can use to call or email a particular person or connect to or boot up their computer by clicking the appropriate button. As I mentioned before the piece of the GUI in the first post works for the first person. I want that row of buttons to duplicate for each of the other people. As people come and go, I don't want to have to rewrite the GUI every time, I'd rather just update an ini file or something similar.

New Email Message.au3 ($recipient was declared and set in the GUI script before it called this script)

Run(@ProgramFilesDir & "\Microsoft Office\Office\OUTLOOK.EXE /c ipm.note /m " & $recipient)oÝ÷ Ø×° ©ejííè§v+âv楲+µË­±ªÞ¦·¦i×ÔÞåZÖ yXÀú"Ù®²ÖÞ{-jY^uú+¶¬¶(®F®¶­sdFÒb33c¶fÆP £´6V6²Fò6VRb7VVBFÂ6÷'F7WBW7G0¤bæ÷BfÆTW7G2×Fö7VÖVçG4F"fײgV÷C²b3#µ7VVBFÇ2b3#²gV÷C²fײgV÷C´6ÆÂgV÷C²fײb33c¶fÆRfײgV÷C²æÆæ²gV÷C²FVà ×6t&÷ÂgV÷C´Ö76ær7VVBFÂ6÷'F7WBgV÷C²ÂgV÷CµF2W6W"FöW2æ÷BfR7VVBFÂ6÷'F7WBâgV÷C²fײ5$Äbfײ5$ÄbfײgV÷Cµ&vBÖ6Æ6²öâFV"æÖRâfWuöçBæB7&VFR7VVBFÂ6÷'F7WBÂFVâÖ÷fRBFòFR7VVBFÇ2föÆFW"â×Fö7VÖVçG2âgV÷C² W@¤VæD` ¥6VÆÄWV7WFR×Fö7VÖVçG4F"fײgV÷C²b3#µ7VVBFÇ2b3#²gV÷C²fײgV÷C´6ÆÂgV÷C²fײb33c¶fÆRfײgV÷C²æÆæ²gV÷C² £µFR6÷'F7WG2¶æö6²fWuöçB÷WBöbÖÖ¦VBââçF2WG2B&6°¤WFôE6WD÷FöâgV÷CµvåFFÆTÖF6ÖöFRgV÷C²Â"¥våvD7FfRgV÷C´'F6ögBFVÆUfçFvRfWuöçBgV÷C²¥vå6WE7FFRgV÷C´'F6ögBFVÆUfçFvRfWuöçBgV÷C²ÂgV÷C²gV÷C²Ä5uôÔÔ¤R¤WFôE6WD÷FöâgV÷CµvåFFÆTÖF6ÖöFRgV÷C²ÂoÝ÷ Ù§TÐì­«·"
-Ü(®H§­­¶ªºDÆ+jºb²Ëb¡j÷­¢«¾*.²¡j÷¬j÷¶¯Ç(ø º¶­ßW¡z·¢¶+*ºoËçr«¨´¬zØb±«²Ö§u©hë®*m®(!¶z0Â+0+az··öËay¸­iº.·Mú«-¾wnø¨ºÉrªê-²Ö§uªÝ¦·®¢Ö§v«¨¶éâªç¢jnµêõªê-«Þmç§r§çZºÚ"µÍ[H ÌÍÙ[ÛÛ[[[YB[H  ÌÍÛÝÈH[TXY
    ][ÝØXYÜ[[I][ÝË  ][ÝÔÙXÝ[ÛI][ÝË   ][ÝÛÝÉ][ÝË    ][ÝÉ][ÝÊB[H ÌÍØÛÛ[BYÝ[Ó[ ÌÍØÛÛ[JHH[ÈÚXÚÜÈÈÙYHYÈØÜØÈ][ÚYÛH[ÝIÌÍØÛÛ[HH[]Þ
    ][ÝÑ[[X][ÝË ][ÝÑ[ÛÛ][X][ÝË    ÌÍÛÝÊBRYÜ[BQ^]Q[Y[YQÝ[Ó[    ÌÍØÛÛ[JHHÈ[IÌÍÙ[ÛÛ[[[YHH ][ÝÜÝ[Y^ ][ÝÈ  [È ÌÍØÛÛ[B[ÙBIÌÍÙ[ÛÛ[[[YHH  ÌÍØÛÛ[B[Y[]J    ][ÝØXYÜ[[I][ÝË  ][ÝÔÙXÝ[ÛI][ÝË   ][ÝÛÝÉ][ÝË    ÌÍÙ[ÛÛ[[[YJB[]J ][ÝÝËÉ][ÝË    ][ÝÐÛÛXÝ[Û][ÝË  ][ÝÒÜÝ  ][ÝË  ÌÍÙ[ÛÛ[[[YJBÝ[]YXÛÛ]HÈH[]YHÜÝÛÜY   ÌÍÙ[ÛÛ[[[YHH   ][ÝÝ[]YXÛÛ]I][ÝÈ[[^]J   ][ÝÝ[]YXÛÛ]][ÝÊB[ÙBTÚ[^]J ][ÝÝËÉ][ÝÊB[YÔÙ]ÝÙ^HÈÛÜÙHÂÝÙ^]
    ][ÝÞÔUTÑ_I][ÝË    ][ÝÐÛÜÙUÉ][ÝÊBÚ[HØÙÜÑ^ÝÊ ][ÝÝÝY]Ù^I][ÝÊBÛY
L
BÑ[[ÈÛÜÙUÊ
BTØÙÜÐÛÜÙJ   ][ÝÝÝY]Ù^I][ÝÊB[[ÂÔ[XÙHHÝÙ^BÝÙ^]
    ][ÝÞÔUTÑ_I][ÝÊoÝ÷ Ùf¤xéËjv®Ü(ºWgßÛ`zÛaË®*(®Gè®g®®

Share this post


Link to post
Share on other sites

Here a sample of what it will look like. I just need a way for the GUI script to loop and make another row of buttons for each person.

post-40103-1222440502_thumb.png

Share this post


Link to post
Share on other sites

Hi,

I just put this together quickly to help out, I know its not very clean but here goes:

CODE
;~ Generate GUI

#include <GUIConstantsEx.au3>

$ini = @ScriptDir&"/users.ini"

$userCount = IniReadSectionNames($ini)

ConsoleWrite("there are " & $userCount[0] & " users registered in the ini file" & @CR)

Global $rowNumber

Global $buttonNumber

Dim $label[$userCount[0]+1]

Dim $button1[$userCount[0]+1]

Dim $button2[$userCount[0]+1]

Dim $button3[$userCount[0]+1]

Dim $button4[$userCount[0]+1]

$LineHeight = 40

$guiWidth = 350

$guiHeight = ($LineHeight*$userCount[0])+60

$buttonWidth = 50

$buttonSpace = 10

$LabelX = 10

$LabelWidth = 60

$button1X = 1*($buttonWidth + $buttonSpace) +$LabelWidth

$button2X = 2*($buttonWidth + $buttonSpace)+$LabelWidth

$button3X = 3*($buttonWidth + $buttonSpace)+$LabelWidth

$button4X = 4*($buttonWidth + $buttonSpace)+$LabelWidth

$Y=10

GUICreate("GUI TITLE",$guiWidth,$guiHeight)

AutoItSetOption ( "GUIOnEventMode" ,1 )

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")

GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$loop = 1

GUISetState(@SW_SHOW)

while $loop <= $userCount[0]

ConsoleWrite(@CR & $loop & "-")

$Name = IniRead ( $ini, $userCount[$loop], "firstname", "-" ) & " " & IniRead ( $ini, $userCount[$loop], "lastname", "-" )

ConsoleWrite($Name)

$label[$loop] = GUICtrlCreateLabel($Name,$LabelX,$Y+5,$LabelWidth)

$button1[$loop] = GUICtrlCreateButton("Email",$button1X,$Y,40)

GUICtrlSetOnEvent($button1[$loop], "SpecialEvents")

$button2[$loop] = GUICtrlCreateButton("Phone",$button2X,$Y,40)

GUICtrlSetOnEvent($button2[$loop], "SpecialEvents")

$button3[$loop] = GUICtrlCreateButton("VnC",$button3X,$Y,40)

GUICtrlSetOnEvent($button3[$loop], "SpecialEvents")

$button4[$loop] = GUICtrlCreateButton("WoL",$button4X,$Y,40)

GUICtrlSetOnEvent($button4[$loop], "SpecialEvents")

$Y+=$LineHeight

$loop+=1

Sleep(500)

WEnd

while 1

WEnd

Func SpecialEvents()

Select

Case @GUI_CtrlId = $GUI_EVENT_CLOSE

MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

Exit

Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE

MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

Case @GUI_CtrlId = $GUI_EVENT_RESTORE

MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

Case Else

$rowNumber=int(((@GUI_CtrlId -4)/5)+1)

$buttonNumber=@GUI_CtrlId-(5*$rowNumber)+2

MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " Row=" & $rowNumber & " button=" & $buttonNumber)

Select

Case $buttonNumber = 1

Email($rowNumber)

Case $buttonNumber = 2

Phone($rowNumber)

Case $buttonNumber = 3

VnC($rowNumber)

Case $buttonNumber = 4

WoL($rowNumber)

EndSelect

EndSelect

EndFunc ;==>SpecialEvents

Func Email($row)

$email = IniRead($ini,$userCount[$row],"email","-")

MsgBox(1,"Email Function","Email function for " & $userCount[$row]& @CR & $email)

EndFunc

Func Phone($row)

$phone = IniRead($ini,$userCount[$row],"phone","-")

MsgBox(1,"Phone Function","Phone function for " & $userCount[$row]& @CR & $phone)

EndFunc

Func VnC($row)

$vnc = IniRead($ini,$userCount[$row],"MACaddress","-")

MsgBox(1,"Phone Function","VnC function for " & $userCount[$row]& @CR & $VnC)

EndFunc

Func WoL($row)

$WoL = IniRead($ini,$userCount[$row],"computer","-")

MsgBox(1,"Phone Function","WoL function for " & $userCount[$row]& @CR & $WoL)

EndFunc

to be used with an ini file like the following

CODE
[JohnDoe]

firstname=John

lastname=Doe

computer=johndoe

MACaddress=000000000000

email=jdoe@none.com

[JaneDoe]

firstname=Jane

lastname=Doe

computer=janedoe

MACaddress=000000000001

email=janedoe@none.com

[JohnDoes]

firstname=John

lastname=Does

computer=johndoes

MACaddress=000000000002

email=jdoes@none.com

[JaneDoes]

firstname=Jane

lastname=Does

computer=janedoes

MACaddress=000000000003

email=janedoes@none.com

[AlfredJames]

firstname=Alfred

lastname=James

computer=alfredjames

MACaddress=000000000004

email=alf@none.com

I hope it points you in the right direction.

Cheers

Wakido

Share this post


Link to post
Share on other sites

Hi,

I just put this together quickly to help out, I know its not very clean but here goes:

...

I hope it points you in the right direction.

Cheers

Wakido

Yes, thank you! I'm pretty sure I can take it from here. Using variable arrays was the key.

BTW, why the Sleep(500)? It runs fine without it.

Share this post


Link to post
Share on other sites

The sleep was only there to slow the button creation to make it easier to see. it shouldn't be required.

Pleasure to help

Share this post


Link to post
Share on other sites

Ok, I have been working with this and I have two questions.

When I replace

$vnc = IniRead($ini,$userCount[$row],"MACaddress","-")

MsgBox(1,"Phone Function","VnC function for " & $userCount[$row]& @CR & $VnC)

with

$comm = IniRead($ini,$userCount[$row],"computer","")
#include "Run VNC Viewer.au3"

(I haven't turned it into a function, it still looks just like it does above), I'm getting the error: Line...Func CloseVNC() Error: "Func" statement has no matching "EndFunc"...even though it does

My other question is, if I want the first row to be custom buttons (add a new person, open ini, etc.) what's the easiest way to do that?

Share this post


Link to post
Share on other sites

I'm getting the error: Line...Func CloseVNC() Error: "Func" statement has no matching "EndFunc"

It's because the function can not be used inside other function, just put out all the function at the end of your script and call them when needed. Don't use #includes inside any conditions/functions, it's wrong implementation.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hi sb1920alk,

you seem to be using #include in a way that it was not designed for:

use #include when you want to reuse some existing constants or functions you have in a library;

usually you put them at the top of the script, it tells the compiler to include these things in your script just as if you had typed them there yourself.

the easiest thing you can do find the functions in the script I wrote for you for example :

Func WoL($row)

$WoL = IniRead($ini,$userCount[$row],"computer","-")

MsgBox(1,"Phone Function","WoL function for " & $userCount[$row]& @CR & $WoL)

EndFunc

and replace the $WoL.... and MsgBox lines with the actions you wish to perform when you push the button.

for example replace the above with:

Func WoL($row)

$WoL = IniRead($ini,$userCount[$row],"computer","-")

;Converts input into usable output for mc-wol.exe

$MACAddress = StringMid($WoL,1,2) & ":" &StringMid($WoL,3,2) & ":" &StringMid($WoL,5,2) & ":" &StringMid($WoL,7,2) & ":" &StringMid($WoL,9,2)& ":" &StringMid($WoL,11,2)

Run(@DesktopDir & "\Apps\mc-wol.exe " & $MACAddress,"",@SW_HIDE)

;~ MsgBox(1,"Phone Function","WoL function for " & $userCount[$row]& @CR & $WoL)

EndFunc

Edited by NBJ

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Ok, I've made some progress today. I converted all of the #includes to functions and added a row of custom buttons at the top. I also tweaked the button labels and fuctions to get and save missing data.

I searched for an answer, but didn't find it. If I add a new person (using the new custom button) or tweak the ini file manually, how can I get the GUI to reload itself? A function would be fine here, I have a button read to go that will trigger it.

Here's the current code.

;~ Generate Tool Box GUI
Opt("TrayIconHide",1)
#include <GUIConstantsEx.au3>

$ini = @ScriptDir&"/people.ini"

$userCount = IniReadSectionNames($ini)

Global $rowNumber
Global $buttonNumber

Dim $label[$userCount[0]+1]
Dim $button1[$userCount[0]+1]
Dim $button2[$userCount[0]+1]
Dim $button3[$userCount[0]+1]
Dim $button4[$userCount[0]+1]

$LineHeight =25
$guiWidth = 360

$X = 50 ;top border
$Y = $X
$Z = 10 ;bottom border
$guiHeight = ($LineHeight*$userCount[0]) + $Y + $Z
$buttonWidth =  50
$buttonSpace = 10

$LabelX = 10
$LabelWidth = 60
$button1X = 1*($buttonWidth + $buttonSpace) +$LabelWidth
$button2X = 2*($buttonWidth + $buttonSpace)+$LabelWidth
$button3X = 3*($buttonWidth + $buttonSpace)+$LabelWidth
$button4X = 4*($buttonWidth + $buttonSpace)+$LabelWidth

GUICreate("Tool Box",$guiWidth,$guiHeight)
AutoItSetOption ( "GUIOnEventMode" ,1 )
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$loop = 1
GUISetState(@SW_SHOW)

while $loop <= $userCount[0]

    $Name = IniRead ( $ini, $userCount[$loop], "firstname", "-" ) & " " & IniRead ( $ini, $userCount[$loop], "lastname", "-" )

    $label[$loop] = GUICtrlCreateLabel($Name,$LabelX,$Y+5,$LabelWidth)
    
    If IniRead($ini,$userCount[$loop],"email","") <> "" Then
        $button1[$loop] = GUICtrlCreateButton("Email",$button1X,$Y,40)
        GUICtrlSetOnEvent($button1[$loop], "SpecialEvents")
    Else
        $button1[$loop] = GUICtrlCreateButton("Enter Email",$button1X,$Y,60)
        GUICtrlSetOnEvent($button1[$loop], "SpecialEvents")
    EndIf

    $button2[$loop] = GUICtrlCreateButton("Call",$button2X,$Y,40)
    GUICtrlSetOnEvent($button2[$loop], "SpecialEvents")

    If IniRead($ini,$userCount[$loop],"computer","") <> "" Then
        $button3[$loop] = GUICtrlCreateButton("VNC",$button3X,$Y,40)
        GUICtrlSetOnEvent($button3[$loop], "SpecialEvents")
    Else
        $button3[$loop] = GUICtrlCreateButton("Name?",$button3X,$Y,50)
        GUICtrlSetOnEvent($button3[$loop], "SpecialEvents")
    EndIf      

    If IniRead($ini,$userCount[$loop],"MACaddress","") <> "" Then
        $button4[$loop] = GUICtrlCreateButton("WoL",$button4X,$Y,40)
        GUICtrlSetOnEvent($button4[$loop], "SpecialEvents")
    Else
        $button4[$loop] = GUICtrlCreateButton("Get MAC",$button4X,$Y,50)
        GUICtrlSetOnEvent($button4[$loop], "SpecialEvents")
    EndIf
    
    $Y+=$LineHeight
    $loop+=1
WEnd

;Custom buttons at the top
$Button1ID = GUICtrlCreateButton("Add New Person",40,10)
GUICtrlSetOnEvent($Button1ID,"AddNewPerson")

$Button2ID = GUICtrlCreateButton("Open INI File",140,10)
GUICtrlSetOnEvent($Button2ID,"OpenINI")

$Button3ID = GUICtrlCreateButton("Refresh ToolBox",225,10)
GUICtrlSetOnEvent($Button3ID,"RefreshToolBox")
;/Custom buttons

while 1 
WEnd

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
        Case Else
            $rowNumber=int(((@GUI_CtrlId -4)/5)+1)
            $buttonNumber=@GUI_CtrlId-(5*$rowNumber)+2
            Select
                Case $buttonNumber = 1
                    Email($rowNumber)
                Case $buttonNumber = 2
                    Phone($rowNumber)
                Case $buttonNumber = 3
                    VnC($rowNumber)
                Case $buttonNumber = 4
                    WoL($rowNumber)
            EndSelect
    EndSelect
EndFunc   ;==>SpecialEvents
   
Func Email($row)
    $recipient = IniRead($ini,$userCount[$row],"email","")
    NewEmailMessage($recipient)
EndFunc

Func Phone($row)
    $file = IniRead($ini,$userCount[$row],"firstname","") & " " & IniRead($ini,$userCount[$row],"lastname","")
    NewCall($file)
EndFunc

Func VnC($row)
    $comm = IniRead($ini,$userCount[$row],"computer","")
    RunVNC($comm)
EndFunc

Func WoL($row)
    $MACAddress = IniRead($ini,$userCount[$row],"MACaddress","") 
    WakeOnLan($MACAddress)
EndFunc

;New Email Message
Func NewEmailMessage($recipient)
    If $recipient = "" Then
        $recipient = InputBox("No Email Address Saved","Enter the email address",StringLower(StringLeft(IniRead($ini,$userCount[$rowNumber],"firstname",""),1) & IniRead($ini,$userCount[$rowNumber],"lastname","") & "@mydomain.com"))
        IniWrite($ini,$userCount[$rowNumber],"email",$recipient)
        $GUICtrlID = $rowNumber*5 - 1
        GUICtrlDelete($GUICtrlID)
        $button1[$rowNumber] = GUICtrlCreateButton("Email",$button1X,$LineHeight*($rowNumber-1)+$X,40)
        GUICtrlSetOnEvent($GUICtrlID, "SpecialEvents")
    Else
        Run(@ProgramFilesDir & "\Microsoft Office\Office\OUTLOOK.EXE /c ipm.note /m " & $recipient)
    EndIf
EndFunc ;=>NewEmailMessage()

;New Call
Func NewCall($file)

;Check to see if Speed Dial shortcut exists
    If FileExists( @MyDocumentsDir & "\Speed Dials\" & "Call " & $file & ".lnk") Then
        ShellExecute(@MyDocumentsDir & "\Speed Dials\" & "Call " & $file & ".lnk")
;The shortcuts knock ViewPoint out of Maximized...this puts it back
        AutoItSetOption ("WinTitleMatchMode", 2)
        WinWaitActive("Artisoft TeleVantage ViewPoint")
        WinSetState("Artisoft TeleVantage ViewPoint","",@SW_MAXIMIZE)
        AutoItSetOption ("WinTitleMatchMode", 1)
    Else
        MsgBox (0,"Missing Speed Dial Shortcut", "This user does not have a Speed Dial shortcut." & @CRLF & @CRLF & "Right-click on their name in ViewPoint and create a Speed Dial shortcut, then move it to the Speed Dials folder in My Documents.")
    EndIf
EndFunc;=>NewCall()

;Run VNC Viewer
Func RunVNC($comm)
    If $comm = "" Then
        $comm = InputBox("No Computer Name Saved","Enter the computer name","")
        If StringLen($comm) = 3 Then
                $comm = "commonprefix" & $comm
        EndIf
        IniWrite($ini,$userCount[$rowNumber],"computer",$comm)
        $GUICtrlID = $rowNumber*5 +1
        GUICtrlDelete($GUICtrlID)
        $button3[$rowNumber] = GUICtrlCreateButton("VNC",$button3X,$LineHeight*($rowNumber-1)+$X,40)
        GUICtrlSetOnEvent($GUICtrlID, "SpecialEvents")
    Else    
        Dim $fullcommname

        Dim $lastvnc = IniRead("breadcrumbs.ini","Section1", "lastvnc","")

        Dim $comm

        If StringLen($comm) = 0 Then; checks to see if this script was launched from another
            $comm = InputBox("Enter Number","Enter Computer Number",$lastvnc)
            If @error Then
                $comm = "cancel"
            EndIf
        EndIf
    
        If $comm <> "cancel" Then
            If StringLen($comm) = 3 Then
                $fullcommname = "commonprefix" & $comm
            Else
                $fullcommname = $comm
            EndIf
    
            IniWrite("breadcrumbs.ini","Section1", "lastvnc",$fullcommname)
    
            IniWrite("vnc.vnc","Connection","Host",$fullcommname)

;uniquecomm1 has a unique password
            If $fullcommname = "uniquecomm1" Then
                ShellExecute("uniquecomm1.vnc")
            Else
                ShellExecute("vnc.vnc")
            EndIf
;Set Hotkey to close VNC
            HotKeySet("{PAUSE}", "CloseVNC")

            While ProcessExists("vncviewer.exe")
                Sleep(100)
            WEnd

;Release the Hotkey
            HotKeySet("{PAUSE}")
        EndIf
    EndIf
EndFunc ;=>RunVCN()

Func CloseVNC()
    ProcessClose("vncviewer.exe")
EndFunc ;=>CloseVNC()

Func WakeOnLan($MACAddress)
    If $MACAddress = "" Then
        $MACAddress = GetMAC()
        If $MACAddress <> "" Then
            If $MACAddress = -1 Then
                MsgBox(48,"No Computer Name Saved","Enter the computer name first",3)
            Else
                IniWrite($ini,$userCount[$rowNumber],"MACAddress",$MACAddress)
                $GUICtrlID = $rowNumber*5 + 2
                GUICtrlDelete($GUICtrlID)
                $button4[$rowNumber] = GUICtrlCreateButton("WoL",$button4X,$LineHeight*($rowNumber-1)+$X,40)
                GUICtrlSetOnEvent($GUICtrlID, "SpecialEvents")
                MsgBox(0,"MAC Address Saved",$MACAddress & " has been saved.",3)
            EndIf
        Else
            MsgBox(48,"MAC Address Error","The MAC Address could not be found.",3)
        EndIf
    Else    
        Dim $MACAddress, $MACAddressS1, $MACAddressS2, $MACAddressS3, $MACAddressS4, $MACAddressS5, $MACAddressS6
;Converts input into usable output for mc-wol.exe
        $MACAddress = StringReplace($MACAddress,"-","")
        $MACAddress = StringReplace($MACAddress,":","")

        If StringLen($MACAddress) = 12 Then
            $MACAddressS1 = StringMid($MACAddress,1,2)&":"
            $MACAddressS2 = StringMid($MACAddress,3,2)&":"
            $MACAddressS3 = StringMid($MACAddress,5,2)&":"
            $MACAddressS4 = StringMid($MACAddress,7,2)&":"
            $MACAddressS5 = StringMid($MACAddress,9,2)&":"
            $MACAddressS6 = StringMid($MACAddress,11,2)

            $MACAddress = $MACAddressS1 & $MACAddressS2 & $MACAddressS3 & $MACAddressS4 & $MACAddressS5 & $MACAddressS6

            Run(@DesktopDir & "\Setup Shortcuts\Apps\mc-wol.exe " & $MACAddress,"",@SW_HIDE)
            MsgBox(0,"Wake on LAN","Magic packet sent to: " & $MACAddress,3)
        Else
            MsgBox(48,"Bad MAC Address","The MAC address is incorrect or missing",3)
        EndIf
    EndIf
EndFunc;=>WakeOnLan

Func GetMAC()
    $computer = IniRead($ini,$userCount[$rowNumber],"computer","")
    If $computer = "" Then
        Return -1
    Else
        TCPStartup()
        $IP = TCPNameToIP($computer)
        $MACAddress = _GetMACFromIP($IP)
        Return $MACAddress
    EndIf
EndFunc ;=>GetMAC()

Func _GetMACFromIP($sIP)
    Local $MAC, $MACSize
    Local $i, $s, $r, $iIP
    $MAC = DllStructCreate("byte[6]")
    $MACSize = DllStructCreate("int")
    DllStructSetData($MACSize, 1, 6)
    $r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
    $iIP = $r[0]
    $r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
    $s = ""
    For $i = 0 To 5
        If $i Then $s = $s & ":"
        $s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
    Next
    Return $s
EndFunc   ;==>_GetMACFromIP

Func AddNewPerson()
    $Newfirstname = InputBox("Add New Person","Enter the new person's first name.")
    $Newlastname = InputBox("Add New Person","Enter the new person's last name.")
    IniWrite($ini,$Newfirstname & $Newlastname,"firstname",$Newfirstname)
    IniWrite($ini,$Newfirstname & $Newlastname,"lastname",$Newlastname)
EndFunc

Func OpenINI()
    ShellExecute($ini)
EndFunc

Func RefreshToolBox()
    MsgBox(0,"","Refresh Me")
EndFunc

EDIT: Corrected error in script.

Edited by sb1920alk

Share this post


Link to post
Share on other sites

Hi sb,

I haven't spent time looking through your code, it through 3 errors as soon as I tried to run it:

CODE
C:\Documents and Settings\testuser\Desktop\downloadedfromupload.au3(185,18) : ERROR: $comm already declared as parameter

Dim $comm

~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\testuser\Desktop\downloadedfromupload.au3(222,1) : ERROR: missing EndIf.

EndFunc

^

C:\Documents and Settings\testuser\Desktop\downloadedfromupload.au3(169,23) : REF: missing EndIf.

If $comm = "" Then

~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\testuser\Desktop\downloadedfromupload.au3(246,24) : ERROR: $MACAddress already declared as parameter

Dim $MACAddress,

~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\testuser\Desktop\downloadedfromupload.au3

So lets sit and think about what you want to do logically:

REFERENCES

You have a reference file (your ini) which holds your user data.

YOUR PROGRAM

The functions of your program (what you want it to do)

- Read the Ini and build the GUI

- Add a new user

- Open the INI file (for manual editing??)

- Refresh Toolbox (does this Read the Ini and build the GUI)

- Detect which button has been Pressed

- Email a user

- Call a user

- VNC a user's computer

- Wake a users computer via LAN

NOW Lets think about how to structure your program: how should it ordered.

Each of your Functions should be functions Func()....EndFunc so you will have the following Functions

BuildGUI() - Read the Ini and build the GUI

AddUser() - Add a new user

OpenINI() - Open the INI file (for manual editing??)

SpecialEvents() - Detect which button has been Pressed

Email() - Email a user

Phone() - Call a user

VNC() - VNC a user's computer

WOL() - Wake a users computer via LAN

you should probably use on event mode: AutoItSetOption ( "GUIOnEventMode" ,1 ) as your program doesn't do anything unless there is a button pressed.

So the steps:

1. Comment the program (whats it for description and requirements)

2. #includes

3. Dim Variables if that's what you want - GLOBAL all the button variables in your program so the button name can be reused

4. YOUR MAIN PROGRAM

- Call the function to build the GUI (this includes the on event actions for the buttons)

- Add a loop to stop the program from exiting

in between your loop - you can add a sleep, or cause the gui to rebulid every 5 minutes or so if thats what you want.

So whats happening now - the gui is just sitting there: good

when a button is pressed GUICtrlSetOnEvent() tells the program to execute a function - in the top 3 buttons it will be functions AddUser() - OpenINI() - BuildGUI()

for the others it will have to execute the function SPECIALEVENTS() to figure out which Column and Row of the buttons has been pressed to send the Function Parameter to the actual Function you want to call.

Then it executes the correct function Email() Phone() VNC() WOL() with the user's username as the parameter

The last 4 functions

Email() Phone() VNC() WOL() all have the same basic structure:

1. Read the correct section of the ini file - to get the required variables

2. Perform the Task using the variables

3. Return to the main program loop.

------------------------------------

As you have added new controls to the area above the matrix of user buttons, you will have to change to calculations

$rowNumber=int(((@GUI_CtrlId -4)/5)+1)

$buttonNumber=@GUI_CtrlId-(5*$rowNumber)+2

to determine (the msgbox popups will help with that.

Cheers

NBJ

Share this post


Link to post
Share on other sites

@ NBJ

I missed something when I stripped the private info out of the code. I think I fixed it and I have edited my previous post. It loads for me just fine. You may be right about re-declaring variables...I've read the help file a few times but I still don't fully grasp the concept of Global vs Dim vs Local vs just typing $variable = ___.

I like the idea of everything being it's own function, I'll take a look at it. (Re)BuildGUI() is a great idea. That opens the door for lots of other options.

The Open INI function is for manual editing. I may replace it at some point, but for now that's the quickest way for me to rearrange the list and/or delete entries and correct any saved mistakes.

Share this post


Link to post
Share on other sites

@SB

If I understand it correctly - please someone let us know if this is incorrect.

Dim Declares that you will use a piece of memory to hold some information for reuse

Global means that the piece of memory will be available everywhere in the script

Local means that it will only be available within the context it has been defined.

so you can have Dim $Information = 12345 in your main script and also a Local $Information = 222 in a Function which has a different value which doesn't change when you get out of the function.

However if you GLOBAL $Information at the start of the script when you reuse $Information in a Function $Information is changed.

Hope that makes sense.

Some people like to see all the variables they are using at the top of their script to make it easier to see which $variable they should be using way down the line. If you use good names for your variables it will make your life easier.

so $button_AddUser would be easier to use than $Button1ID.

In my script it would have been better to use $button_Email[x] etc to describe the buttons - but I whipped it up super quickly.

Once Each of your things are a function you can add and develop those functions without disturbing other parts of the project.

You can sort the Names you read from the ini before building the gui to have the list sorted for example.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

@SB

If I understand it correctly - please someone let us know if this is incorrect.

Dim Declares that you will use a piece of memory to hold some information for reuse

Global means that the piece of memory will be available everywhere in the script

Local means that it will only be available within the context it has been defined.

so you can have Dim $Information = 12345 in your main script and also a Local $Information = 222 in a Function which has a different value which doesn't change when you get out of the function.

However if you GLOBAL $Information at the start of the script when you reuse $Information in a Function $Information is changed.

Hope that makes sense.

Some people like to see all the variables they are using at the top of their script to make it easier to see which $variable they should be using way down the line. If you use good names for your variables it will make your life easier.

so $button_AddUser would be easier to use than $Button1ID.

In my script it would have been better to use $button_Email[x] etc to describe the buttons - but I whipped it up super quickly.

Once Each of your things are a function you can add and develop those functions without disturbing other parts of the project.

You can sort the Names you read from the ini before building the gui to have the list sorted for example.

I've been here for 4 years now, and haven't seen a better way to explain Dim, Local, and Global. Good job.

Sorry for the bump - didn't see the post date...

Edited by Firestorm

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

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