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?. - Imports System.Math
-
-
Public Class frmMatrix
-
Dim lblKolom() As System.Windows.Forms.Label
-
-
Private Sub btnBereken_Click(....
-
Dim intPicX, intPicY, intPixelWaarde, intTellerX, intTellerY As Integer
-
Dim intMatrix(,) As Integer
-
Dim strKolom As String = ""
-
Dim strPixel As String
-
-
-
intPicX = Rnd() * 5 + 4
-
intPicY = Rnd() * 5 + 4
-
ReDim intMatrix(intPicX - 1, intPicY - 1)
-
ReDim lblKolom(intPicX - 1)
-
-
For intTellerX = 0 To intPicX - 1
-
Me.lblKolom(intTellerX) = New System.Windows.Forms.Label
-
Me.lblKolom(intTellerX).Location = New System.Drawing.Point(12, 49 + (intPicX * 24))
-
Me.lblKolom(intTellerX).Name = "Kolom" + Str(intTellerX)
-
Me.lblKolom(intTellerX).TabIndex = intTellerX + 2
-
Me.lblKolom(intTellerX).AutoSize = True
-
Me.lblKolom(intTellerX).Visible = True
-
Me.lblKolom(intTellerX).TextAlign = ContentAlignment.MiddleCenter
-
Me.lblKolom(intTellerX).BackColor = Color.CadetBlue
-
Me.lblKolom(intTellerX).Show()
-
-
Next intTellerX
-
-
For intTellerX = 0 To intPicX - 1
-
For intTellerY = 0 To intPicY - 1
-
...
-
Next intTellerY
-
lblKolom(intTellerX).Text = strKolom
-
...
-
Next intTellerX
-
End Sub
-
-
Private Sub Form1_Load(...
-
Randomize()
-
End Sub
-
-
End Class
Thanks i.a.
10 3958
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?. - Imports System.Math
-
-
Public Class frmMatrix
-
Dim lblKolom() As System.Windows.Forms.Label
-
-
Private Sub btnBereken_Click(....
-
Dim intPicX, intPicY, intPixelWaarde, intTellerX, intTellerY As Integer
-
Dim intMatrix(,) As Integer
-
Dim strKolom As String = ""
-
Dim strPixel As String
-
-
-
intPicX = Rnd() * 5 + 4
-
intPicY = Rnd() * 5 + 4
-
ReDim intMatrix(intPicX - 1, intPicY - 1)
-
ReDim lblKolom(intPicX - 1)
-
-
For intTellerX = 0 To intPicX - 1
-
Me.lblKolom(intTellerX) = New System.Windows.Forms.Label
-
Me.lblKolom(intTellerX).Location = New System.Drawing.Point(12, 49 + (intPicX * 24))
-
Me.lblKolom(intTellerX).Name = "Kolom" + Str(intTellerX)
-
Me.lblKolom(intTellerX).TabIndex = intTellerX + 2
-
Me.lblKolom(intTellerX).AutoSize = True
-
Me.lblKolom(intTellerX).Visible = True
-
Me.lblKolom(intTellerX).TextAlign = ContentAlignment.MiddleCenter
-
Me.lblKolom(intTellerX).BackColor = Color.CadetBlue
-
Me.lblKolom(intTellerX).Show()
-
-
Next intTellerX
-
-
For intTellerX = 0 To intPicX - 1
-
For intTellerY = 0 To intPicY - 1
-
...
-
Next intTellerY
-
lblKolom(intTellerX).Text = strKolom
-
...
-
Next intTellerX
-
End Sub
-
-
Private Sub Form1_Load(...
-
Randomize()
-
End Sub
-
-
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 :)
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...
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.
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.
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.
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.
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 :-/
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.
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.
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... Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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++)...
|
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
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |