473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Create variable amount of labels (Visual Basic newbie)

Hi,

I'm trying to create a programme which generates a matrix with variable sized rows and columns. Now to reduce the amount of useless code i want to have it so that the labels are automatically generated.

I've tried creating an array of labels.

The following code seems to work when i debug it but the labels do not show up on the form after running. It does not stall or crash it just executes the program and that's it. What code do i need to make the labels appear on the form?

Or may it be that they just fall of the screen? Maybe i chose the coordinates wrong?.

Expand|Select|Wrap|Line Numbers
  1. Imports System.Math
  2.  
  3. Public Class frmMatrix
  4.     Dim lblKolom() As System.Windows.Forms.Label
  5.  
  6.     Private Sub btnBereken_Click(....
  7.         Dim intPicX, intPicY, intPixelWaarde, intTellerX, intTellerY As Integer
  8.         Dim intMatrix(,) As Integer
  9.         Dim strKolom As String = ""
  10.         Dim strPixel As String
  11.  
  12.  
  13.         intPicX = Rnd() * 5 + 4
  14.         intPicY = Rnd() * 5 + 4
  15.         ReDim intMatrix(intPicX - 1, intPicY - 1)
  16.         ReDim lblKolom(intPicX - 1)
  17.  
  18.         For intTellerX = 0 To intPicX - 1
  19.             Me.lblKolom(intTellerX) = New System.Windows.Forms.Label
  20.             Me.lblKolom(intTellerX).Location = New System.Drawing.Point(12, 49 + (intPicX * 24))
  21.             Me.lblKolom(intTellerX).Name = "Kolom" + Str(intTellerX)
  22.             Me.lblKolom(intTellerX).TabIndex = intTellerX + 2
  23.             Me.lblKolom(intTellerX).AutoSize = True
  24.             Me.lblKolom(intTellerX).Visible = True
  25.             Me.lblKolom(intTellerX).TextAlign = ContentAlignment.MiddleCenter
  26.             Me.lblKolom(intTellerX).BackColor = Color.CadetBlue
  27.             Me.lblKolom(intTellerX).Show()
  28.  
  29.         Next intTellerX
  30.  
  31.         For intTellerX = 0 To intPicX - 1
  32.             For intTellerY = 0 To intPicY - 1
  33.                ...
  34.             Next intTellerY
  35.             lblKolom(intTellerX).Text = strKolom
  36.             ...
  37.         Next intTellerX
  38.     End Sub
  39.  
  40.     Private Sub Form1_Load(...
  41.         Randomize()
  42.     End Sub
  43.  
  44. End Class
Thanks i.a.
Nov 13 '06 #1
10 3958
willakawill
1,646 1GB
Hi,

I'm trying to create a programme which generates a matrix with variable sized rows and columns. Now to reduce the amount of useless code i want to have it so that the labels are automatically generated.

I've tried creating an array of labels.

The following code seems to work when i debug it but the labels do not show up on the form after running. It does not stall or crash it just executes the program and that's it. What code do i need to make the labels appear on the form?

Or may it be that they just fall of the screen? Maybe i chose the coordinates wrong?.

Expand|Select|Wrap|Line Numbers
  1. Imports System.Math
  2.  
  3. Public Class frmMatrix
  4.     Dim lblKolom() As System.Windows.Forms.Label
  5.  
  6.     Private Sub btnBereken_Click(....
  7.         Dim intPicX, intPicY, intPixelWaarde, intTellerX, intTellerY As Integer
  8.         Dim intMatrix(,) As Integer
  9.         Dim strKolom As String = ""
  10.         Dim strPixel As String
  11.  
  12.  
  13.         intPicX = Rnd() * 5 + 4
  14.         intPicY = Rnd() * 5 + 4
  15.         ReDim intMatrix(intPicX - 1, intPicY - 1)
  16.         ReDim lblKolom(intPicX - 1)
  17.  
  18.         For intTellerX = 0 To intPicX - 1
  19.             Me.lblKolom(intTellerX) = New System.Windows.Forms.Label
  20.             Me.lblKolom(intTellerX).Location = New System.Drawing.Point(12, 49 + (intPicX * 24))
  21.             Me.lblKolom(intTellerX).Name = "Kolom" + Str(intTellerX)
  22.             Me.lblKolom(intTellerX).TabIndex = intTellerX + 2
  23.             Me.lblKolom(intTellerX).AutoSize = True
  24.             Me.lblKolom(intTellerX).Visible = True
  25.             Me.lblKolom(intTellerX).TextAlign = ContentAlignment.MiddleCenter
  26.             Me.lblKolom(intTellerX).BackColor = Color.CadetBlue
  27.             Me.lblKolom(intTellerX).Show()
  28.  
  29.         Next intTellerX
  30.  
  31.         For intTellerX = 0 To intPicX - 1
  32.             For intTellerY = 0 To intPicY - 1
  33.                ...
  34.             Next intTellerY
  35.             lblKolom(intTellerX).Text = strKolom
  36.             ...
  37.         Next intTellerX
  38.     End Sub
  39.  
  40.     Private Sub Form1_Load(...
  41.         Randomize()
  42.     End Sub
  43.  
  44. End Class
Thanks i.a.
Hi. A couple of things spring to mind with this code.
When you declare variables in this format:
Dim intPicX, intPicY, intPixelWaarde, intTellerX, intTellerY As Integer
only the last one, intTellerY is typed as an integer. The rest will be variants

this part of the code;
Me.lblKolom(intTellerX).Location = New System.Drawing.Point(12, 49 + (intPicX * 24))
Seems to position each label with the same coordinates

hope this helps :)
Nov 13 '06 #2
Thanks, but if all the labels have the same position, i should still see the topmost one. I'm working with the 2005 version if this brings any extra info...
Nov 14 '06 #3
LacrosseB0ss
113 100+
if you're trying to position the labels in relation to each other, I think there's an attribute "Top" and "Left" or something referring to where the corners of the label will be.

Then you can use lblName(i-1) to get the last label and use it that way. I could be thinking of a different version however. If I am, my apologies.
Nov 14 '06 #4
willakawill
1,646 1GB
Thanks, but if all the labels have the same position, i should still see the topmost one. I'm working with the 2005 version if this brings any extra info...
OK. You may not see them yet and the logic of the code still positions them all in the same place.

In VB6 you would set the Caption property of a label and not the Text property. This might be the 'invisible man' problem.
Nov 14 '06 #5
But i set the backgroundcolor to Something blueish, that should show up pretty clear?

I've also tried writing a procedure to create a label but the same thing happens. The programme goes through the entire code but nothings shows up.

Dim intPicX, intPicY, intPixelWaarde, intTellerX, intTellerY As Integer
only the last one, intTellerY is typed as an integer. The rest will be variants
When i hover the mouse over each identical variable one of those yellow boxes shows up with ..... as integer.
Nov 15 '06 #6
willakawill
1,646 1GB
But i set the backgroundcolor to Something blueish, that should show up pretty clear?

I've also tried writing a procedure to create a label but the same thing happens. The programme goes through the entire code but nothings shows up.



When i hover the mouse over each identical variable one of those yellow boxes shows up with ..... as integer.
Yes you are right about the declarations because you are using .NET
You can't get away with that in VB6
This is going to be a source of confusion for as long as you are asking a .NET question in this forum.
Nov 15 '06 #7
Yes you are right about the declarations because you are using .NET
You can't get away with that in VB6
This is going to be a source of confusion for as long as you are asking a .NET question in this forum.
Well i just learned something new. .NET <> regular VB

So i have to be in the VB .NET forum. Oops, sry :-/
Nov 15 '06 #8
Killer42
8,435 Expert 8TB
Well i just learned something new. .NET <> regular VB

So i have to be in the VB .NET forum. Oops, sry :-/
The VB forum covers both. You just need to let people know which you are talking about. Those who post most frequently here are VB6 developers, but we see posts about both versions. There are differences in syntax, but the logic will often be the same.

There is a .NET forum, but I don't know what happens over there. When in doubt, you could try posting to both.
Nov 15 '06 #9
AricC
1,892 Expert 1GB
Pardon the heinousness of this but I am not at a PC with VS. You are trying to create a bunch of labels dynamically why don't you use the syntax Dim lblMyNewLabel As New Label(), make an array of those then use the label attributes to position them. Also, I believe in .Net to show your label/controls you need something like Me.Controls.Add(lblMyNewLabel)

Also, as a matter of good habit I like to declare all variables on a new line just a thought.
Nov 21 '06 #10
willakawill
1,646 1GB
The VB forum covers both. You just need to let people know which you are talking about. Those who post most frequently here are VB6 developers, but we see posts about both versions. There are differences in syntax, but the logic will often be the same.

There is a .NET forum, but I don't know what happens over there. When in doubt, you could try posting to both.
In fact this is one area that is completely different in .NET
The ability to create a control array has disappeared. To find out how to get around this problem (which seems to be one of the most irritating in the switch to working with .NET) try reading this...
Nov 21 '06 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tom Rathbun | last post by:
This is probably simple but it has stumped me. I want to create objects at runtime for example: A program that would allow you to draw lines on a form. For each new line I would like to create a...
1
by: Al Murphy | last post by:
Hi, I hope that you can help me wit this one please and apologies if i'm in the wrong forum! I recently bought a book that contaiend a CD-ROM of very useful Visual Basic algoritms. Now these...
83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
18
by: Tinus | last post by:
Hello, I want to do the following: I have 10 labels on my form, called Label0 to Label9. Now I want to change the Text property of all the labels at once, e.g.: for (int i = 0; i < 10; i++)...
3
by: Andreas Klemt | last post by:
Hello, for what is the LABEL good when programming in visual studio like this: Sub xxxx Label1: xxxx xxxx xxx
10
by: Shapper | last post by:
Hello, I am working on an ASP.NET / VB web site and I need to have 2 versions: In English and French. I could create two versions of the web site by duplicating all the pages. Is that the...
9
by: Shapper | last post by:
Hello, I am declaring a variable in my aspx.vb code as follows: Public Class catalogue Public productid As String Private Sub Page_Load ... I have an image button where I call the...
5
by: Mel | last post by:
I created a header that adjusts with the size of the browser windows. How do I place labels in the header section so they also maintain their position when the window is resized? One of the labels...
4
by: Macneed | last post by:
i am a newbie, i remember i read a book talking about when u declare a array variable using float ABC = new float; the whole array element in ABC ( ABC to ABC ) will automatic initialize to 0...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.