vb.net

JScript Arguments Collection - .Net Equivalent

When writing code in JScript, as I am wont to do as I have never been a fan of ASP.Net and Jscript is infinitely more elegant than VBScript, you can call upon the arguments collection. This is extremely useful to pass into error handlers as you can then output messages to development teams which tell them exactly what the state of the ap...

Register Hotkey

I have this function: RegisterGlobalHotKey(Keys.F6, MOD_SHIFT | MOD_CONTROL); which call an API to register a global shortcut key in the system. void RegisterGlobalHotKey(Keys hotkey, int modifiers) I created a small options form to set this keys to be variables not fixed values like this: RegisterGlobalHotKey(VARIABLE1, VARIABLE2 | VAR...

Converting enum tostring of underlying type in VB.Net (Option Strict On)

I'd like to get a string representation of the underlying type of the enum. Dim target As System.ConsoleColor = ConsoleColor.Cyan Dim actual = 'What goes here? Dim expected = "11" ...

Date Calculating

Hi, Can u give me a simple function in vb.net which can take number of days and date as parameters and subtract these number of days from given date. Forexample Private function Calculate(Byval p_number_days,p_date) as date Dim calculated_date as Date= (p_date) - (p_number_days) return calculated End Function ...

override navigation of datagridview using enter key

How do you override the enter key in a datagridview so that it will set focus to the next column instead to the next row? ...

Linq SubmitChanges does not work

Hi, I have some code like this: Function GetTypeFromTableName(ByVal _TableName As String, ByVal _DataContext As DataContext) Dim Mytype As Type = (From t In _DataContext.Mapping.GetTables Where t.TableName = "dbo." + _TableName Select t.RowType.Type).SingleOrDefault Return Mytype End Function Dim DBA As ...

How to programmatically add a Tab to TabControl with a ListView control docked inside it?

I'm using Visual Basic 9 (VS2008) I want to create new Tabs as and when the user clicks an Add Tab button. The Tab must have a ListView control docked inside it. How to programmatically add a Tab to TabControl with a ListView control docked inside it? ...

To check if String contains an element from a List (of Strings) - Is there a better way to write this code?

For the following block of code: For I = 0 To listOfStrings.Count - 1 If myString.Contains(lstOfStrings.Item(I)) Then Return True End If Next Return False The output is: Case 1: myString: C:\Files\myfile.doc listOfString: C:\Files\, C:\Files2\ Result: True Case 2: m...

Comma seperated textbox value to list/array of strings - Is there a better way to write this code?

I want to create an array/list of strings of the Comma seperated strings (file extensions) that are entered in a Textbox. For the following block of code: Dim csv As String = Textbox1.Text + "," While csv.IndexOf(".") <> -1 lstOfStrings.Add(csv.Substring(0, csv.IndexOf(","))) csv...

Evaluation of an IF statement in VB.NET

For the following If-statements in VB.NET, what will be the sequence in which the conditions will be evaluated? Case 1: If ( condition1 AND condition2 AND condition3 ) . . End If Case 2: If ( condition1 OR condition2 OR condition3 ) . . End If Case 3: If ( condition1 OR condition2 AND condition3 OR condition4) . . End If ...

How to use Array / Collection in WPF?

I have a program which has some Textareas / Labels these can be anywhere on the Window and in any order - however I want to assign them values from a List, Collection or Array so I want one label to read MyCollection(1) and another MyCollection(2) and so on - they are not always together or in the same order so a ListBox is no good - how...

How to store and retrieve multiple shapes in XAML/WPF?

Seem to be having a lot of problems doing what should be simple things with XAML / WPF - I have created some XAML-based images using shapes like Rectangle and Ellipse to create icons which I need other parts of my application to use - but I cannot seem to find out how to do this - I seem to be able to store a Canvas in the Resource Dicti...

Time as a determining value

Hello, I have a section of code that is being used to determine if a certain event should happen. The code looks like this. If (Date.Now.Ticks Mod 100) < 4 Then Return True Else Return False End If The idea here is that this event should happen 4 time out of 100, or 4%. However, in prod...

asp.net gridview is fetching data too long

Hi, it seems common issue so I am surprised I didn't find solution already, maybe someone can help me out. I have a gridview that displays list of users of the app, this list is very big, and takes forever to load the data. Otherwise, data is paged through and once loaded everything goes fine. To help admins, I made search box and that w...

How do I fill a region to its bounds with a color on a graphics object?

I'm playing around and try to make a Coloring book for my children and I have a lots of black and white line drawings that I use as backgrounds so they they can paint on them. Now, I want to add a FILL-function so they can point and click somewhere where its white in the drawing and then let the function fill the whole region within it...

c# DateLastAccessed saved in SQL returned 1millissecond out (less)

When I save a file 'last saved' date time in a SQL database, I cannot compare with a future scan directly - eg if( SavedLastAccessDate <> FileSavedDate I have to do this: DateTime fileSavedDateTime = System.IO.File.getLastWriteTime(filepath); TimeSpan gap = fileSavedDateTime - SavedLastAccessDateTime; if (gap.Milliseconds > ) { do so...

What is the issue with UserControls in XAML / WPF?

I have had major problems with getting UserControls to work in XAML - I have spent hours trying to figure out all the problems but have got nowhere and cannot find where I am going wrong. The main problem I am having is when I create a UserControl for example a simple one which shows an object different colours - I have successfully crea...

How can I re-factor this code?

I'm using the following function to map columns from a DataTable (passed from the data tier) to object properties. The function exists within the class I'm populating. The class has two methods: Load() which loads the object with values and LoadAll() which returns a collection of populated objects. I wanted to be able to use the same cod...

Should we select VB.NET or C# when upgrading our legacy apps?

At the company where I work, we have a number of legacy apps written in Visual Basic 6.0. Without casting aspersions on the developers who wrote them, suffice it to say we have decided to rewrite the applications from scratch due to several compelling factors: 1.) Lack of documentation. 2.) Lack of exception handling. 3.) Lack of logg...

Global variable (or alternative) best practise in .NET

What's the best practise for storing global variables in a VB.NET WinForms app. For example when a user logs into an app you may want to store a CurrentUser object which can be accessed throughout the app. You could store this as an object in a module or create a class which contains members for all the required globals, you would still ...