Jump to content

GUI Display


Recommended Posts

I'm creating a GUI with each letter of the alphabet as a button. I tried arrays (commented code) but got out of range, so I'm using the _ArrayAdd.

What is wrong with the commented code?

For some reason some of the buttons are out of alphabetical order.

I'm going to expand this program later to create a simple alphabet program (I was going to do it in Director, but I want to create a small filesize right now).

Code:

dim $letter[26]

$centered=-1

$Xstart=10

$Ystart=10

$Xoffset=50

$Yoffset=35

$count=0

$mywindow=GUICreate("My 1st Window",400,400,$centered,$centered)

;,WS_Popup,$WS_EX_CLIENTEDGE))

;create the alphabet using buttons

;each letter is a button

$x=65

$array_pos=0

msgbox(0,"",Chr($x))

while ($x<=90)

if $count=5 then

;msgbox(0,"",$x)

$letter_id=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart+$Yoffset, 50)

_ArrayAdd ( $letter, $letter_id )

$count=0

$xstart=10

;$letter[$array_pos]=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart+$Yoffset, 50)

$Ystart=$YStart+$Yoffset

else

$letter_id=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart, 50)

_ArrayAdd ( $letter, $letter_id )

$count=$count+1

$xstart=$xstart+$xoffset

;$letter[$array_pos]=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart, 50)

endif

$x=$x+1

;$array_pos=$array_pos+1

wend

GUISetState (@SW_SHOW)

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

;end of code

;Thanks :idiot:

Edited by closeupman
Link to comment
Share on other sites

I've tinkered with the code a bit more. I want to get the chosen letter, but for some reason $x resets to 0, so it screws w/my control id's.

#include <guiconstants.au3>

#include <string.au3>

#include <Array.au3>

;used to hold the control id of the button of each letter

dim $letter[26]

;used to center window

$centered=-1

;used to place buttons (i.e. letters)

$Xstart=10

$Ystart=10

$Xoffset=50

$Yoffset=35

;used to let us know when to go to the next line

;to place another row of buttons

$count=0

$mywindow=GUICreate("My 1st Window",400,400,$centered,$centered)

;,WS_Popup,$WS_EX_CLIENTEDGE))

;create the alphabet using buttons

;each letter is a button

;use 65-90 and Chr to turn into a Capital Letter for the button

$x=65

;used only if we do subscript reference with arrays

;$array_pos=0

$index=0

while (($x+$index)<=90)

msgbox(0,"111111111",$x+$index)

if $count=5 then

;display 5 letters per line

;when count = 5, indicates that you need to go to the next line

;and start over

;so reset xstart and count

$letter_id=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart+$Yoffset, 50)

;msgbox(0,"",$letter_id)

_ArrayInsert ( $letter,$index, $letter_id )

$count=0

$xstart=10

;$letter[$array_pos]=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart+$Yoffset, 50)

$Ystart=$YStart+$Yoffset

else

;we haven't put 5 letters on this line yet

;place the letter

;increase the count

;increase xstart for the next button

$letter_id=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart, 50)

;msgbox(0,"",$letter_id)

_ArrayInsert ( $letter, $index,$letter_id )

$count=$count+1

$xstart=$xstart+$xoffset

;$letter[$array_pos]=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart, 50)

endif

$index=$index+1

;$array_pos=$array_pos+1

wend

_ArrayDisplay( $letter, "_ArrayDisplay() Test" )

;msgbox(0,"",Chr(90))

GUISetState (@SW_SHOW)

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then

ExitLoop

else

;tell which letter was chosen

$letter_id=0

;msgbox(0,"","You Chose " & $msg & " " & $letter[$letter_id])

;$chosen_letter=65

;while $chosen_letter<=90

; if $msg=$letter[$letter_id] then

; msgbox(0,"","You Chose " & Chr($chosen_letter))

; exitloop

; endif

;$chosen_letter=$chosen_letter+1

;$letter_id=$letter_id+1

;wend

endif

Wend

Link to comment
Share on other sites

Cant you do a $i = 26, For Every $i to $i2 = $i2+1 and if $is = 1 then A etc....

Why dont u just make the buttons.....?

<{POST_SNAPBACK}>

I'll try that.

I am making buttons...using the Gui function to....it's easier than if what you're saying to do is to make my own.

I still am wondering what was wrong w/my array code. I know I like to make things complicated, so if you can redesign my code to make it simpler, by all means. Post it here.

Thanks

:idiot:

Link to comment
Share on other sites

Finally got it to work....in a manner speaking lol

