Q: For Each loops
(Monday, January 30, 2006)
Found the following interesting discussion in the Newsgroups:
Q: For Each loops by:Geoff Jones
| Hi
Suppose I have a For Each loop, for example,
For Each x As DataRow In drMyData ' Do stuff - calculation 1 ' Do more stuff - calculation 2 ' and even more stuff - calculation 3 Next
If after completing calculation 1, I discover that there is no point doing calculations 2 and 3, how do I jump back to the start to starting processing the next DataRow?
I've tried adding a conditional statement something like:
If (no point carrying on) Then Next End if
but I can't get it to compile.
Can anybody please help?
Thanks in advance
Geoff
| | | Reply: by:One Handed Man \( OHM - Terry Burns \)
| | | Simply structure your code differently with conditional branching such as select case and if's, if you cant cope with that then you could put a goto statement in, but I try to avoid this if possible
if then goto continue continue:
Next
--
Terry Burns
| | | Reply: by:Anonymous
| | | why not just do this? For Each x As DataRow In drMyData ' Do stuff - calculation 1
' Do more stuff - calculation 2 ' and even more stuff - calculation 3
| | | Reply: by:Anonymous
| | | not just do this? For Each x As DataRow In drMyData ' Do stuff - calculation 1 if calculation1ok then ' Do more stuff - calculation 2 if calculation2ok then ' and even more stuff - calculation 3 end if end if Next
hth guy
| | | Reply: by:PAul Maskens
| | | Well, it is a FOR loop, how about using LOOP ? If you want to exit and stop processing any more rows, use EXIT
|
Posted by Xander Zelders
How to find a list of SQL Servers?
Found the following interesting discussion in the Newsgroups:
Finding a list of SQL Servers by:Craig G
| without using SQLDMO
is there another way, i've used the SQLDMO way but have had a few issues with it.
is there another way?
Cheers, Craig
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
P/invoke, a VB6 sample that needs to be translated before using it can be found here:
<URL:http://vbnet.mvps.org/index.html?code/network/netserverenumver.htm>
-- Herfried K. Wagner
|
Posted by Xander Zelders
How to find whether an Image is Color or b/w?
Found the following interesting discussion in the Newsgroups:
How to find whether an Image is Color or b/w by:Chellapa
| For my ImageProcessing Application i need to find whether an Image is Color or B/W through code for GrayScale automation purpose, Iam using vb.net and photoshop for developing the application.
Image Format is PNG
Can any one help in this regard.
Thanks, Chellapandian.S
| | | Reply: by:One Handed Man \( OHM - Terry Burns \)
| | | You didnt even answer my last reply to this question !
--
Terry Burns
|
Posted by Xander Zelders
Find Missing Data
Found the following interesting discussion in the Newsgroups:
Find Missing Data by:Justin Emlay
| I'm hopping someone can help me out on a payroll project I need to implement.
To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks).
I have a dataset as follows (1 week to keep it short):
Employee 1 - Date 1 Employee 1 - Date 2 Employee 1 - Date 3 Employee 1 - Date 4 Employee 1 - Date 5 Employee 2 - Date 1 Employee 2 - Date 3 Employee 2 - Date 4 Employee 2 - Date 5
You'll notice Employee 2 - Date 2 is missing. I need to develop a routine that will give me all missed dates per employee.
I'm open to any ideas/theories. I have one of my own but before I get started on it I wanted some opinions on it. I'm not sure how productive such a routine will be. It sounds like a cluster f. to me. Create an array of unique employee numbers
then
Loop through that array and create a second array of unique dates. If the ubound of that second array is < 9 then figure out missed date(s) (I have period start). Dump employee number and date into a third array. Destroy second array. Next Thoughts?
| | | Reply: by:Cor Ligthert
| | | Hi Justin,
I assume every date is a row.
Seeing this than there are two question, you want to know if there are dates missing, that is easy, you set them employee by employee in a dataview, the count should always be 10.
Than you can show which dates are there, it should than for every programmer be very easy to know what is missing.
(I would first make an array with dates which should be and test when there is a missing one. The array because you have to deal with weekends which can make it complex when you do it in a direct routine calculating everytime the dates)
I assume that you do not have to test on doubles, which is of course with that dataview as well a piece of cake.
Or do I see this the simple?
Cor
|
Posted by Xander Zelders
Design Tutorials
Found the following interesting discussion in the Newsgroups:
Design Tutorials by:Anonymous
| I need a couple free tutorials on application design, I am trying to build a project but i really lack in the design category and its is affecting my production.
thanks for the help
WStoryeII
| | | Reply: by:Ken Tucker [MVP]
| | | Hi,
http://www.microsoft.com/resources/practices/default.mspx
Ken
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
<URL:http://www.martinfowler.com/books.html#eaa>
-- Herfried K. Wagner
|
Posted by Xander Zelders
Dateformat on databound textboxes?
Found the following interesting discussion in the Newsgroups:
Dateformat on databound textboxes? by:Graham Blandford
| Hi all,
Can anyone tell me how I go about setting a custom date format (or any other format for that matter) to a textbox that has a databinding?
In VB6 I would do something like 'set text1.format = myformat', but that isn;t a format property in VB.NET.
Any help would be gratefully received.
Thanks, Graham
| | | Reply: by:William Ryan eMVP
| | | You can use Format directly on a value, but if I understand your question correctly, you'll want to add a handler for the .Format and .Parse events. This explains it pretty well but let me know if you have any problems. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclassbindingcontexttopic.asp
-- W.G. Ryan
|
Posted by Xander Zelders
Moveable Toolbars
Found the following interesting discussion in the Newsgroups:
Moveable Toolbars by:VJ
| I am looking to implement moveable toolbars like in Word, or Visual Studio... any pointers or articles would great..
Thanks VJ
| | | Reply: by:Cor Ligthert
| | | Hi VJ,
I made this sample for John Crouse, however the only thing in my opinion what you have to change basicly are toolbars instead of labels.
(You can open a windowform application, delete all the code, past this bellow in and try)
I hope this helps.
Cor
\\Public Class Form1 Inherits System.Windows.Forms.Form Public Sub New() MyBase.New() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private components As System.ComponentModel.IContainer Private WithEvents Label1 As New System.Windows.Forms.Label Private WithEvents Label2 As New System.Windows.Forms.Label Private mouseX, mouseY As Integer Private arLabels() As Label Dim myMousedown As String Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Me.ClientSize = New System.Drawing.Size(400, 400) Label1.Name = "Label1" Label2.Name = "Label2" arLabels = New Label() {Label1, Label2} Dim lblY As Integer = 100 For Each Lbl As Label In arLabels Lbl.Location = New System.Drawing.Point(100, lblY) Lbl.ForeColor = Color.Red Lbl.BackColor = Color.Transparent Lbl.TextAlign = ContentAlignment.MiddleCenter Lbl.Text = Lbl.Location.X.ToString & "." & Lbl.Location.Y.ToString AddHandler Lbl.MouseDown, AddressOf Label_MouseDown AddHandler Lbl.MouseUp, AddressOf Label_MouseUp AddHandler Lbl.MouseMove, AddressOf Label_MouseMove lblY += 30 Me.Controls.Add(Lbl) Next End Sub Private Sub Label_MouseDown(ByVal sender As Object, ByVal _ e As System.Windows.Forms.MouseEventArgs) Dim lbl As Label = DirectCast(sender, Label) myMousedown = lbl.Name lbl.BringToFront() mouseX = Cursor.Position.X - lbl.Location.X mouseY = Cursor.Position.Y - lbl.Location.Y lbl.Cursor = Cursors.Hand End Sub Private Sub Label_MouseUp(ByVal sender As Object, ByVal e As _ System.Windows.Forms.MouseEventArgs) Dim lbl As Label = DirectCast(sender, Label) myMousedown = "" lbl.Cursor = Cursors.Default End Sub Private Sub Label_MouseMove(ByVal sender As Object, ByVal e _ As System.Windows.Forms.MouseEventArgs) Dim lbl As Label = DirectCast(sender, Label) Static LastCursor As Point Dim NowCursor As Point = New Point(Cursor.Position.X, Cursor.Position.Y) If Point.op_Inequality(NowCursor, LastCursor) Then If myMousedown = lbl.Name Then lbl.Location = New System.Drawing.Point(Cursor.Position.X _ - mouseX, Cursor.Position.Y - mouseY) End If LastCursor = Cursor.Position lbl.Text = lbl.Location.X.ToString & "." & lbl.Location.Y.ToString End If End Sub End Class ///
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
Do you want to implement that on your own or are you looking for (commercial) components?
-- Herfried K. Wagner
| | | Reply: by:Tom Spink
| | | Hi, Check out this website:
http://www.divil.co.uk
I use his components and they are amazing! So long as the application you are writing is freeware, the license is free.
-- HTH, -- Tom Spink
|
Posted by Xander Zelders
Help with hiding LinkButton in DataList
Found the following interesting discussion in the Newsgroups:
Help with hiding LinkButton in DataList by:News
| Hi,
I need help with datalist and linkbutton. I need a LinkButton to be visible in datalist only on the condition when datafield "is_measure_customchecklist" in a db table set to true.
Here is the code (in parts):
<asp:DataList id="dtl1" runat="server" DataKeyField="program_id" OnItemCommand="DoItemSelect" OnItemCreated="Item_Created" OnItemDataBound="BindProgramGrid" > <ItemTemplate> <%# Container.DataItem("name") %> <asp:LinkButton Visible="false" ID="managechecklist" CommandName="managechecklist" Text="Manage Checklist" CommandArgument='<%#DataBinder.Eval(Container.DataItem, Runat="server" /> </ItemTemplate>
<SelectedItemTemplate> <b><%# Container.DataItem("name") %></b> <asp:LinkButton CommandName="Editprogram" Text="Edit Program" runat="server" /> <asp:LinkButton ID="managechecklist" CommandName="managechecklist" Text="Manage Checklist" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "is_measure_customchecklist") %>' Runat="server" /> ..... </SelectedItemTemplate> 1. I tried with this method (below) but can not get value of the CommandArgument of the LinkButton (understand that commandargument is not part of DataListItemEventArgs):
Sub Item_Created(sender As Object, e As DataListItemEventArgs) If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then ' Retrieve the Label control in the current DataListItem. Dim lbtnManageCheckist As LinkButton = CType(e.Item.FindControl("managechecklist"), LinkButton)
lbtnManageCheckist.visible = False If lbtnManageCheckist.CommandArgument.toString() Then lbtnManageCheckist.visible = True End If
End If End Sub 2. I tried another way, here I can get the value of CommandArgument value but setting of the link button (lbtnManageCheckist.visible = True) to visible is not working:
Sub DoItemSelect(sender As Object, e As DataListCommandEventArgs) If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then ' Retrieve the Label control in the current DataListItem. Dim lbtnManageCheckist As LinkButton = CType(e.Item.FindControl("managechecklist"), LinkButton)
lbtnManageCheckist.visible = False If lbtnManageCheckist.CommandArgument.toString() Then lbtnManageCheckist.visible = True End If
End If End Sub
Can anyone advise what is the better way to get this thing working. I need link button to appear in DataList on condition "is_measure_customchecklist" is true Thank you...
| | | Reply: by:Cor Ligthert
| | | Hi News,
Why do you not set that visible and not visible in the server side load event?
Cor
|
Posted by Xander Zelders
Project converted from VB6 to VB.Net gets subclassed WndProc -- why?
Found the following interesting discussion in the Newsgroups:
Project converted from VB6 to VB.Net gets subclassed WndProc -- why? by:Rob Richardson
| Greetings!
I have a VB.Net 2003 project that was originally written in VB6, converted to VB.Net 2002, and then converted to VB.Net 2003. I am trying to handle a form's Resize event. I put a breakpoint in it and saw that that event got fired four times before the form's Load event got fired! I then saw that I have the following routine in the form's code:
Private Const WM_SHOWWINDOW = &H18 Private m_loaded As Boolean Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = WM_SHOWWINDOW Then If Not m_loaded Then MyBase.OnLoad(New System.EventArgs()) End If End If MyBase.WndProc(m) End Sub
And my form's Load event sets the m_loaded flag to true.
I never put that routine in. I presume it was added at some point in one of those conversions. Why is it here?
Thanks!
Rob
| | | Reply: by:Tom Spink
| | | It's because of the legacy way VB6 handled forms... VB6 was not Object-Oriented, not even Object-Based.... At a push, I'd call it Object-Aware....
Stepping off the Soap Box, The code is designed to emulate the functionality of the 'Load' keyword in '6:
<VB6> Form1.Show() </VB6>
This will load the form, if not already loaded then show it. So, provided the Form hasn't been 'Load'ed yet, showing the window will cause the 'Load' event to occur. Whether you keep it or not is a personal decision... do you need the functionality that comes with this?
-- HTH, -- Tom Spink
|
Posted by Xander Zelders
.Net says I'm not Online, but I am!
Found the following interesting discussion in the Newsgroups:
.Net says I'm not Online, but I am! by:Selden McCabe
| While at a client's site today, I suggested looking at one of the .Net newsgroups. When I pulled up the .Net start page, and clicked "Online Resources" it reported that we were not connected to the Internet.
But we were!
Does anyone have any idea why this was happening, and what to do about it?
Thanks, ---Selden McCabe
| | | Reply: by:Richard Myers
| | | Perhaps their browser IE was working offline?
Richard
|
Posted by Xander Zelders
Freeware/shareware Windows controls
Found the following interesting discussion in the Newsgroups:
Freeware/shareware Windows controls by:Richard L Rosenheim
| I'm experimenting with .Net programming and is wondering what free (or low-cost) UI controls are available for non-commercial use.
As I'm just playing around with code and concepts at the moment, I'm not really ready to go out and start purchasing commercial libraries at hundreds of dollars each. For one thing, I'm not sure what I'm really looking for in a library yet. My primary interest at the moment is playing around with simulating some of the look and feel of Office 2003 (such as the panels on the right side of Word, etc.).
I have looked at various contributions to GotDotNet and I am aware of the Magic UI Library, which provides docking panels like Visual Studio uses. I'm wondering if anyone knows of, or care to, recommend any other such libraries.
TIA,
Richard Rosenheim
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
Have a look at <URL:http://www.codeproject.com/>, <URL:http://www.gotdotnet.com/>, <URL:http://www.vbAccelerator.com/> and the Visual Basic .NET Resource Kit (<URL:http://msdn.microsoft.com/vbasic/vbrkit/>).
-- Herfried K. Wagner
| | | Reply: by:Richard L Rosenheim
| | | Thanks. Looked a little at codeproject.com, seems to be a lot of useful stuff there.
Richard Rosenheim
| | | Reply: by:Oleg Zherebin
| | |
Try http://www.divil.co.uk/net/
|
Posted by Xander Zelders
Combobox in datagrid?
Found the following interesting discussion in the Newsgroups:
Combobox in datagrid? by:John Doe
| Now i know how to manually add a combobox to a datagrid, but how would i handle the recordset below?
ID | FirstName | LastName | Job -------------------------------- 1 |Joe | Smith | janitor 1 |Joe | Smith | cashier 2 |Bob | Anderson | cook
I want to bind the above datatable to a datagrid so that Job field will be a combobox of the appropriate list of jobs. So for Joe Smith, it will have janitor and cashier, for Bob, it will only have cook. So the datagrid would only display the two row (one for each person). Is there a way to do this without having to look through the rows and manually adding to the combobox? Some kind of group by functionality?
| | | Reply: by:Cor Ligthert
| | | Hi John,
I assume you mean a dataset and not a recordset. There is no standard combobox for the datagrid, they all are inheritted ones, so the answer is difficult to give with code.
However the answer is most probably Yes most comboboxes for datagrid work the same as a normal combobox so you can add in your code the items you want.
And when you want it from a datatable than you have to make that datatable. When you want the selectedvalue, than you need a columntype datagridcombobox.
I hope this helps,
Cor
|
Posted by Xander Zelders
To parenthesize or not... Bug in VB.Net?
Found the following interesting discussion in the Newsgroups:
To parenthesize or not... Bug in VB.Net? by:Anonymous
| Call me a purist or picky but...
I've found 2 instances where VB.Net considers parenthesis optional. Consider the following property, sub, and function in VB.Net:
Public Property TestProperty() As Integer Get Return 0 End Get Set(ByVal Value As Integer) End Set End Property
Private Sub TestSub() ' Do nothing End Sub
Private Function TestFunction() As Integer Return 0 End Function
VB.Net allows the following syntax in calling the previous routines:
1. If Me.TestProperty = 0 Then... 'Looks ok 2. If Me.TestProperty() = 0 Then... 'Huh? 3. If Me.TestFunction() = 0 Then... 'Looks ok 4. If Me.TestFunction = 0 Then... 'Huh? 5. Me.TestSub() 'Looks ok
The interesting thing is if you remove the "Me." in call #4, the IDE forces both parenthesis in the syntax. This leads me to believe #4 is a bug. This call SHOULD look like #3 because VB.Net now requires parenthesis on all sub/function calls with parameters. Why should the syntax be any different with a function call without parameters?
The syntax in call #1 is consistent with the use of properties. However call #2 looks like a function call, not a property query. You could make a strong argument that this syntax is ok for two reasons. First, properties can contain processing code just like a sub or function. Second, VB.Net properties can take parameters just as a sub or function so they should include the parenthesis. My argument is either force one syntax or the other, but not both and not neither. I'd prefer to see #1 instead of #2 simply to tell that it a property that is being accessed as opposed to a function.
To summarize, I believe call #4 is a bug which I'd like to see fixed. I believe there is a bug allowing the syntax of both calls #1 and #2. I'd like to see one or the other fixed.
Are either of these considered bugs? Has anyone else seen this? I couldn't find any posts relating to this anomaly.
| | | Reply: by:David Browne
| | | Consider the following property, sub, and function in VB.Net:
Well you're certianly not a VB purist. Empty parameter lists are optional in VB, they always have been.
There is no ambiguity in VB like there would be in C or C# since the function name without the parameter list is not used as a function pointer. VB has the addressOf operator for that.
But you wouldn't be the first person to hold the opinion that VB is a bit sloppy looking.
David
| | | Reply: by:Cor Ligthert
| | | Hi David,
A lot of other people have the opinion that C type languages are often very discipline acting as a puritan schoolteacher, who is not telling why however only that you should.
:-)
Cor
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
The '()' for calling parameterless methods or accessing parameterless properties are always optional. What you are experiencing may be caused by the IDE's pretty listing/reformatting feature. Did you try to compile the code using "VBC.EXE" with and without the parenthesis?
-- Herfried K. Wagner;
|
Posted by Xander Zelders
How to change the Color of a Toolbar?
Found the following interesting discussion in the Newsgroups:
Changing the Color of a Toolbar by:Charles A. Lackman
| Hello,
I am using the Toolbar from inside VS.NET and am looking for a way to change it's background color. When I look it up on Microsoft's Web Site I see that it is overridden ,but, I am very unsure how to accomplish this. Any suggestions will be greatly appreciaed.
Thanks,
Chuck
P.S. I am using VB.NET. Thanks
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
Set the control's 'Appearance' property to 'Flat' and change the backcolor of the container the toolbar is placed in.
-- Herfried K. Wagner
| | | Reply: by:Charles A. Lackman
| | | Thank You,
Is there a way of doing this without makeing the Appearance Flat?
|
Posted by Xander Zelders
How to pass Objects as type System.Object?
Found the following interesting discussion in the Newsgroups:
Passing Objects as type System.Object by:Stephen Travis
| I'm trying to ReDim a child object after passing the parent object as System.Object and it throws a System.InvalidCastException: Cast from type 'Object()' to type 'ChildType()' is not valid. If I pass the parent object as its type, the ReDim succeeds. How can I ReDim a child object from a parent object passed as System.Object?
Here's the problem...
Private Sub Page_Load Dim NewParent As New ParentType addTwoChildrenSucceeds(NewParent) addTwoChildrenFails(NewParent) End Sub
Public Sub addTwoChildrenFails(ByVal parentobject As System.Object) ReDim parentobject.Child(1) ' Throws the exception. parentobject.Child(0) = New ChildType parentobject.Child(0).ChildName = "Brian" parentobject.Child(1) = New ChildType parentobject.Child(1).ChildName = "Gail" End Sub
Public Sub addTwoChildrenSucceeds(ByVal parentobject As ParentType) ReDim parentobject.Child(1) parentobject.Child(0) = New ChildType parentobject.Child(0).ChildName = "Brian" parentobject.Child(1) = New ChildType parentobject.Child(1).ChildName = "Gail" End Sub
Public Class ParentType Public ParentName As System.String Public Child() As ChildType End Class
Public Class ChildType Public ChildName As System.String End Class
| | | Reply: by:The Grim Reaper
| | | You're nearly there...
Public Sub addTwoChildrenFails(ByVal parentobject As System.Object) parentobject = DirectCast(parentobject, ParentType) ReDim parentobject.Child(1) ' Doesn't throw an exception any more parentobject.Child(0) = New ChildType parentobject.Child(0).ChildName = "Brian" parentobject.Child(1) = New ChildType parentobject.Child(1).ChildName = "Gail" End Sub
Untested... I'm sure someone else will contradict me.... tis the way of it :D _____________________________ The Grim Reaper
| | | Reply: by:Tom Spink
| | | Hi, May I ask why you pass it as an object... will you have different classes being ReDim'med?
-- HTH, -- Tom Spink
Posted by Xander Zelders

