Sign in to follow this  
Followers 0
pancwk

GuiCtrlCreateInput

9 posts in this topic

Hello, I am a newbie on AutoIt. I created a GUI using it. But it seems not working as expected. I used GuiCtrlCreateInput and GUICtrlRead. It seems when I changed the value from the GUI interface, GUICtrlRead does not read the new value. Can anyone help me to point out what is wrong with my codes?

#include <GUIConstants.au3>

Opt("GUIOnEventMode",1)

GUICreate("PK Trader", 165, 120)

WinSetOnTop("PK Trader", "", 1)

; MENU

;GuiCtrlCreateMenu("Menu&One")

;GuiCtrlCreateMenu("Menu&Two")

; CONTEXT MENU

$contextMenu = GuiCtrlCreateContextMenu()

GuiCtrlCreateMenuItem("Context Menu", $contextMenu)

GuiCtrlCreateMenuItem("", $contextMenu) ;separator

GuiCtrlCreateMenuItem("&Properties", $contextMenu)

;first row

GuiCtrlCreateLabel("SL:", 5, 0, 20, 20)

;GuiCtrlSetBkColor(-1, 0x00FF00)

$slID = GuiCtrlCreateInput("50", 25, 0, 30, 20)

$sl = GUICtrlRead($slID)

GuiCtrlCreateLabel("pips", 65, 0, 30, 20)

GuiCtrlCreateLabel("TP:", 105, 0, 20, 20)

$tpID = GuiCtrlCreateInput("50", 125, 0, 30, 20)

$tp= GUICtrlRead($tpID)

;second row

GuiCtrlCreateLabel("BE:", 5, 20, 20, 20)

$beID = GuiCtrlCreateInput("50", 25, 20, 30, 20)

$be = GUICtrlRead($beID)

GuiCtrlCreateLabel("pips", 65, 20, 30, 20)

GuiCtrlCreateLabel("TS:", 105, 20, 20, 20)

$tsID = GuiCtrlCreateInput("50", 125, 20, 30, 20)

$ts = GUICtrlRead($tsID)

;third row

$buyID = GUICtrlCreateButton("Buy", 0, 50, 50, 35)

GUICtrlSetOnEvent($buyID,"onBuy")

#cs

$symbolID = GuiCtrlCreateCombo("", 55, 45, 65, 20)

GUICtrlSetData($symbolID,"EURUSD|GBPUSD|USDCHF|USDJPY","EURUSD")

$symbol = GUICtrlRead($symbolID)

#ce

$symbolID = GuiCtrlCreateInput("EURUSD", 55, 45, 55, 20)

$symbol = GUICtrlRead($symbolID)

GuiCtrlCreateLabel("qnt:", 55, 70, 30, 20)

$qntID = GuiCtrlCreateInput("1", 85, 65, 25, 20)

$qnt = GUICtrlRead($qntID)

$sellID = GUICtrlCreateButton("Sell", 115, 50, 50, 35)

GUICtrlSetOnEvent($sellID,"onSell")

;forth row

$slipEnable = GuiCtrlCreateCheckbox("", 0, 95, 20, 20)

GuiCtrlSetState(-1, $GUI_CHECKED)

GuiCtrlCreateLabel("slip:", 20, 95, 30, 20)

$slipID = GuiCtrlCreateInput("2", 55, 95, 15, 20)

$slip = GUICtrlRead($slipID)

$pendID = GUICtrlCreateButton("ppo", 80, 95, 30, 20)

GuiCtrlCreateLabel("ID:", 120, 95, 20, 20)

$sysID = GuiCtrlCreateInput("0", 140, 95, 20, 20)

$sysIDn = GUICtrlRead($sysID)

GUISetOnEvent($GUI_EVENT_CLOSE,"OnExit")

GUISetState() ; display the GUI

While 1

Sleep (1000)

WEnd

;--------------- Functions ---------------

Func onBuy()

$file = FileOpen("pkOrder.csv", 2)

; Check if file opened for writing OK

If $file = -1 Then

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

Exit

EndIf

FileWrite($file, "OP_BUY" & "," & $qnt & "," & $symbol & "," & $slip & "," & $sl & "," & $be & "," & $ts & "," & $sysIDn & ",")

FileClose($file)

EndFunc

Func onSell()

$file = FileOpen("pkOrder.csv", 2)

If $file = -1 Then

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

Exit

EndIf

FileWrite($file, "OP_SELL" & "," & $qnt & "," & $symbol & "," & $slip & "," & $sl & "," & $be & "," & $ts & "," & $sysIDn & ",")

FileClose($file)

EndFunc

Func OnExit()

Exit

EndFunc

Share this post


Link to post
Share on other sites



Hello, I am a newbie on AutoIt. I created a GUI using it. But it seems not working as expected. I used GuiCtrlCreateInput and GUICtrlRead. It seems when I changed the value from the GUI interface, GUICtrlRead does not read the new value. Can anyone help me to point out what is wrong with my codes?

#include <GUIConstants.au3>

Opt("GUIOnEventMode",1)

GUICreate("PK Trader", 165, 120)

WinSetOnTop("PK Trader", "", 1)

; MENU

;GuiCtrlCreateMenu("Menu&One")

;GuiCtrlCreateMenu("Menu&Two")

; CONTEXT MENU

$contextMenu = GuiCtrlCreateContextMenu()

GuiCtrlCreateMenuItem("Context Menu", $contextMenu)

GuiCtrlCreateMenuItem("", $contextMenu) ;separator

GuiCtrlCreateMenuItem("&Properties", $contextMenu)

;first row

GuiCtrlCreateLabel("SL:", 5, 0, 20, 20)

;GuiCtrlSetBkColor(-1, 0x00FF00)

$slID = GuiCtrlCreateInput("50", 25, 0, 30, 20)

$sl = GUICtrlRead($slID)

GuiCtrlCreateLabel("pips", 65, 0, 30, 20)

GuiCtrlCreateLabel("TP:", 105, 0, 20, 20)

$tpID = GuiCtrlCreateInput("50", 125, 0, 30, 20)

$tp= GUICtrlRead($tpID)

;second row

GuiCtrlCreateLabel("BE:", 5, 20, 20, 20)

$beID = GuiCtrlCreateInput("50", 25, 20, 30, 20)

$be = GUICtrlRead($beID)

GuiCtrlCreateLabel("pips", 65, 20, 30, 20)

GuiCtrlCreateLabel("TS:", 105, 20, 20, 20)

$tsID = GuiCtrlCreateInput("50", 125, 20, 30, 20)

$ts = GUICtrlRead($tsID)

;third row

$buyID = GUICtrlCreateButton("Buy", 0, 50, 50, 35)

GUICtrlSetOnEvent($buyID,"onBuy")

#cs

$symbolID = GuiCtrlCreateCombo("", 55, 45, 65, 20)

GUICtrlSetData($symbolID,"EURUSD|GBPUSD|USDCHF|USDJPY","EURUSD")

$symbol = GUICtrlRead($symbolID)

#ce

$symbolID = GuiCtrlCreateInput("EURUSD", 55, 45, 55, 20)

$symbol = GUICtrlRead($symbolID)

GuiCtrlCreateLabel("qnt:", 55, 70, 30, 20)

$qntID = GuiCtrlCreateInput("1", 85, 65, 25, 20)

$qnt = GUICtrlRead($qntID)

$sellID = GUICtrlCreateButton("Sell", 115, 50, 50, 35)

GUICtrlSetOnEvent($sellID,"onSell")

;forth row

$slipEnable = GuiCtrlCreateCheckbox("", 0, 95, 20, 20)

GuiCtrlSetState(-1, $GUI_CHECKED)

GuiCtrlCreateLabel("slip:", 20, 95, 30, 20)

$slipID = GuiCtrlCreateInput("2", 55, 95, 15, 20)

$slip = GUICtrlRead($slipID)

$pendID = GUICtrlCreateButton("ppo", 80, 95, 30, 20)

GuiCtrlCreateLabel("ID:", 120, 95, 20, 20)

$sysID = GuiCtrlCreateInput("0", 140, 95, 20, 20)

$sysIDn = GUICtrlRead($sysID)

GUISetOnEvent($GUI_EVENT_CLOSE,"OnExit")

GUISetState() ; display the GUI

While 1

Sleep (1000)

WEnd

;--------------- Functions ---------------

Func onBuy()

$file = FileOpen("pkOrder.csv", 2)

; Check if file opened for writing OK

If $file = -1 Then

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

Exit

EndIf

FileWrite($file, "OP_BUY" & "," & $qnt & "," & $symbol & "," & $slip & "," & $sl & "," & $be & "," & $ts & "," & $sysIDn & ",")

FileClose($file)

EndFunc

Func onSell()

$file = FileOpen("pkOrder.csv", 2)

If $file = -1 Then

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

Exit

EndIf

FileWrite($file, "OP_SELL" & "," & $qnt & "," & $symbol & "," & $slip & "," & $sl & "," & $be & "," & $ts & "," & $sysIDn & ",")

FileClose($file)

EndFunc

Func OnExit()

Exit

EndFunc

You read the contents of the inputs as soon as you have created, which is not useful since you know what's in them at that stage.

You must read them when you need to know what's in them.

You must have something inside your while, wend loop.

Say you add a button $Btn1

$Btn1 = GUICtrlCreateButton("show what's in an input", 20, 105, 120, 21)

then you could have

while 1
 $msg = GUIGetMsg()

 if $msg = $GUI_EVENT_CLOSE Then ExitLoop

 if $msg = $Btn1 then
  msgbox(0,'Input $slID is', GUICtrlRead($slID))
 endif

wend

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

GUICtrlRead() must be inside your functions as martin said.

@martin: He used Opt("GUIOnEventMode",1) so his main Loop can stay as is.

Yes, thanks Zedna, I didn't read it properly.

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

must be inside your functions as martin said.

@martin: He used Opt("GUIOnEventMode",1) so his main Loop can stay as is.

Thanks a lot. I did as you told. It works.

another question is: the return value of GUICtrlRead() of a checkbox is 1 if it is checked, 4 if not checked. right?

Share this post


Link to post
Share on other sites

For chekcbox i would reccomend using guictrlgetstate it will then return $GUI_CHECKED or $GUI_UNCHECKED

Share this post


Link to post
Share on other sites

For chekcbox i would reccomend using guictrlgetstate it will then return $GUI_CHECKED or $GUI_UNCHECKED

Thanks a lot!

Share this post


Link to post
Share on other sites

Thanks every one here in this forum who helped me. now my application is ready for trys for users in the Metatrader community, and I name my application pkTrader. if any one here is interested in what I did by using a combination of AutoIt and mql4,he can download and test what I did.

I realy love AutoIt.

the link to download pkTrader:

http://www.wsforex.com/pktrader/PKTrader2.zip

or

http://f1.grp.yahoofs.com/v1/ABmhRaVhpVZN0...r/PKTrader2.zip

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