I get the choice done now, but for some reason the buttons are out of alphabetical

order on the form, even though they are correct in the array.

Anyone can write my code my elegantly and simpler?

Also, why in my previous code post was $x=65 up above when creating the buttons, resetting to 0? It was 65 then reset to 0 even though I didn't change it in the While loop.

Here's the new code:

#include <guiconstants.au3>
#include <string.au3>
#include <Array.au3>
;used to hold the control id of the button of each letter
dim $letter[26]

;used to center window
$centered=-1

;used to place buttons (i.e. letters)
$Xstart=10
$Ystart=10
$Xoffset=50
$Yoffset=35

;used to let us know when to go to the next line
;to place another row of buttons
$count=0

$mywindow=GUICreate("My 1st Window",400,400,$centered,$centered)
;,WS_Popup,$WS_EX_CLIENTEDGE))

;create the alphabet using buttons
;each letter is a button
;use 65-90 and Chr to turn into a Capital Letter for the button



;used only if we do subscript reference with arrays
;$array_pos=0

For $index=0 to 25
  
  if $count=5 then
  ;display 5 letters per line
  ;when count = 5, indicates that you need to go to the next line
  ;and start over
  ;so reset xstart and count

      $letter_id=GUICtrlCreateButton (Chr(65+$index),$Xstart+$Xoffset, $Ystart+$Yoffset, 50)
  ;msgbox(0,"",Chr(65+$index))
      _ArrayInsert ( $letter,$index, $letter_id )
      $count=0
    $xstart=10

  ;$letter[$array_pos]=GUICtrlCreateButton (Chr(65+$index),$Xstart+$Xoffset,   ;Ystart+$Yoffset,50)
      $Ystart=$YStart+$Yoffset


  else 
 ;we haven't put 5 letters on this line yet
 ;place the letter
 ;increase the count 
 ;increase xstart for the next button

    $letter_id=GUICtrlCreateButton (Chr(65+$index),$Xstart+$Xoffset, $Ystart, 50)
   ;msgbox(0,"",Chr(65+$index))
    _ArrayInsert ( $letter, $index,$letter_id )
    $count=$count+1
    $xstart=$xstart+$xoffset

 ;$letter[$array_pos]=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart, 50)

  endif

  

 ;$array_pos=$array_pos+1
Next

_ArrayDisplay( $letter, "_ArrayDisplay() Test" )
;msgbox(0,"",Chr(90))

GUISetState (@SW_SHOW)

While 1
  $msg = GUIGetMsg()

  If $msg = $GUI_EVENT_CLOSE Then
    ExitLoop
  else
;tell which letter was chosen
    For $x=0 to 26
     if ($letter[$x]>0) and ($msg > 0) then
        ; if the two values(button control id)
            ; are equal then that is the letter chosen.
        ;so do whatever you want associated with that letter
        ;and get out of this For..Next by setting $x to the
        ;end value
         if $letter[$x] = $msg then
          msgbox(0,"","You Chose ME " & Chr(65+$X))
          $x=26 
         endif
    ;endif
     endif
    Next
  endif
Wend
Link to comment
Share on other sites

Finally got it to work....in a manner speaking lol

I get the choice done now, but for some reason the buttons are out of alphabetical

order on the form, even though they are correct in the array.

This fixes the ABC button arrangement problem you were having. It makes 5 rows of 5 buttons each plus a 6th row with only Z.

For $index = 0 To 25
  If $count = 5 Then
   ;display 5 letters per line
   ;when count = 5, indicates that you need to go to the next line
   ;and start over
   ;so reset xstart and count
    $count = 0
    $Xstart = 10
    $Ystart = $Ystart + $Yoffset
   ;$letter[$array_pos]=GUICtrlCreateButton (Chr(65+$index),$Xstart+$Xoffset,  ;Ystart+$Yoffset,50)
  EndIf
 ;we haven't put 5 letters on this line yet
 ;place the letter
 ;increase the count
 ;increase xstart for the next button
  $letter_id = GUICtrlCreateButton(Chr(65 + $index), $Xstart + $Xoffset, $Ystart, 50)
 ;msgbox(0,"",Chr(65+$index))
  _ArrayInsert ($letter, $index, $letter_id)
  $count = $count + 1
  $Xstart = $Xstart + $Xoffset
 ;$letter[$array_pos]=GUICtrlCreateButton (Chr($x),$Xstart+$Xoffset, $Ystart, 50)
 ;$array_pos=$array_pos+1
Next

Phillip

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...