473,394 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,394 software developers and data experts.

Initially Empty Labels

cindy2
35
Hi,

In my vb2005-project I have a x by x array as type double. To visualise what's in it, I connected each index to a label. When I run the programm, the initial array is empty, so each label contains a zero.

The problem I have is, I don't wanna see all the zero's initially (on runtime). I only want to see the labels if I put a zero (or another number) in the array. Is there an easy way to do this?

Cindy
Oct 11 '07 #1
14 1648
Killer42
8,435 Expert 8TB
(Caveat: I'm a VB6 developer so may be talking garbage...)

Can you explain what you mean by "connecting each index to a label"? Or is this too obvious in VB2005 to explain?
Oct 11 '07 #2
cindy2
35
(Caveat: I'm a VB6 developer so may be talking garbage...)

Can you explain what you mean by "connecting each index to a label"? Or is this too obvious in VB2005 to explain?
Hi,

Yes, it's very obvious in vb2005 :). Let's say I have an array with 4 by 4 elements, which gives a total of 16 elements. Now, on my design-form I put 16 labels. Each of these labels is connected to an index of the array:

Expand|Select|Wrap|Line Numbers
  1. label1.text = Arr(0, 0)    'first colomn
  2. label2.text = Arr(1, 0)
  3. label3.text = Arr(2, 0)
  4. label4.text = Arr(3, 0)
  5. label5.text = Arr(1, 1)   'second column
  6. label6.text = Arr(2, 1)
  7. ....etc.
  8. Label16.text = Arr(3, 3)
I hope this explains what you mean, because on the other hand, I don't know VB6.

Cindy
Oct 11 '07 #3
cugone
20
Depending on the legal range of numbers you want, just put a number outside said range and check for not that number. EX:

Your legal range is zero or above:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'This can also be accomplished by setting each label in the Propeties tab on the
  3. 'Designer page (select them all, set the Text Prop to -1.0).
  4.  
  5. label1.text = "-1.0"
  6. label2.text = "-1.0"
  7. ...
  8. label16.text = "-1.0"
  9.  
  10. .....
  11. dim i as double = 0.0
  12. dim j as double = 0.0
  13.  
  14. for each allControls in me.Controls
  15.      if (typeof allControls is label) then
  16.           if Convert.toDouble(allControls.text) >= 0.0 then
  17.                allControls.text = array(i,j).tostring
  18.           end if
  19.      end if
  20.      i += 1
  21.      j += 1
  22. next
  23.  
  24.  
Oct 11 '07 #4
cindy2
35
Depending on the legal range of numbers you want, just put a number outside said range and check for not that number. EX:

Your legal range is zero or above:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'This can also be accomplished by setting each label in the Propeties tab on the
  3. 'Designer page (select them all, set the Text Prop to -1.0).
  4.  
  5. label1.text = "-1.0"
  6. label2.text = "-1.0"
  7. ...
  8. label16.text = "-1.0"
  9.  
  10. .....
  11. dim i as double = 0.0
  12. dim j as double = 0.0
  13.  
  14. for each allControls in me.Controls
  15.      if (typeof allControls is label) then
  16.           if Convert.toDouble(allControls.text) >= 0.0 then
  17.                allControls.text = array(i,j).tostring
  18.           end if
  19.      end if
  20.      i += 1
  21.      j += 1
  22. next
  23.  
  24.  
Thank you for your reply. I'm sorry, but I don't understand. I know the code you have written is specific, but I'm afraid it's not specific enough for me. I tried some things with your code, but it does not give the results I want.

For example: Is the array of type data or string?

Cindy
Oct 11 '07 #5
Killer42
8,435 Expert 8TB
Yes, it's very obvious in vb2005 :). Let's say I have an array with 4 by 4 elements, which gives a total of 16 elements. Now, on my design-form I put 16 labels. Each of these labels is connected to an index of the array:
Expand|Select|Wrap|Line Numbers
  1. label1.text = Arr(0, 0)    'first colomn
  2. label2.text = Arr(1, 0)
  3. label3.text = Arr(2, 0)
  4. label4.text = Arr(3, 0)
  5. label5.text = Arr(1, 1)   'second column
  6. label6.text = Arr(2, 1)
  7. ....etc.
  8. Label16.text = Arr(3, 3)
So, in other words, there isn't any sort of connection between them. You just copied the values from the array into the labels.

Which means the reason there are zeroes there is that you put them there. Which in turn means that the solution is obvious - don't! :)

For example...
Expand|Select|Wrap|Line Numbers
  1. If Arr(1, 0) Then
  2.   label2.text = Arr(1, 0)
  3. End If
(This is taking advantage of the fact that any non-zero value will evaluate to True in an IF. If you want, you could also say If Arr(1, 0) <> 0 Then.)

Of course, I wouldn't code this IF test 16 times. It'd make for nicer code to do something like creating a function that returns a string containing the number only if it's non-zero. For the sake of argument, let's say you called the function BlankIfZero. Then you could say...
Expand|Select|Wrap|Line Numbers
  1. label1.text = BlankIfZero(Arr(0, 0))    'first colomn
  2. label2.text = BlankIfZero(Arr(1, 0))
  3. label3.text = BlankIfZero(Arr(2, 0))
  4. label4.text = BlankIfZero(Arr(3, 0))
  5. label5.text = BlankIfZero(Arr(1, 1))   'second column
  6. label6.text = BlankIfZero(Arr(2, 1))
Oct 11 '07 #6
cindy2
35
For example...
Expand|Select|Wrap|Line Numbers
  1. If Arr(1, 0) Then
  2.   label2.text = Arr(1, 0)
  3. End If
(This is taking advantage of the fact that any non-zero value will evaluate to True in an IF. If you want, you could also say If Arr(1, 0) <> 0 Then.)

Of course, I wouldn't code this IF test 16 times. It'd make for nicer code to do something like creating a function that returns a string containing the number only if it's non-zero. For the sake of argument, let's say you called the function BlankIfZero. Then you could say...
Expand|Select|Wrap|Line Numbers
  1. label1.text = BlankIfZero(Arr(0, 0))    'first colomn
  2. label2.text = BlankIfZero(Arr(1, 0))
  3. label3.text = BlankIfZero(Arr(2, 0))
  4. label4.text = BlankIfZero(Arr(3, 0))
  5. label5.text = BlankIfZero(Arr(1, 1))   'second column
  6. label6.text = BlankIfZero(Arr(2, 1))
Thanks for your reply,

I only want to "hide' the zero's initially at runtime. So it must still be possible to put a zero in the array and then copy it to the corresponding label. Is that also possible with your approach?

Cindy
Oct 12 '07 #7
Killer42
8,435 Expert 8TB
I only want to "hide' the zero's initially at runtime. So it must still be possible to put a zero in the array and then copy it to the corresponding label. Is that also possible with your approach?
Sure. Since your code is putting the zeroes in there, you can do it or skip it any time you like.

One simple technique would be to create a global Boolean variable. Let's call it ThisIsNotTheFirstTime, just for fun. At the end of the segment of code which sets the labels, you set it to True.

Then, in the BlankIfZero function, you'd do something like...

Expand|Select|Wrap|Line Numbers
  1. Public Function BlankIfZero(ByVal TheNumber As Long) As String
  2.   If (TheNumber <> 0) Or ThisIsNotTheFirstTime Then
  3.     BlankIfZero = TheNumber
  4.   End If
  5. End Function
You just have to use a bit of imagination. :)
Oct 12 '07 #8
cindy2
35
Sure. Since your code is putting the zeroes in there, you can do it or skip it any time you like.

You just have to use a bit of imagination. :)

Thank you, it does work fine, but I still have a problem. The labels are initially empty, but when I want to put a number in the array, that then is copied to a label, I have to go through all the 'code' that copies the array-indexes to the labels. This is because in the first instance I don't know which index must be copied to the corresponding label. So all the zero's will be visible (again). My code looks something like this:
Expand|Select|Wrap|Line Numbers
  1. If Arr1(j) = Arr2(i) Then                           
  2.           Array(i, column) = Arr3(j)      ' "Array" is the array we are talking about
  3. End If
  4.  
And as mentioned, next I have to copy the indexnumbers to the labels:
Expand|Select|Wrap|Line Numbers
  1. label1.text = BlankIfZero(Array(0, 0))    'first colomn
  2. label2.text = BlankIfZero(Array(1, 0))
  3. label3.text = BlankIfZero(Array(2, 0))
  4. label4.text = BlankIfZero(Array(3, 0))
  5. label5.text = BlankIfZero(Array(1, 1))   'second column
  6. label6.text = BlankIfZero(Array(2, 1))
  7. ........etc.
  8. label16.text = BlankIfZero(Array(3, 3))
  9.  
I really tried to use my imagination, but I can't figure it out how to 'hide' the initial zero's when I change the array. Do you have some advice for me?

Cindy
Oct 12 '07 #9
Killer42
8,435 Expert 8TB
Um... I think someone else posted a solution earlier in this thread which might help. That is, pick some value that won't show up in the real data, and initialise all your array entries with that value. For example, set them all to -999.

