5 Replies - 522 Views - Last Post: 16 April 2009 - 08:28 PM Rate Topic: -----

#1 seadog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-April 09

Labels

Posted 16 April 2009 - 04:52 AM

Hi all, my name is Rob, I am a caual user of VB6, I like reproduce things I see, like slot machines etc, at the moment I am trying to reproduce the Matrix back screen with the green text on black background falling from top to botton of the screen, I am trying to stream line my code by letting a loop do most of the work for me.
I am using a loop to create a series of labels to hold the text that falls down the screen, below is the code I am using, the issue is I don't want to do this for every array of labels, i.e. label1(0), Label1(1), label2(0), Label2(1), Label3(0), Label3(1) etc. etc..
I would like to create a snippet of code that builds the labels for me, but the issue I have is that I can't work out how to index each label, Label(x) rather that Label1, Label2 etc.

Any ideas.

Cheers

Seadog

for TheArray = 1 to 100
		Load Label1(TheArray)
		Label1(TheArray).Caption = Chr(RandomNumberGenerator(100))
		Label1(TheArray).Top = 720
		Label1(TheArray).Left = ((TheArray * 200))
		Label1(TheArray).FontBold = True
		Label1(TheArray).Visible = True

		Load Label2(TheArray)
		Label2(TheArray).Caption = Chr(RandomNumberGenerator(100))
		Label2(TheArray).Top = 480
		Label2(TheArray).Left = ((TheArray * 200))
		Label2(TheArray).FontBold = True
		Label2(TheArray).Visible = True
		
		Load Label3(TheArray)
		Label3(TheArray).Caption = Chr(RandomNumberGenerator(100))
		Label3(TheArray).Top = 240
		Label3(TheArray).Left = ((TheArray * 200))
		Label3(TheArray).FontBold = True
		Label3(TheArray).Visible = True

		Load Label4(TheArray)
		Label4(TheArray).Caption = Chr(RandomNumberGenerator(100))
		Label4(TheArray).Top = 0
		Label4(TheArray).Left = ((TheArray * 200))
		Label4(TheArray).FontBold = True
		Label4(TheArray).Visible = True

		etc
		etc
next TheArray


This post has been edited by seadog: 16 April 2009 - 04:58 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Labels

#2 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 91
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: Labels

Posted 16 April 2009 - 04:55 AM

Hi.
Please post like this: :code:

and I will have a think about this one...
Was This Post Helpful? 0
  • +
  • -

#3 seadog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-April 09

Re: Labels

Posted 16 April 2009 - 05:00 AM

View Postfirebolt, on 16 Apr, 2009 - 03:55 AM, said:

Hi.
Please post like this: :code:

and I will have a think about this one...


Done.

Cheer

Rob
Was This Post Helpful? 0
  • +
  • -

#4 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 48
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

Re: Labels

Posted 16 April 2009 - 06:29 AM

I hate using arrays so here's another idea.

1) Use same set of label boxes, move them to the bottom using a timer control.
2) When they reach the bottom edge of form, again, move them to the top.
3) Be careful with the alignment, you can create a nice looking program using some basic designing sense.

:^:
Was This Post Helpful? 0
  • +
  • -

#5 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 48
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

Re: Labels

Posted 16 April 2009 - 08:02 PM

here's something..

Click
Was This Post Helpful? 0
  • +
  • -

#6 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: Labels

Posted 16 April 2009 - 08:28 PM

have a look at some others coding of the same...

http://search.yahoo....c...ss&ei=UTF-8

and this is an example of how you can load labels (or any other control that has an index property) at runtime.

Start a new standard exe project
Add label (label1) to your form and set its font properties to what you want.
Set its index (via properties) to zero (0)
add code
Option Explicit

Private Sub Form_Load()
Dim ForLoopCounter As Integer
For ForLoopCounter = 1 To 10
  Load Label1(ForLoopCounter)
  Label1(ForLoopCounter).Left = Label1(ForLoopCounter - 1).Left + Label1(ForLoopCounter - 1).Width + 30
  Label1(ForLoopCounter).Visible = True
Next ForLoopCounter
End Sub



Good Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1