How To Make Namespaces Behave Like C#?
Mar 4, 2010
I am converting projects from C# to Visual Basic, and the namespaces in VB.NET behave in a weird way. There is some kind of hidden default namespace, and it's annoying. I want it to behave identical to C#, which works as expected - things go into the namespaces you create for them.
I've been getting around it usually with say
using MyClassLibrary;in C#, and in VB
Imports MyClassLibrary
Imports MyClassLibrary.MyClassLibrary
but it would be nice to have the functionality the same, and also logical.The other bigger problem is, I have a .tt file, and the C# project generates the code in a different namespace to the VB one.
Is there some solution to make both behave identically with regards to namespaces?
View 3 Replies
ADVERTISEMENT
Feb 27, 2009
Is it possible to make a checked list box behave like a Radio button?
View 1 Replies
Nov 25, 2011
This is driving me round the bend. I'm a long time VB.NET forms developer, quite new to ASP.NET and completely new to MVC. I'm creating vbhtml pages that use the VB.NET razor syntax, and I seem to be constantly fighting against the UI which is trying to indent my code incorrectly. Take the following example, based on the template page for a new Razor view:
@Code
Layout = Nothing
End Code
[code].....
View 2 Replies
Jun 1, 2012
I have a very simple class that holds a few public properties - ID, Text, Colour, etc. and a Boolean called 'SelectedItem'. Just like the Checked property on RadioButtons, only one item can have its SelectedItem property set to True within a particular group. Note: there will be several separate groups (lists), each allowed to have only one item with SelectedItem = True.
My first thought was that I would probably just have to handle everything outside of the class, setting SelectedItem to False for every other item in a particular list when another item was selected. But that seems rather inelegant to me. So I've been trying to think of how this might be done within the class. For example: could I perhaps have a private string property called say "GroupName" - set in the New sub when adding a new instance of the class - and then use a private shared method to set every item's SelectedItem property to False, provided the item has the same GroupName as the newly selected item? I would have a go at doing this but I have no idea how to enumerate every instance of a class from within that class, or whether that's even possible. Is it? Or is there another (better) way to achieve my goal? Here is a cut-down version of what I've got so far:
Public Class ResourceItem
Public ID As Integer
Public Text As String[code]....
As can be seen: instead of instantiating a new ResourceItem and passing that as an argument to the manager's Add procedure, I'm simply passing the details of the new item and the procedure is creating the item from those. I don't know whether this is a good or bad idea - please advise - but I've done it because I couldn't figure out how to make the SelectedItem property only writeable by the manager, so I wanted to avoid having directly accessible objects that could have their SelectedItem property set to True without it deselecting all the other items in the same group. Of course that still leaves the possibility of setting a variable to one of the manager's list items and setting it from there, so I would still like to know how I could prevent that, if possible.
UPDATE: I didn't use the code above in the end, deciding instead to go with Cyborgx37's solution - which seems to work perfectly well for me despite the warnings about best practice. I also realised I would need to use the same class in another scenario where multiple items could be selected, so it was easy to add a Boolean property to the manager to enable that.
View 2 Replies
Jun 15, 2009
I am using the follwoing code to generate Menustrip at runtime.
Dim dgv1 As DataGridView
dgv1 = Me.MenuDataGridView
ReadMenuInGridView(dgv1)
Dim MItems As New SortedList(Of String, ToolStripMenuItem)
For Each dgr As DataGridViewRow In dgv1.Rows
[Code] .....
Where the sub "ReadMenuInGridView" passes the DGV by reference and populates it with the menu item from the database. My question is,, the program as it is in the form listed above works fine (where I have a DGV "MenuDataGridView" created at design time), however, if I want to make it 100% dynamic and use a DGV created at run time I will not get the menu? Actually the program will not get in to the For loop?
Simply to do that we can replace the first 2 statement with:
Dim dgv1 As New DataGridView
'dgv1 = Me.MenuDataGridView
View 5 Replies
May 21, 2012
I have created ~ 9,000 desktop.ini files, using VB code shown at
[URL]
My goal was to assign an icon to each folder of a set of folders.My problem is that the created desktop.ini files seem to behave erratically: some folders display their assigned icon, some do not.I verified that all folders and assigned icons exist.
View 2 Replies
Jan 12, 2011
I'm trying to get the 'Enter' key to behave like the tab key in a combobox control. I've placed the following code in the keypress event: If e.KeyChar = ToChar(Keys.Enter) Then NextTextBox.Focus()End If When ran, nothing happens. I've placed a break point at the 'private sub' line, and the code is not breaking. What am I doing wrong?
View 5 Replies
Feb 9, 2010
This questions is for VBers, it's irrelevant in C#.
In VB, when you create a module, all it's fucntions and members are available in the scope without need to type the module name, just like all the VB functions (Rnd, Mid, IIf etc.).
I want to create a module but I should have to explicitly write it's name to access it's members, i.e. it shouldn't be loaded to the scope like a namespace.
Update
For example, I have a Module of extension methods, I don't want all it's members to show up on the scope and in the intellisense.
I want it to be available only by instance.ExtensionMethod().
View 3 Replies
Dec 23, 2009
If you create new projects in C# and VB.NET, then go directly in the Immediate Window and type this:
? 567 / 1000
C# will return 0, while VB.NET will return 0.567.To get the same result in C#, you need to type
? 567 / 1000.0
Why is there this difference? Why does C# require the explicit decimal point after 1000?
View 5 Replies
Feb 20, 2009
I'm developing with VB.NET 2008.One of my host was crashed, so I take the files and keep development on another host. But now something strange is happening:All frames, lines and shapes are disappeared on design-time, but are seen normally in runtime.
[Code]...
View 1 Replies
Apr 8, 2010
I am developing a windows desktop application and I am using vb.net 2008 Now I have 5 datagridviewcheckboxescoloumns and i want them to behave like radio button.How can i accomplish it. I made lots of search on internet to solve this problem but i couldn't so far. Actually if i had two coloumns it wont be problem i can handle it.
View 8 Replies
Dec 30, 2009
Example:
Dim Sh32 As Object = CreateObject("Shell.Application")
Dim path As String = "C: empcatalog.zip"
Dim sf As Object = Sh32.NameSpace(path)
-> does not work, sf = Nothing
Dim Sh32 As Object = CreateObject("Shell.Application")
Dim path As String = "C: empcatalog.zip"
Dim sf As Object = Sh32.NameSpace(path.ToString)
Clearly path = path.ToString, but they behave differently when used as COM parameters.
View 1 Replies
Jan 27, 2012
I want to implement a password text box that will behave like the one we see in Windows 7 (ie, when there is no user input, then it will display a string 'Enter password', and when the user press any key, this string is cleared). I tried all the events like 'TextChanged', KeyPress', etc., but failed to get the result.
View 5 Replies
May 27, 2011
I need to create a menu bar (similar to VB6) for my ASP.NET application.
What I don't need is a standard navigation menu bar (plenty of those out there). I'm not redirecting to a different page. What i do need is a menubar that will behave similarly to a VB6 menu, or ASP.NET button control. I have to postback and execute some VB code (depending on what menu item the user selected).
View 3 Replies
Oct 15, 2011
I use some random number generators in a piece of VB.net code to simulate Gene reproduction. It works as followed:
- I generate a male chromosome that contains 46 random chromosomes which I put in the Arraylist: MaleChromosomes.
- I generate a female chromosome that contains 46 random chromosomes which I put in the Arraylist: FemaleChromosomes.
- Then I have a piece of code that randomly picks 23 chromosomes from the female arraylist and randomly picks 23 chromosomes from the male chromosomes ( Very simple simulation of reproduction ) and put these in the arraylist: Child
- I repeat this for the second child ( Arraylist: Child2.)
- Now I have piece of code that compares these arraylist to see how many chromosomes the two children share.
View 1 Replies
Jul 8, 2011
I have a big stored procedure that I run. At the end its supposed to select a singe value to say if it succeeded or not, so I run the query as
Dim Command As New SqlCommand(SqlString, Conn)
Return Command.ExecuteScalar()
Which works. However there is an error in my stored procedure. I know its causing an error because the logic in the stored procedure rolls back the transactions, and after the Execute Scalar call, my transaction count is down to 0 and the my data hasn't changed. However no SQL exception was generated.
The strange part is, I changed the code to grab all the result sets from the SP to see if I could get more information. So I called the same SP like this,
Dim DAObj As SqlDataAdapter = New SqlDataAdapter
Dim CommandObj As SqlCommand = New SqlCommand(SQLString, Conn)
DAObj.SelectCommand = CommandObj
Dim DS As New DataSet()
DAObj.Fill(DS)
When I run this, with the exact same sql as before, executing the exact same stored procedure, this time I get an SQL exception because one of my nested SP calls was missing required parameters. So what could cause this? Why would running it one way produce an error and the other way have the error but not report it? Is the difference on purpose, or some kind of obscure bug in ADO.Net?
View 2 Replies
Nov 4, 2010
I'm just starting out learning C# this may be really simple but in VB i have these namespaces
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Globalization" %>
<%@ import Namespace="System.Data.SqlClient" %>
How do I go about using those namespaces in C#?
I tried
namespace System.Data
and
using System.Data
but they didn't work
View 4 Replies
Dec 12, 2009
In C#, if you do this, it will compile:
namespace Name
{
public class Test
{
[code]....
I get (depending on the way I try to use "Test") either "'Name' is not a member of '<Default>'." or "Type 'Name.Test' is not defined." in my error list. I've found two ways to make it work, but neither are reasonable to expect of a user. One is to remove the "Root Namespace" from the project properties. The other is to include that namespace between "Global" and "Name".
I have made a custom tool that uses CodeDom to generate code for both C# and VB.NET. This is the reason why neither of the two fixes above are feasible: I can't expect my users to have an empty root namespace, and I'd hate to have to do VB-specific tricks in my code generation (kind of defeats the purpose of using a language-neutral tool, doesn't it?) such as picking out the "Root Namespace" (not that I'd know how off the top of my head) and including it in my code generation.
I don't want to leave out the global modifier either, because it protects the tool from users picking bad names for the generated output. Does anybody have a suggestion for how I should deal with this?
View 1 Replies
Jul 13, 2010
Is something like this possible?
Namespace Transaction, Document
Class Signer
Public Sub New()
[Code].....
I basically want to be able to instantiate the Signer class from either Namespace. The reason is that I mistakenly set it up in the Transaction class and need to migrate it over to the Document class without breaking existing legacy code. I'd prefer to not have the same Signer class duplicated in both Namespaces if possible.
View 3 Replies
Oct 19, 2010
I am building an ASP.Net application and want to use Namespaces for the first time. Within an App_Code folder, I have created three classes called RewriteContext, RewriteModule, and RewriteHandler.
[Code]...
View 10 Replies
Aug 30, 2010
I am using XML Literals and Linq to XML to read/write data to an external system.[code]The client now wants to put the url in a parameter table so the table can change to point to a test server or a real server. I assume that I cannot put a variable in my Imports statement.So how to I access the correct URL from a variable?url...
View 13 Replies
Apr 6, 2011
I had weird compile errors. When I opened a project of mine today, suddenly I received over 100 errors. It gives even error for try catch, foreach and all those functions under system and Microsoft.VisualBasic namespace. I have also class libraries and although references are looking added, main project doesnt recognize references as well. I tried clean solution, rebuilt solution, cleared my aspnet tmp folder, re-added references but no help. what could be the problem? anyone experienced such problem. my VS2010 isnt spoiled because any other project works fine,even with same class libraries.
View 2 Replies
Feb 8, 2012
I have ASP.NET Application: I have added 5 classes with different Namespacess in App_Code folder..
In Default.aspx.cs file.. I just want to get the list of available Namespaces in App_Code folder:
I tried : AppDomain.CurrentDomain.GetAssemblies();
but i didn't find Namespace that is available in App_Code Folder
View 1 Replies
Jul 31, 2009
I am working with VB.Net and am kinda new. I was wondering, if my asp.net project has a lot of shared functions, can I put them all into one Namespace? Do I have to put them into a class?
View 7 Replies
Feb 15, 2010
I have a bunch of methods that do some formatting on data that is contained in a structure. I'm passing the structure to the methods as a parameter. The problem is that the same structure is returned from 2 different webservices depending on the program flow (I did not create these services and cannot change them). So at one point I would be passing WebService1.Service.MyStruct and later I might have to pass WebService2.Service2.MyStruct.
Is there a way I can write only one method to handle both type of parameter? The struct is the same and only differs by namespace. I can overload the methods but I was wondering if there was another way to do this with reflection or something along those lines.
View 3 Replies
Jul 14, 2011
Question: How does the class for the serialization of this XML content look ?
<?xml version="1.0" encoding="utf-8"?>
<vcc:CreateTextSearchResponse xmlns:vcc="urn:veloconnect:catalog-1.1" xmlns:vct="urn:veloconnect:transaction-1.0">
[code]....
View 2 Replies
Dec 9, 2010
VB has a feature that C# does not, imported namespaces at a project level (My Project>References>Imported Namespaces). When new people check projects out of source control none of our custom imports are included. Where is this VB specific Imported Namespaces stored?
View 2 Replies
Nov 17, 2009
I've only just noticed that all the 3.5 namespaces are greyed out in VS2008. Any idea why that would be? The 3.5 framework is installed OK.
View 3 Replies
Dec 2, 2011
I have two XML files.
Consumers.xml
<consumers>
<consumer>consumer1</consumer>
[code].....
View 2 Replies
May 6, 2011
When I add an 3party Library (Gibraltar.Agent) to a VB.NET project I get namespaces which interfere with my current code. For example the namespace Gibraltar.Agent.IS makes the following code invalid:
[Code]...
View 3 Replies