Then, every time you copy them to the labels, you show whatever value is there, unless it's -999. That way, if a zero does turn up, it will be displayed.

What do you think? I can't say for sure, as I don't know your data.
Oct 12 '07 #10
QVeen72
1,445 Expert 1GB
Hi,

Declare the Array as a Variant.. say :
Dim MyArr(4,4)

Do not write as Double.. (or whatever)
This is Because, when you declare an Array as some type, All the Array items will be Initialized to default Value (0 for numeric, Blank String for Strings, False For Boolean). With Variant, All of the Array Items wud be Empty.. And Non-Initialized items will show as blank in the Label..
And will work for your problem..
Write one Common Procedure To Populate the Labels with array Values.
And whenevr, Array items are Manipulated, call that Procedure.

Regards
Veena
Oct 12 '07 #11
cindy2
35
Hi,

Declare the Array as a Variant.. say :
Dim MyArr(4,4)

Do not write as Double.. (or whatever)
This is Because, when you declare an Array as some type, All the Array items will be Initialized to default Value (0 for numeric, Blank String for Strings, False For Boolean). With Variant, All of the Array Items wud be Empty.. And Non-Initialized items will show as blank in the Label..
And will work for your problem..
Write one Common Procedure To Populate the Labels with array Values.
And whenevr, Array items are Manipulated, call that Procedure.

Regards
Veena
Thank you for your reply,
It does work, all the labels are blank initially. And when I put a number in the array, the corresponding label will visualize it.

Another part of the programm adds all the row ellements of the array. Because of the 'variant' type, the programm tries to add string-elements (the elements of the array that haven't been populated yet), so an error occured. I tried to convert the type of the array to single for that part of programm, but that didn't work. Do you have a suggestion?

Cindy
Oct 12 '07 #12
QVeen72
1,445 Expert 1GB
Hi,

use Val Function
Some thing like this :

TArr(1,2) = Val(TArr(2,3)) + Val(TArr(2,4))

Regards
Veena
Oct 12 '07 #13
cindy2
35
Thank you all!!!
It works great! :)
Oct 13 '07 #14
Killer42
8,435 Expert 8TB
Thank you all!!!
It works great! :)
Excellent!

Good work, team. :)
Oct 14 '07 #15

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

Similar topics

4
by: db2group88 | last post by:
we are using db2 udb v8.2 on windows. all our tables are created with not logged initially property, So if i want to activate HADR (high availability disaster recovery) for the database, in...
6
by: DebbieG | last post by:
I am creating a database for a small department in a university. Each student in their database can have 2 mailing addresses. They wanted mailing labels pulling just the 1st address. No problem....
3
by: Grim Reaper | last post by:
I print mailing labels out of Access 2000 databases about 3 to 4 times a week. I have been having problems with one thing since I have been printing mailing labels. I print mailing labels by...
3
by: grlgeek | last post by:
I have a report for creating the switchboard labels for our phone system receptionist switchboard. The template has 12 records per column. I setup a report that will create the labels and put a...
3
by: Pafo007 | last post by:
Hi. I've built a small window, with some buttons and labels, and one listbox. During design time, I put five lines in the listbox and launch the program: the listbox appears empty! I can select...
2
by: Eric Maia | last post by:
I have a textbox (StartDateTextBox) in a UserControl on my page, that is supposed to have a date entered into it. I have a RequiredFieldValidator that has its ControlToValidate property set to the...
4
by: bughunter | last post by:
I'm sorry but previously command ALTER TABLE tbl ACTIVATE NOT LOGGED INITIALLY on table created without NOT LOGGED INITIALLY option was impossible. Or not? IMHO, more better give error or...
6
by: Ron | last post by:
Hi, I know Access allows for easy construction of a report setup to print labels from a table/query, etc. I've done that one. It works pretty well for what I need. However, is there an...
7
by: Vinodh | last post by:
Started reading about Binary Trees and got the following questions in mind. Please help. Definition of a Binary Tree from "Data Structures using C and C++ by Tanenbaum" goes like this, "A...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.