Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo


  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


0 Comments


  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


0 Comments


  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


0 Comments


  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


0 Comments


  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


0 Comments


  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


0 Comments


  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


0 Comments


  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


0 Comments


  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


0 Comments


  .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


0 Comments


 
Previous Posts
    - Q: For Each loops
    - How to find a list of SQL Servers?
    - How to find whether an Image is Color or b/w?
    - Find Missing Data
    - Design Tutorials
    - Dateformat on databound textboxes?
    - Moveable Toolbars
    - Help with hiding LinkButton in DataList
    - Project converted from VB6 to VB.Net gets subclass...
    - .Net says I'm not Online, but I am!

Archives
    - 2006-01-01
    - 2006-01-08
    - 2006-01-15
    - 2006-01-22
    - 2006-01-29


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland