String.Empty To Initialize A Variable?
Mar 31, 2009
I always initialize my variables with a value when declaring them.I was wondering if using String.Empty to initialize a variable is correct.'Is this OK ?
Dim strValue As String = String.Empty
'I used to do
Dim strValue2 As String = ""
On the same subject.
[code]....
View 13 Replies
ADVERTISEMENT
Oct 2, 2009
just found out that replace(string does not do the same as string.replace when my string variable was an empty str the first one returns "nothing" and the second returns an empty string (as expected).just sloppy coding anyhow, it was a function that was converted from classic asp and never rewritten properly. [code]
View 1 Replies
Jun 28, 2010
This must've have been asked before but I couldn't locate it. In a mixed code project (VB and C#) we were debugging some old Visual Basic code where a statement as follows could be found:
If Request.Params("xxx") <> "" Then
'do something
I considered this a bug as Request.Params could be null, in which case the statement would've become false which wasn't the idea. So I thought. I just found out, -- probably for the tenth time and I will keep forgetting -- that the following two statements are not equal, while Nothing in VB should be equal to null in C# (thought I):
if(String.Empty == null) // always false
If String.Empty = Nothing Then ' always true
Should I dismiss this as a typical Microsoft backward compatibility effort, or should I consider this a huge error in the VB.NET compiler? Does anybody know the Microsoftean opinion on this oddity?
View 3 Replies
Sep 15, 2011
In C#, I can declare an array variable like this: object[] Parameters;
And initialize it like this: Parameters = new object[20];
In VB, declaring and initializing an array is easy:
Dim Parameters(19) As Object
Dim Parameters As Object(19) ' Alternative Syntax
How would I initialize an array variable that has already been declared in VB.NET? Parameters = New Object(19) doesn't work.
For example, how would I translate the following to vb.net?
int value = 20;
object[] Parameters;
if (value > 10)
{
Parameters = new Object[20];
}
View 3 Replies
Aug 11, 2010
I have a array of strings and I am looping through them, but the string might be empty so I am trying this:
[Code]...
View 3 Replies
Mar 29, 2012
I have 2 web pages. In the first webpage I have a text box which takes an user input.The number of controls rendered in the second page is based on the user input in the first page.I am storing the user input from the first page as a session variable [code]Now, I wish to use this session variable in the next page for initializing a global variable and what I tried to do is Dim num_Invitees As Integer = CType (Session("NoOfControls ToGenerate"),Integer)But this gives me a NullReferenceException.Can someone please suggest me what exactly I should be doing in order to use the session variable to initialize a global variable and also why the session variable's value is null while using outside a function but works fine when used inside a function?
View 1 Replies
Jul 6, 2010
Dim pix() As new List(Of String) = {"*.jpg", "*.avi", "*.mov"}
Dim pix As new List(Of String)() = {"*.jpg", "*.avi", "*.mov"}
Dim pix() As List(Of String) = {"*.jpg", "*.avi", "*.mov"}
Dim pix As List(Of String)() = {"*.jpg", "*.avi", "*.mov"}
Does it matter where the () are?
What difference does New make?
View 1 Replies
Nov 18, 2009
I'm looking for a way to search a string variable for two words and copy the text in between them into another variable. This needs to be done as many times as the match occurs.
View 3 Replies
Jul 5, 2011
How create a array of objects (another class) in VB.NET and initialise it. Since I am not sure about the length of the array, it should be generic. I mean I should be able to add any number of objects to the array.
View 2 Replies
Mar 9, 2010
how should i initialize the string array in this procedure call
vb
Private Sub SetAddres(Optional ByVal Addrvalues(4) As String ) End Sub
how to initialize it with values and also with empty strings or null values
View 7 Replies
Feb 4, 2012
I was trying to call a method using Reflection on a method that has a STRING parameter.However a STRING does not have a parameterless constructor.So instead of something like.>>
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
[code].....
View 15 Replies
Mar 2, 2009
i have a string array that i want to output to a text file. the array size is 10000. i fill the array starting from 0 with some strings. at the end, i only want to show the array from index 256 to the last array that is not empty (for eg. if the array is filled with data from 0 to 2000, i only want the text file to show the data from 256 to 2000 and ignore the remaining strings). Is there any function to do this?t i use is shown below
Dim myArray(10000) as string
Dim strArray As New System.IO.StreamWriter("c:List.txt")
strArray.WriteLine("{0,10}{1,30}", "Index", "Symbol")
[code].....
View 8 Replies
Mar 2, 2009
i have a string array that i want to output to a text file. the array size is 10000. i fill the array starting from 0 with some strings. at the end, i only want to show the array from index 256 to the last array that is not empty (for eg. if the array is filled with data from 0 to 2000, i only want the text file to show the data from 256 to 2000 and ignore the remaining strings). Is there any function to do this? i am using visual basic express 2008. The code that i use is shown below
[Code]...
View 2 Replies
Feb 24, 2010
I have a nullable database field of type varchar. I am writing a unit test for a service method that retrieves the value of this field. The service method uses a custom DAL that returns a value of String.Empty if the database field is Null (this is desired behaviour).
[Code]...
View 3 Replies
Jun 2, 2011
Say I have something like this
Dim Level1 as Integer = 83
Dim Goal as String
Goal = InputBox(" What level is your goal?")
[code].....
View 7 Replies
Jun 8, 2009
I have a webpage that has a Telerik RadComboBox on the page. One of the properties of this ComboBox is EmptyMessage, which fills the combobox with a message when an item is not selected. I am binding my combobox to a datasource at runtime and for some reason, it wipes this EmptyMessage away. Is there a way to keep my data items in tact and have the empty message there too?
View 5 Replies
May 19, 2010
I'm using VB's StringBuilder, and I was curious what is considered "best practice" for emptying the builder/setting it to a new string. Would it be something like this:[code]or is there a "Better" way?
View 2 Replies
Sep 16, 2010
Possible Duplicate: In C#, should I use string.Empty or String.Empty or "" ? I just don't understand the benefits of using String.Empty over "". Aside it being strongly typed its longer.
View 2 Replies
Apr 30, 2012
I am storing value in Double. If that value is 0.0, I dont want to display anything.
means,
If Value = 14.0, I want to display Value = 14.0
If value = 0.0, I want to display Value =
View 2 Replies
Apr 13, 2010
Why does the first if statement evaluate to true? I know if I use "is" instead of "=" then it won't evaluate to true. If I replace String.Empty with "Foo" it doesn't evaluate to true. Both String.Empty and "Foo" have the same type of String, so why does one evaluate to true and the other doesn't?
//this evaluates to true
If Nothing = String.Empty Then
[CODE]...
View 3 Replies
Nov 26, 2010
I have an attribute class:
[code]...
With that said, shall the Private Property Attributes() As String() not return the values of DirectoryAttribute placed over the interfaces properties as well, since I specify True in the inheritance parameter of the Type.GetCustomAttributes method?
View 1 Replies
Jan 5, 2011
In my EF4 EntityModel I have an entity named Users. Users have the common UserName and Password string fields. If I do something like this
Dim u as new USERS
U.UserName = String.Empty
Then U.UserName are still Nothing.
But if I Do Something like this
Dim u as new USERS
u.UserName = "A"
u.UserName = String.Empty
Then U.UserName take String.Empty as value without problem.
The reason is the way that EF4 generate the UserName Property
Public Property UserName() As Global.System.String
Get
Return _UserName
End Get
[Code] .....
I do not want to make two assignations every time I want to set string.empty to a property with a nothing value, and I do not want to remember that I must do it in this way everytime, because I'm pretty sure that I will forget it and then I will introduce bugs in the code. I just want to assign the empty.string value to a property and the property take "" as value.
View 2 Replies
Aug 19, 2009
How can i check if a string collection is empty? I tried
VB.NET
My.Settings.IPBank.Count = 0
But it said
Quote:
Object reference not set to an instance of an object.
View 6 Replies
Oct 31, 2011
I'm sure this is simple to do but I'm struggling to get this work, I've tried using convert.tostring, decimal.tostring, ctype(object, type) and cstr(object) but without success. I guess I'm trying to change the decial object to a string object and then assign it a value of empty string but always get type mismatch error.[code]
View 4 Replies
Jan 31, 2011
How can I create an empty string that is a certain length?
View 5 Replies
Jul 27, 2010
In my program i have it send an email and it send the email but after it sends i get this error "The parameter 'addresses' cannot be an empty string. Parameter name: addresses". I don't know why.
View 1 Replies
Apr 26, 2011
To make it clear this IS homework, however this is also a method of research. i only ask when i get in binds i can not find answers to in other forums . There are so many i could spend more time[code]...
View 2 Replies
Apr 4, 2009
I am trying to insert a string variable inside of two strings, and make a combined string. Public Sub Page_Load() Dim Id As String Id = Trim (Request.QueryString("Id")) End Sub Dim mp3text as string url... & Id & ".mp3" My goal is to make the mp3text variable have a string that is: url...(If Id is 7) It is for some reason not connecting up correctly. I checked what string it is outputting and this is what it is giving: url...It is missing the Id content.
View 12 Replies
Jul 9, 2010
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias _
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Dim value As String = ""
Dim length As Integer
Dim IniFileName As String
GetPrivateProfileString("Config", "UserName", "None", value, length, IniFileName)
but value contains an empty string I confes to being a VB n00b, less than a week, in fact, but I can't see what's wrong there. The file exists, it contains a section called "Config" which has an entry called "UserName" with a value - but even if not, wouldn't value take the default?
Edit: It's not returning an empty string - it's returning whatever I initialize value to before calling GetPrivateProfileString().
Which is to say that if I Dim value As String = "xxx" then it stil contains "xxx" after the call and not the default value.
View 4 Replies
Apr 7, 2009
I've always use String.IsNullOrEmpty to check for a empty string. It recently come to my attention that a " " count as not a empty string. For example,
Dim test As String = " "
If String.IsNullOrEmpty(test) Then
MessageBox.Show("Empty String")
[Code]....
It will show "Not Empty String". So how do we check for " " or " " in a string?
edit: I wasn't aware that " " count as character.
View 13 Replies