|
I have approximately 50 labels on an asp.net page written in VB.NET 2003. I use these labels to indicate when an error has occurred by changing the color to system.drawing.color.red when the user tries to submit the page.
Before I perform this validation (there are good reasons why I don't use the native validation controls) I want to make the label invisible so that they don't appear unless an error has been detected.
I tried the following (which obviously didn't work)!
dim LabelCollection as new Collection
dim x as label
for each x in LabelCollection
if x.forecolor.equals(system.drawing.color.red) then
x.visible=false
end if
next
When I debug this code it reaches the "for each" statement but skips over the rest of the code block, i.e. it doesn't appear to find any labels in the collection.
Can anyone help with this process of iterating through a collection of controls?
What have I missed?
|
|
|
|
|
Peter Stanford wrote: dim LabelCollection as new Collection
dim x as label
I'm confused. By what piece of magic did you expect this collection to contain anything ?
The form has a Controls collection. But because a web page is heirarchical, all the controls in it also have a controls collection. You need to iterate over it recursively to find all the labels.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks, I understand recursion, what I can't find is an example of the syntax to use for this particular situation. None of the online help or forums like this one provide anything other than the answer you've just given, i.e. "just do this".
With respect, if I knew how to "just do this" I wouldn't have asked the question!
|
|
|
|
|
Well, like I said - the form has a Controls collection, and so does each control
private void SetLabels(ControlCollection ctrls)
foreach(Control c in ctrls)
{
if (c is Label)
{
// Whatever
}
SetLabels(c.Controls);
}
(somewhere else)
SetLabels(this.Controls)
Sorry, I don't 'do' VB.NET, I give answers here because I know the framework, from using C#. Hopefully, you can convert this.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks Christian,
That's all I was looking for! I can work it out from here.
Best regards
|
|
|
|
|
Thanks Christian,
That's all I was looking for. I can work it out from here!
Best regards
|
|
|
|
|
I'm using VB.net with Framework.
How to monitor the mic level of the default soundcard? I would like to be able to set a treshold value (0-100%) and when the mic level is greater than that a message box would appear. It would be important that the detection would be fast (with as short delay as possible) and consume CPU resources as little as possible.
I found some code in VB6 and C but could not translate them in VB.net.
Thank you!
|
|
|
|
|
Is there a way n VB.net to count a certain number of XML nodes. Say for instance that I had an XML document that held a particular number of nodes named <employee>. Is there a function I can call to tell the exact number of nodes named <employee>?
|
|
|
|
|
If the XML is in an XmlDocument, or any other DOM implimentation, SelectNodes("//Nodename") will return a collection of all nodes with that name, // in XPath means to look everywhere. The collection has a Count or Length property.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi, this is chandu,
I am developing an application which includes Datareports in VB with Access. I am getting the report on user input for the first time. But when i am trying to get another record it is giving the error message like
Msgbox "Operation can't process as the object is already open"
please soleve this problem.
Please give the code.
Thank you
|
|
|
|
|
Help! I am using something I don't understand and need some direction.
I am trying to use "WININET.DLL" to ftp a file. I know the function FtpPutFile returns false but I don't know why. How can I find out why? Below is a code snippet of what I am doing.
All help is greatly appreciated!
Public Function bolFtpUpload(ByVal...............<br />
bolFtpAction = FtpPutFile(intNetConn, _<br />
strLocalFile, _<br />
strRemoteDirectory, _<br />
intTransferTypeFlag, _<br />
intContext)<br />
If bolFtpAction = False Then<br />
"Transfer failed " <br />
Else<br />
"Transfer Succeeded "<br />
End If<br />
End Function<br />
<br />
Private Declare Function FtpPutFile Lib "WININET.DLL" _<br />
Alias "FtpPutFileA" (ByVal intFtpSession As Integer, _<br />
ByVal strLocalFile As String, _<br />
ByVal strRemoteFile As String, _<br />
ByVal intFlags As Integer, _<br />
ByVal intContext As Integer) As Boolean
|
|
|
|
|
|
Hello everyone.
At work we are using PDF file to store some expenses. It's a form that sales people use and then submit it. After someone actualy rekeys it in Excel (don't ask me why).
I would like to animate process with VB.NET solution (if someone knows solution in C# I can look into translating it to VB.NET as long as it works), meaning that PDF files will be read (all form entries) and transfered to the database (no Excel).
What I need is the following:
1. Can I read PDF file and parse the form?
2. What I can use (object)?
If someone has an example I would really appreciate it.
Thank you in advance.
-- modified at 16:27 Friday 6th October, 2006
|
|
|
|
|
There are toolkits you can buy, and some free stuff at SourceForge for PDF.
If you can control how the PDF is written, PDF is compressed, but doesn't have to be. If you had an uncompressed PDF, they do tend to insert word breaks in odd places, but it would be parsable.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thank you. I've used iTextSharp (SourceForge) before to create PDF files but I thought it cannot read PDF. When you say control how PDF is written you mean I know what the fields are, etc.?
Thank you.
|
|
|
|
|
Hi Guys
I was wondering if anyone knew an approach to retrieve a rectangle that would contain the points of a polygon? I had a crack at it as below:
<br />
Dim size As New SizeF(400.0F, 500.0F)<br />
Dim points(5) As PointF<br />
<br />
points(0) = New PointF(20.0F, 20.0F)<br />
points(2) = New PointF(92.0F, 25.0F)<br />
points(3) = New PointF(115.0F, 60.0F)<br />
points(4) = New PointF(127.0F, 90.0F)<br />
points(5) = New PointF(130.0F, 167.0F)<br />
<br />
Using image As New Bitmap(CInt(size.Width), CInt(size.Height))<br />
Using graphics As Graphics = graphics.FromImage(image)<br />
Dim path As New GraphicsPath<br />
Dim region As New Region<br />
<br />
path.AddPolygon(points)<br />
region.Union(path)<br />
<br />
Return region.GetBounds(graphics)<br />
End Using<br />
End Using<br />
However this returned a bizzar rectangle {X=-4194304,Y=-4194304,Width=8388608,Height=8388608} regardless of the coordinates.
Any help, greatly appreciated!
Thanks
Tom
|
|
|
|
|
You can do this several different ways. In all cases, you keep track of the lowest and highest values for the points involved. You can either use a custom Structure to do this and not keep track of the points themselves, only the result, or you can hold the points in a custom implementation of an Array, ArrayList, or List class so you can add and remove points and update the tracked values as the changes are made.
But, basically, the first call to this class/structure would set the upper and lower bounds of the bounding rectangle.
_lowX = newPoint.X : _highX = newPoint.X
_lowY = newPoint.Y : _highY = newPoint.Y
After that, subsequent calls would simply do something like this:
_lowX = Math.Min(_lowX, newPoint.X)
_lowY = Math.Min(_lowY, newPoint.Y)
_highX = Math.Max(_highX, newPoint.X)
_highY = Math.Max(_highY, newPoint.Y)
I knew I had something like this around here. I'll modify it for what you're looking for and post a quick article on it later tonight.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Here, try this. It's based off something I used for a custom graphing component. A couple modifications and it was all set to go:
Imports System.Collections.Generic
...
Public Class BoundingRectangle
Inherits List(Of Point)
Private _lowX As Single
Private _lowY As Single
Private _highX As Single
Private _highY As Single
Public Shadows Sub Clear()
_lowX = 0 : _lowY = 0 : _highX = 0 : _highY = 0
MyBase.Clear()
End Sub
Public ReadOnly Property Rectangle() As Rectangle
Get
UpdateBounds()
Return New Rectangle(_lowX, _lowY, _highX - _lowX, _highY - _lowY)
End Get
End Property
Public Sub New()
MyBase.New()
Me.Clear()
End Sub
Public Shadows Sub Add(ByVal p As Point)
MyBase.Add(p)
End Sub
Private Sub UpdateBounds()
' If we have no points in our list, the bounding rectangle is (0,0)-(0,0)
If MyBase.Count = 0 Then
Me.Clear()
Exit Sub
Else
' If this is the first point we have, it defines the starting bounding rectangle
With MyBase.Item(0)
_lowX = .X : _highX = .X
_lowY = .Y : _highY = .Y
End With
End If
If MyBase.Count > 1 Then
' We have more than one point, find the new bounding rectangle.
For i As Integer = 1 To MyBase.Count - 1
With MyBase.Item(i)
_lowX = Math.Min(_lowX, .X)
_lowY = Math.Min(_lowY, .Y)
_highX = Math.Max(_highX, .X)
_highY = Math.Max(_highY, .Y)
End With
Next
End If
End Sub
End Class
I can't get the article written tonight, so this will have to do for now. It's primarily going to be about creating your own custom typed collections, with added functionality, like tracking and returning a bounding rectangle!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dave
Thanks for the time you put into this, very helpful. I have to say, I considered this loop/test method originally, but assumed there would be an approach somewhere in the framework that would do the task. Glad my fruitless search was not down to my incompetence!
Cheers again.
Tom
P.S. Worked like a charm!
-- modified at 4:46 Monday 9th October, 2006
|
|
|
|
|
Thanks for posting this. I can tell you that I hate it as it's more wordy than VB. At least in VB/C#/C++/Java I can just LOOK at the code an know what is does. In your's, I actually have to READ it, and that takes time.
There is something to be said for concise brevity.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
The Osmosian Order wrote: Perhaps. But why, then, is your entire reply (shown above) written in English?
Oh shut up! Because I'm talking to a human being, not a computer. Unless there's something about yourself you're not telling us?
I didn't say it was a poor vehicle for communication. You did! You said every language we use now to program a computer is a poor choice. The language I use is chosen based on the subject that I'm talking to. I'm not going to speak German to some guy who only understands Portugese.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
That would be nice, provided the machine could actually learn English. As it stands now, machines have very limited learning capabilities. What good is teaching a machine English if it's incapable of understanding the lesson?
English works best as a two way communication with two or parties negotiating a concept until a common understanding is reached. Your compiler can't do this. The machine cannot talk back with any understanding. It can't ask you questions in an attempt to clarify concepts to come to that understanding. It's still a program, debug, rewrite, debug, rewrite, debug, process you've got. Sure, you can make an English language, but until you've taught the machine to learn using that language, you haven't broken any ground. All you've done is create another C# or VB.NET.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
The Osmosian Order wrote: But our machine does, in a real sense, understand English.
No, it doesn't. It SEES English. The common understanding and context is already implied. Your still forcing the programmer to think in a limited box that the compiler predefines for him/her.
The Osmosian Order wrote: Not yet. But it's a first step.
It's a huge leap between what your compiler does now, and actual interaction and understanding.
The Osmosian Order wrote: So ask again if you really care, and I'll explain our idea.
Nope. You've already over-represented what your compiler is now. So, I have no interest in even listening to you, let alone your ideas. That's what happens when you force this stuff down peoples throats. When you completely dodge some points of contention and twist other. When you don't even recognize flaws in your compiler, but instead keep focusing on the same tired "It does this, and this, and this..." You haven't discussed your compiler, but shoved it in our faces and insisted on a recognition of accomplishment. Sorry, but respect, of any kind, is earned, not just given.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I had a question that I was hoping someone could help me figure out. I am using vb.net 2005 express edition. I create a structure definition in a class and I want to pass an array containing this structure array back to the form that called it. How would I do that.
|
|
|
|
|
You would have to declare your structure as public and then pass it like you would any other type. For example, your class would contain code like this:
'Declare the Structure
Public Structure myTestStructure
Dim val1 As Integer
Dim val2 As String
End Structure
'Pass the structure
Public Function myFunction() As myTestStructure
Dim StructureInstance As myTestStructure
StructureInstance.val1 = 3
StructureInstance.val2 = "Hi"
Return StructureInstance
End Function
Hope this helps.
|
|
|
|
|