How to create a Username/Login Page?
Found the following interesting discussion in the Newsgroups:
Creating a Username/Login Page by:Erik T. Nomad
| Hey...I'd like to link a login page (e-mail address, password) to an access database on the server whereby users can save items in a "wish list" and retrieve them later -- even e-mail the wish list to others. This threatens to be a pretty big project, but can anyone point me in the right direction? Thanks.
Erik
| | | Reply: by:Lucas Tam
| | | This is quite simple with .NET. Take a look at forms authentication.
http://www.15seconds.com/issue/020220.htm -- Lucas Tam
| | | Reply: by:Erik T. Nomad
| | |
Excellent. Thanks!
Erik
|
Posted by Xander Zelders
Suggestions to increase the performance of searching my array?
Found the following interesting discussion in the Newsgroups:
Suggestions to increase the performance of searching my array? by:Anonymous
| I wonder if anyone has suggestions for reducing the amount of time it would take to search my array using the function that I have written. I want to find a position in the array of an item that matches on all three variables. Suggestions?
Public Shared Function GetArrayPosition(ByVal ipRemoteEndPoint As String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer) For i As Integer = 0 To aryDevice.GetUpperBound(1) If aryDevice(0, i) = ipRemoteEndPoint.ToString And aryDevice(1, i) = intEngine_Type And aryDevice(2, i) = intEngine_ID Then Return i End If Next Return -1 End Function
| | | Reply: by:Anonymous
| | | How can you create an array include different datatype (String, Integer). I suggest you use datatable.
| | | Reply: by:Anonymous
| | | I was thinking about that after I posted and can change the format of the items so that they are all integers. Would this improve my situation or do you still recommend using a datatable?
Dan
| | | Reply: by:Cablewizard
| | | Dan,
First, you don't want to mix types in an array. I noticed you have String and Integer types. If all 3 dimensions of your array reference a single item, then I might use an array of a Structure with a fixed length string.
Second, do not perform multiple tests in a single line using the "And" operator. VB must resolve all the expressions prior to evaluating your comparison test. In cases where the first test fails, it will still perform the other two tests along with all the unnecessary overhead. VB.Net does include the "AndAlso" and "OrElse" operators which will provide a Meaning the first test to fail will cause the whole expression to fail, and return False without evaluating the subsequent expressions. IMHO, I prefer to break them into separate tests for readability. In addition, it also allows you to perform other operations between tests, as in the case of indexing.
Third, along with the second, perform your tests in the order which will most likely give you a False first. This will allow you to minimize the number of unnecessary comparisons. Sometimes that fastest way to get to your desired item is to eliminate as many of the items as quickly as possible that cannot fulfill your criteria.
Fourth, if you have a large number of elements in the array and you will be accessing them a lot, then I recommend pre-sorting the array on an appropriate key. You could also create Index arrays with pointers into the primary array and use this to minimize the number of elements to test. The best implementation of an Index, if even appropriate, would be dependant upon the contents of the array and intended usage.
Hope this helps, Gerald take to search my array using the function that I have written. I want to find a position in the array of an item that matches on all three variables. Suggestions? ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer) = intEngine_Type And aryDevice(2, i) = intEngine_ID Then
|
Posted by Xander Zelders
Where did my Dataset Go?
Found the following interesting discussion in the Newsgroups:
Where did my Dataset Go? by:Wayne Wengert
| I have a VB App (VSNET 2003) in which, during form load, I create a dataset (ds1) and then populate a datagrid by binding to the dataset. That works fine. The form has a button which, when clicked, initiates an export process. When the button click event opens, the dataset is "Nothing". The dataset is Dim'ed to be available throughout the form. Other variables dim'ed at that same point are fine and can be used within the button click event.
What is closing my dataset?
Wayne
| | | Reply: by:Anonymous
| | | Web app or windows app?
could we a code example?
B
| | | Reply: by:Wayne Wengert
| | | Sorry - It is a Windows app. Portion of code follows:
==================================== Public Class Form1
Inherits System.Windows.Forms.Form
Dim cn As SqlConnection
Dim strSelectedRegionalID = "Denver"
Dim strSQL As String
Dim ds1 As DataSet
Dim ShowSets As DataRelation
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents btnXMLExport As System.Windows.Forms.Button
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
Friend WithEvents DataGrid2 As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.btnXMLExport = New System.Windows.Forms.Button
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
Me.DataGrid2 = New System.Windows.Forms.DataGrid
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(12, 39)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(472, 160)
Me.DataGrid1.TabIndex = 0
'
'btnXMLExport
'
Me.btnXMLExport.Location = New System.Drawing.Point(186, 429)
Me.btnXMLExport.Name = "btnXMLExport"
Me.btnXMLExport.Size = New System.Drawing.Size(104, 23)
Me.btnXMLExport.TabIndex = 1
Me.btnXMLExport.Text = "Export to XML"
'
'DataGrid2
'
Me.DataGrid2.DataMember = ""
Me.DataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid2.Location = New System.Drawing.Point(12, 239)
Me.DataGrid2.Name = "DataGrid2"
Me.DataGrid2.Size = New System.Drawing.Size(472, 146)
Me.DataGrid2.TabIndex = 2
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(493, 457)
Me.Controls.Add(Me.DataGrid2)
Me.Controls.Add(Me.btnXMLExport)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load the data
..........................
DataGrid1.DataSource = ds1
DataGrid1.DataMember = "CGShows" '<= ds1 is fine here
/'Wait for user to Click Button
Private Sub btnXMLExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXMLExport.Click
Dim filename As String = "myXmlDoc.xml".
Dim myFileStream As New System.IO.FileStream(filename, System.IO.FileMode.Create)
ds1.WriteXml(myFileStream, XmlWriteMode.WriteSchema) ' <= ds1 is "Nothing
End Sub
|
Posted by Xander Zelders
Password Filter DLL
Found the following interesting discussion in the Newsgroups:
Password Filter DLL by:Andreas Hecker
| Hello, i want to write a password filter dll for windows 2003 server. I found an example in msdn http://support.microsoft.com/default.aspx?scid=kb;en-us;151082 wich is written in c++. I am not able to understand c++ in a way to port this onto ..net framework. Can anybody help me to find out how to solve this problem using vb .net or c#?
Thank you for your help Andreas
| | | Reply: by:Klaus H. Probst
| | | Just by looking at that article there's no way you're going to write one in C#. That API requires a straight callback into the DLL, which you cannot do in C#. -- Klaus H. Probst
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
Please do not multipost!
I replied in the German VB.NET group ;-).
-- Herfried K. Wagner
|
Posted by Xander Zelders
An application framework for VB.NET
Found the following interesting discussion in the Newsgroups:
An application framework for VB.NET by:alantolan@users.com (SionnachRoe)
| All,
I was wondering if there is anything akin to the MFC App/Doc/View framework available for VB.NET, either as part of .NET, as a commercial library or as opensource. Background ==========
We are moving from VB6 to VB.NET and are planning to write a number of applications within VB.NET.
We have a number of ex C++/MFC people who have suggested that we create an application architecture/framework that can be re-used throughout all these applications.
This strikes me as a good idea. When completed we can create an 'out-of-the-box' application that provides an amount of basic functionality just by deriving the classes for the new application from a set of base classes. We get a common look and feel for all the company's apps and it should gets us focussed on constructing common functionality in a single place, not having each development group implementing their own version of something for logging or dataaccess or whatever. Wins all round. Problem =======
As well as being a good idea this also strikes me as being a LOT of work.
So it ocurred to me to ask whether something like this already exists either that we can use - MS provided, Open Source, whatever - or that we could license.
Thanks in advance for all answers/comments.
S.
| | | Reply: by:Klaus H. Probst
| | | It depends on what you consider "framework". There are bits and pieces out there. For example, MSDN has an article that details a command routing system for GUI applications, similar to MFCs. Then there are projects like Genghis. And some of Microsoft's application blocks can be useful. But there's no unified framework that approaches MFC's depth. -- Klaus H. Probst
| | | Reply: by:Cindy Winegarden
| | | Hi Alan,
Check out MVP Kevin McNeish's Mere Mortals .NET Framework from http://www.oakleafsd.com/.
-- Cindy Winegarden
|
Posted by Xander Zelders
'System.Net.WebException' - Strange Error
Found the following interesting discussion in the Newsgroups:
'System.Net.WebException' - Strange Error by:A User
| Very strange - this code is copy and paste from the net and works on 2 of my 3 development machines - but of course not the machine I need to run it on.
I've seen similar posts, but no solutions that work for me. Is it a problem with my proxy settings on this 1 machine? I have all the boxes unchecked for LAN Settings. Net browsing is fine. Other machines are the same.
The error is: An unhandled exception of type 'System.Net.WebException' occurred in system.dll
Additional information: The underlying connection was closed: The remote name could not be resolved. Code for form load:
'Create a new WebRequest object, which can only be done through the static Create method of the WebRequest class Dim wrGETURL As WebRequest wrGETURL = WebRequest.Create("http:www.cnn.com")
'use whatever settings have been configured in Internet Explorer wrGETURL.Proxy = WebProxy.GetDefaultProxy()
'use it to obtain a Stream object corresponding to the response to your request. Dim objStream As Stream objStream = wrGETURL.GetResponse.GetResponseStream()
'After you have the response stream, you can treat it like any other stream (such as from opening a text file) and read through its contents line by line or even all at once. The loop below reads the stream one line at a time until the ReadLine method returns Nothing, outputting each line to the console. Dim objReader As New StreamReader(objStream) Dim i As Integer = 0
Me.TextBox1.Text = objReader.ReadToEnd
| | | Reply: by:Greg Burns
| | | wrGETURL = WebRequest.Create("http:www.cnn.com")
is that a typo?
Greg
| | | Reply: by:A User
| | | Indeed that is a typo - and the url does not matter as I've tried a whole bunch. The problem is exactly as outlined though. Can anyone help?
|
Posted by Xander Zelders
|
|
|
|