Sign in to follow this  
Followers 0
alie

Problem with Label CTRLID's

3 posts in this topic

hello,

my problem is described in the first comment of the script, sorry if I didnt use correct english and couldnt exactly tell my problem very well.

CODE
;This script should transfer the data of an editbox on a set of labels. To realize that, I created an invisible editbox that have controlfocus

;and an array of labels that should show the editboxtext. During a while-loop changes in the editbox are detected and transfered to the labelset.

;The update of new text works well, but when i created the "backspace-function" i got into troubles that I don't understand: The labelarray gives

;the wrong control-id's when I try to get them with the position.

#include<guiconstantsex.au3>

#include<windowsconstants.au3>

HotKeySet("q", "_quit") ;sets exitfunction

GUICreate("GUITest", 600, 400, -1, -1, $WS_POPUP)

Opt("GUIOnEventMode", 1)

Opt("MouseCoordMode", 0)

$EditBox = GUICtrlCreateEdit("", 0, 0, 600, 400)

GUICtrlSetState(-1, $GUI_HIDE)

ControlFocus("GUITest", "", $EditBox)

$KeyInput = GUICtrlRead($EditBox)

Dim $CursorX = 0, $CursorY = 0, $TextPosX = 0, $TextPosY = 0 ;the cursor-vars of create labelset and change labeldata

Dim $LabelList[32][22] ;the array for the labels sorted by position

_CreateLabels() ;creates the labelset on GUI

While 1

Sleep(10)

If StringLen(GUICtrlRead($EditBox)) > StringLen($KeyInput) Then ;If the string got longer the function "_AddInput" is called

$KeyInput = GUICtrlRead($EditBox)

_AddInput()

EndIf

If StringLen(GUICtrlRead($EditBox)) < StringLen($KeyInput) Then ;If the string got shorter the function "_eraseInput" is called

$KeyInput = GUICtrlRead($EditBox)

_eraseinput()

EndIf

WEnd

;This function fills GUI with empty labels with unique arrayid's depending on position.

Func _CreateLabels()

For $x = 1 To 20

$LabelList[$CursorX / 20][$CursorY / 20] = GUICtrlCreateLabel("", $CursorX, $CursorY, 20, 20)

GUICtrlSetFont(-1, 12)

GUICtrlSetOnEvent(-1, "_test")

For $x2 = 1 To 30

$CursorX = $CursorX + 20

$LabelList[$CursorX / 20][$CursorY / 20] = GUICtrlCreateLabel("", $CursorX, $CursorY, 20, 20)

GUICtrlSetFont(-1, 12)

GUICtrlSetOnEvent(-1, "_test")

Next

$CursorY = $CursorY + 20

$CursorX = 0

Next

GUISetState()

EndFunc ;==>_CreateLabels

;This function refreshes the labels with new letters, creating new lines at linefeeds and lineends.

Func _AddInput()

If Asc(StringRight($KeyInput, 1)) <> 8 Then ;checks if a linefeed

If Asc(StringRight($KeyInput, 1)) <> 10 Then ;or carriage return were sent

MsgBox(1, "", $TextPosX & "," & $TextPosY & "," & $LabelList[$TextPosX][$TextPosY]) ;shows a testmsg of actual x-position, y-position and control id

$LabelList[$TextPosX][$TextPosY] = GUICtrlSetData($LabelList[$TextPosX][$TextPosY], StringRight($KeyInput, 1))

MsgBox(1, "", $TextPosX & "," & $TextPosY & "," & $LabelList[$TextPosX][$TextPosY]) ;shows a testmsg of actual x-position, y-position and control id

Else ;again but it shows the wrong control id

$TextPosY += 1

$TextPosX = -1

EndIf

EndIf

$TextPosX += 1

If $TextPosX = 30 Then ;checks for lineend by position

$TextPosY += 1

$TextPosX = 0

EndIf

EndFunc ;==>_AddInput

;This function shoud erase the last letter-label.

Func _eraseinput()

$TextPosX -= 1

MsgBox(1, "", $TextPosX & "," & $TextPosY & "," & $LabelList[$TextPosX][$TextPosY]) ;here my problem is shown in a msg: the control id is not the correct one

GUICtrlSetData($LabelList[$TextPosX][$TextPosY], "") ;but every time an 1.

If $TextPosX = 0 Then

$TextPosX = 30

$TextPosY -= 1

EndIf

EndFunc ;==>_eraseinput

;Testfunction to check position - and controlid's.

Func _test()

GUICtrlSetData($LabelList[Round(MouseGetPos(0) / 20, 1)][Round(MouseGetPos(1) / 20, 1)], InputBox("", "")) ;testing the position id works fine here

EndFunc ;==>_test

;Quitfunction and output of the original editboxtext.

Func _quit()

MsgBox(1, "", GUICtrlRead($EditBox))

Exit

EndFunc ;==>_quit

it would make me very happy, if anyone could help me with this problem,

thx jakob.

Share this post


Link to post
Share on other sites



hello

found that silly mistake.

thx a lot for your method to catch text, but i m not really able to understand it. but my scripts are complicated by default.

jakob.

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