KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Contol Array

 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Mon Aug 21, 2006 5:23 pm    Post subject: Contol Array Reply with quote

Ok I was using a Control Array to build out 6 labels.
So I decided to try and expand that by making it a total of 30 labels.

The issue that I ran into was that I tried to use 2 dimensional array to do this. From the errors I got, I am assuming that this is the incorrect way to do it.

So now I have to ask is there a way to build my labels that are grouped by two different criteria?

EX: (I don't have the code at work so I am trying to show the layout and grouping not the code I do not have working)

Code:

Label     Label      Label      Label     Label     Label  <------ Group 1

Label     Label      Label      Label     Label     Label  <------ Group 2

Label     Label      Label      Label     Label     Label  <------ Group 3

Label     Label      Label      Label     Label     Label  <------ Group 4

Label     Label      Label      Label     Label     Label  <------ Group 5


Every single label is the same with the exception of position and text

I was able to get it to build out the labels as show by using 2 For Loops
Code:

For $Level1 = 0 to 5
  For $Level2 = 0 to 5
    ;Build label stuff
  Next
Next


The problem that I end up running into is that when I go to assign the text to the label, is the way that it is referenced.

Currently when I build the Label I am doing it this way...

Code:

execute("$Lbl_"+($level1 + $Level2)+" ......)


Any suggestions?

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 21, 2006 6:46 pm    Post subject: Reply with quote

Have you tried displaying-out the contents of your executed strings, to see whats going-on under the covers ?

? "$Lbl_"+($level1 + $Level2)+" ......

Would it make more sense to structure the names of your labels like this:

$Lbl_($level1)_($Level2)

So that there is no confusion or maybe duplicate names ?

-Shawn
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Mon Aug 21, 2006 9:27 pm    Post subject: Reply with quote

Yes I did look at the Values being output and there were duplicates which is what my problem was.

Your solution of

execute("$Lbl_"+$Level1+"_"+$Level2+"...")

should do the trick, just couldn't see the code through the coffee induced haze I geuss.

Another ? would be can you make an array of array's for a control and if so how would you write that?

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Mon Aug 21, 2006 10:29 pm    Post subject: Reply with quote

Just to offer another option, you don't have to create controls with different variable names to be able to locate and affect changes to that control. You can use the .name and .tag properties to identify the control and then use the $form.FindControl("Name") grab the control.

Here is an example of what I am talking about:

Code:

;region Variable Setup
$toparray = 0,20,40,60,80
$leftarray = 0,100,200,300,400
;endregion

Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

$Form = $System.Form()
$Form.StartPosition = 1  ;FormStartPosition_CenterScreen
$Form.Size = $System.Size(528,184) ;(Width,Height)
$Form.Text = "Form1"

$Pnl = $System.Panel()
$Pnl.BorderStyle = 1  ;FixedSingle
$Pnl.Height = 102
$Pnl.Left = 10
$Pnl.Tag = "Label_0_0"
$Pnl.Top = 10
$Pnl.Width = 502
$nul = $Form.Controls.Add($Pnl)

For $Row = 0 to 4
  For $Column = 0 to 4
      Dim $array[2]
      $array[0] = $Row
      $array[1] = $Column
      $Lbl = $System.Label()
      $Lbl.BorderStyle = 1  ;FixedSingle
      $Lbl.Height = 20
      $Lbl.Left = $leftarray[$Column]
      $Lbl.Name = "Label_"+$Row+"_"+$Column
      $Lbl.Tag = $array
      $Lbl.Text = "Label_"+$Row+"_"+$Column
      $Lbl.TextAlign = 16  ;MiddleLeft
      $Lbl.Top = $toparray[$Row]
      $nul = $Pnl.Controls.Add($Lbl)
  Next
Next

$Lbl = $Form.FindControl("Label_0_0")
$Lbl.BackColor = $System.Color.FromName("GradientInactiveCaption")
$Pnl.Tag = $Lbl

$Previous = $System.Button()
$Previous.Click = "Previous_Click()"
$Previous.Left = 180
$Previous.Text = "<<"
$Previous.Top = 120
$nul = $Form.Controls.Add($Previous)

$Next = $System.Button()
$Next.Click = "Next_Click()"
$Next.Left = 260
$Next.Text = ">>"
$Next.Top = 120
$nul = $Form.Controls.Add($Next)

$Form.Show  ;Displays the Form

While $Form.Visible
   $Nul = Execute($Form.DoEvents())
Loop
Exit 0

Function Previous_Click()
   Dim $array[2]
   $Lbl = $Pnl.Tag
   $array = $Lbl.Tag
   $Row = $array[0]
   $Column = $array[1]
   $Lbl.BackColor = $System.Color.FromName("Control")
   If $Column > 0
      $Column = $Column - 1
   Else
      $Column = 4
      If $Row > 0
         $Row = $Row - 1
      Else
         $Row = 4
      EndIf
   EndIf
   $Previous_Lbl_Name = "Label_"+$Row+"_"+$Column
   $Previous_Lbl = $Form.FindControl($Previous_Lbl_Name)
   $Previous_Lbl.BackColor = $System.Color.FromName("GradientInactiveCaption")
   $Pnl.Tag = $Previous_Lbl
EndFunction

Function Next_Click()
   Dim $array[2]
   $Lbl = $Pnl.Tag
   $array = $Lbl.Tag
   $Row = $array[0]
   $Column = $array[1]
   $Lbl.BackColor = $System.Color.FromName("Control")
   If $Column < 4
      $Column = $Column + 1
   Else
      $Column = 0
      If $Row < 4
         $Row = $Row + 1
      Else
         $Row = 0
      EndIf
   EndIf
   $Next_Lbl_Name = "Label_"+$Row+"_"+$Column
   $Next_Lbl = $Form.FindControl($Next_Lbl_Name)
   $Next_Lbl.BackColor = $System.Color.FromName("GradientInactiveCaption")
   $Pnl.Tag = $Next_Lbl
EndFunction

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Mon Aug 21, 2006 10:46 pm    Post subject: Reply with quote

Benny I will look that over tonight (I hope). Thanks
_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Tue Aug 22, 2006 1:27 am    Post subject: Reply with quote

Well, if you want to talk about Control Arrays - in the true sense of the term, here is an example of a two-dimensional control array - of labels:

Code:

Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form()
$Form.Size = $System.Size(700,480)

Dim $Controls[18,8]

$Left = 5
$Top = 5
For $i = 0 To UBound($Controls,1)
 For $j = 0 To UBound($Controls,2)
  $Controls[$i,$j] = $FOrm.Controls.Add($System.Label())
  $Controls[$i,$j].Left = $Left
  $Controls[$i,$j].Top = $Top
  $Controls[$i,$j].Width = 75
  $Controls[$i,$j].Text = "Label-" + $i + $j
  $Controls[$i,$j].BackColor = $System.Color.FromRgb(RND(255),RND(255),RND(255))
  $Left = $Controls[$i,$j].Right
 Next
 $Top = $Controls[$i,$j-1].Bottom
 $Left = 5
Next

$Form.Center
$Form.Show

While $form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Tue Aug 22, 2006 1:48 am    Post subject: Reply with quote

Preeeetty Collllors
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Tue Aug 22, 2006 6:10 am    Post subject: Reply with quote

You know Shawn I tried something like that (don't have the exact syntax anymore) and it errored on me, I had assumed that 2D arrays was not supported.

I like the elegance of what you have done. And will have to go over it a bit more to understand how to adapt it.

But for grins and giggles here is my original code.

Code:

$Left = 15
$Top = 250
For $Pick = 1 to 5
     For $ = 1 to 5
        $nul = execute("$LBL_RNUM"+($Pick+$)+"=$Form1.Controls.Add($System.Label) ")
        $nul = execute("$LBL_RNUM"+($Pick+$)+".BorderStyle = 1")
        $nul = execute("$LBL_RNUM"+($Pick+$)+".Left = $Left ")
        $nul = execute("$LBL_RNUM"+($Pick+$)+".Top = $Top")
        $nul = execute("$LBL_RNUM"+($Pick+$)+".Width = 20 ")
        $nul = execute("$LBL_RNUM"+($Pick+$)+".Backcolor = $System.Color.FromName('White')")
        $Left = $Left + 40
   Next
   $ = 6
     $nul = execute("$LBL_RNUM"+($Pick+$)+"=$Form1.Controls.Add($System.Label) ")
     $nul = execute("$LBL_RNUM"+($Pick+$)+".BorderStyle = 1")
     $nul = execute("$LBL_RNUM"+($Pick+$)+".Left = $Left ")
     $nul = execute("$LBL_RNUM"+($Pick+$)+".Top = $Top")
     $nul = execute("$LBL_RNUM"+($Pick+$)+".Width = 20 ")
     $nul = execute("$LBL_RNUM"+($Pick+$)+".Backcolor = $System.Color.FromName('Red')")
   $Top = $top + 30
   $Left = 15
Next
Regenerate()


Function Regenerate()

For $Pick = 1 to 5
  RandomGenerate(5,55)
   For $ = 1 to 5
        $nul = execute("$LBL_RNUM"+($Pick+$)+".Text = $output[$]")
   Next
   $ = 6
     $nul = execute("$LBL_RNum"+($Pick+$)+".Text = RND(41) + 1")

Next
EndFunction

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Tue Aug 22, 2006 12:56 pm    Post subject: Reply with quote

So here is what I ended up with....

Code:

$Left = 15
$Top = 250
For $Pick = 1 to 5
     For $ = 1 to 5
        $LBL_RNUM[$Pick,$]=$Form1.Controls.Add($System.Label)
        $LBL_RNUM[$Pick,$].BorderStyle = 1
        $LBL_RNUM[$Pick,$].Left = $Left
        $LBL_RNUM[$Pick,$].Top = $Top
        $LBL_RNUM[$Pick,$].Width = 20
        $LBL_RNUM[$Pick,$].Backcolor = $System.Color.FromName('White')
        $Left = $Left + 40
   Next
     $LBL_RNUM[$Pick,6]=$Form1.Controls.Add($System.Label)
     $LBL_RNUM[$Pick,6].BorderStyle = 1
     $LBL_RNUM[$Pick,6].Left = $Left
     $LBL_RNUM[$Pick,6].Top = $Top
     $LBL_RNUM[$Pick,6].Width = 20
     $LBL_RNUM[$Pick,6].Backcolor = $System.Color.FromName('Red')
   $Top = $top + 30
   $Left = 15
Next


Function RandomGenerate($howmany,$limit)
Global $output[$howmany]
$R = Rnd($Limit)

$= 0
While $ <= $howmany
   If Ascan($Output,$r) = -1
      $output[$] = $r
      $ = $ + 1
   Else
      $R = RND($Limit)
       Endif
Loop
EndFunction

Function Regenerate()

For $Pick = 1 to 5
  RandomGenerate(5,55)
   For $ = 1 to 5
        $LBL_RNUM[$Pick,$].Text = $output[$]
   Next
     $LBL_RNuM[$Pick,6].Text = RND(41) + 1

Next
EndFunction

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group