Gained By Using The Function Itself To Hold The Return Value Instead Of Declaring A Local Variable?
Oct 28, 2010
What's best practice (in VB.Net):
Function GetSomething() as String
GetSomething = "Here's your string"
End Function
or
Function GetSomething() as String
Dim returnString as String = "Here's your string"
Return returnString
End Function
Obviously, neither of these implementations make any sense, but they're just meant to illustrate my point. Is there anything to be gained by using GetSomething itself to store the return value instead of declaring returnString locally and then returning that (does it avoid having an extra string allocated/instantiated - and if so, are there any performance/memory benefits)?
View 6 Replies
ADVERTISEMENT
Nov 17, 2010
How does the GC dispose objects created in the following 2 scenarios?
1)
Private Function DoSomething() As Boolean
Return New DatabaseManager().Insert()
End Function
2)
Private Function DoSomething() As Boolean
Dim mngr As New DatabaseManager()
Return mngr.Insert()
End Function
In Option 1, I don't create local variable to hold the reference of the object. In Option 2, I hold the reference in local variable.What option is better and why? (if any)
View 2 Replies
Apr 26, 2010
I have created my own ListViewItem class, and added some custom properties to it of attributes. What I have at the moment is a tooltip which shows all of those custom properties (about 18 of them).What I want to be able to do is if multiple are selected, to show a tooltip, but if a property (say Title) for all of them is "My Title" it will show that, otherwise if they are different, I would like it to show "VARIES"Is there a way of declaring a parameter in my function and return a value? [code]
View 1 Replies
Aug 12, 2010
I have a button inside a one of my forms which contain a lot of coding and normally a lot of variables declaration.
Is there is a option/add-on that I can use/set that enable me to display all the variable used inside the sub or function I am currently working in?
All I can find is add-on to display the Properties/Methods and only Public variables inside the form or inside the class. but I need to list the local variables also.
View 8 Replies
Jun 3, 2010
Can't seem to figure out how to use a function return variable in global Dims[code]...
I have also tried adding "FixPath()" under Sub On_load() but got same result. Also the reason I have to have these global is because I have around 30 Subs that refer to "Path" Variable.
View 1 Replies
Jun 17, 2010
I am writing a program with multiple forms (for inputing loan/financial information - so they are set up exactly the same albeit a form number (ie: 1-6)) that feed into a summary page form to display each individuals form's information. When the user closed a financial form, it then feeds the information to a summary page using the code I have below: [Code]. I am new to working with functions, and have not been able to find anything that can show me how to fill multiple textboxes with them (I only know how to return a variable using the function to work a calculation). Any way that I can write a function (or any other call) for this would save me a tremendous amount of coding, and make debugging worlds easier.
View 3 Replies
Apr 12, 2012
Say I've got the following variables:
Public Shared x As String = "100"
Public Shared y As String = "text"
Public Shared z As String = "something"
[Code]....
But this doesn't do what I want, naturally. What I want is that my function giveVar returns the value of the variable that holds giveVar. For example I call giveVar("x") I want my function to return "100".
Of course this can be done by a Select Case but thats not what I like to do. Is it even possible to call a value based on a string?
[edit:]
Namespace i18n
public NotInheritable Class Settings
Public Shared LanguageCode As String
[Code]....
I think this works so far, BUT I get the following error on the CallByName(Me, varName, vbGet) at the Me : "me is only valid within an instance method"
View 5 Replies
Jul 13, 2010
It's often the case that I can write a nice tight little VB.NET function, and when it comes time to do the Return statement, it's really natural to just return the result of a quick calculation or a method call. However, this makes it difficult if I need to step through the debugger to see what is going to be returned from that Function. For example, take this simple method to illustrate the concept[code]...
View 3 Replies
Dec 1, 2010
I'm wondering whether its possible to have a function's return type and input arguments as a variable.
For example this function:Private Function MyFunction(ByVal argument1 As VariableType) As VariableType
[Code]...
View 6 Replies
Mar 9, 2010
Im trying to build an error-logger that loggs running values that is active in the function that caused the error. (just for fun so its not a critical problem)When going in break-mode and looking at the locals-tab and autos-tab you can see all active variables (name, type and value), it would be useful to get hold of that for logging purposes when an error occur and on some other occasions.For my example, I just want to find all local variables that are of type string and integer and store the name and value of them.
View 1 Replies
May 12, 2009
I would like to know how to declare a variable that holds bits.
View 11 Replies
Apr 26, 2011
Trying to declare some arrays. I haven't worked with them that I remember. I always took the long road, of declaring each and every variable, but would like to learn this method. The problem is I'm having trouble with the methods I'm finding on the net..[code]for some reason there is a squiggly under each MonsterName except in the declaration that says "declaration expected"
View 16 Replies
Mar 3, 2012
i am reviewing variabes, and just wondering any variables that can be used in math to hold a value this big =)
[Code]...
View 4 Replies
Mar 16, 2010
Is it possible to make a variable hold a reference to an integer instead of copying its value when using integerVariable = integerValue ?
View 2 Replies
Mar 9, 2009
How do i make a variable that can hold more than 1 piece of data. I wan't a variable that can keep 4 number in it. When i count them in using a for loop the only thing i have after it is finished is the last number counted in by the for loop.
View 2 Replies
May 30, 2012
We can declare a byte variable like this, for hex '88'
Dim bytes = New Byte() { &H88 } My case, 88 is assigned to a variable, hexvalue
How to declare the byte with the variable hex value?
Dim bytes = New Byte() { &H & hexvalue }the above throws syntax error.
View 2 Replies
Feb 19, 2011
I'm trying out a program which I found on the net. Why is it necessary to put to curly braces at the end of the statement? It gives an error: "Byte has no constructors". Dim data As Byte() = New Byte(1023) {} I can't put the code like this either, it produces the error "byte cannot be a 1-dimensional array".
[Code]...
View 2 Replies
Mar 29, 2012
if this silly but I am trying to declare a string variable by the following line
[Code]...
View 2 Replies
Feb 8, 2010
I have declared this variable in a module : Public GenericForm As System.Windows.Forms.Form
and then through code I can asign to that variable a specific form .For example GenericForm = Form1. Then I can use that variable to handle that specific form , for example :
GenericForm.Show
My problem begins when I want to handle a control on that form , for example :
GenericForm.TextBox1.Text = "aaa"
This code creates an error reading :TextBox1 is not a member of System.Windows.Forms.Form.I have been using code like this in VB6 and was quite useful ,but now in VB .NET I cannot .You see I have many forms on which there are some text boxes with the same name,so I declare a generic variable as Form and accordingly insert the code the desired text box conform the form I wish each time . Can I do this in VB .NET too ?
View 23 Replies
Dec 21, 2011
I have started using the builder class to create my connection strings for the sole purpose of making more generic connectivity code. However, I am stumped on this issue. The MS eConnect product apparently expects to receive integrated security=SSPI in its connection string if you want to use integrated security, (vs Integrated Secturity=True). I thought I would just pass "Trusted_Connection"="SSPI" to the builder class.
as it turns out, the item for Integrated Security is boolean and despite what the documentation says, will not give me SSPI in my connection string. Has anybody else found this issue and is there a simple fix for it? as for now, I'll simply strip out the item and replace it in my string.
View 3 Replies
Nov 4, 2010
I'm having a problem declaring a variable and setting it correctly.
BEGIN WORKING CODE:
private sub doSomething
Dim tokenHandle As New IntPtr(0)
Dim dupeTokenHandle As New IntPtr(0)
[Code].....
View 1 Replies
Apr 26, 2010
I am new to VB.NET but used to write a lot of code in VB 6.
How do i declare a variable length array in VB.NET?
In VB6, i would just put:
Dim sArrayList() As String
But when I do that in VB.NET, it highlights my array name and says "unused local variable". What do I need to do to get it to work without an error?
View 2 Replies
Aug 15, 2011
I am building a generic search form in my application. This will allow the user to search for various records throughout the application. The one thing I cannot seem to figure out is how to allow the declaration of the TableAdapter to change at run-time. Each part of the app will be passing a variable to the search form to specify which table should be loaded. In the form class I have the following:
FRIEND WITHEVENTS tbaSearchData AS database.databaseTableAdapters.TableOneTableAdapter This is great for TableOne. But, I have about a hundred tables that could be searched through. To load the data I'm using a DataGridView and populating it via a private method.
View 2 Replies
Apr 5, 2011
I have a class that I would like to link at construction to a given control (say a textbox)
I know I can put a variable into a subroutine referentially but is there a way to store it in the same capacity?
View 1 Replies
Apr 18, 2010
I've got
Option strict ON
Option explicit ON
How should I declare the variable:-
Dim bounds as? = (From item In xml...<bounds>
[Code]
View 7 Replies
Nov 14, 2010
So I do not know at design time if the var ms is going to be a stringreader or a memorystream. So I am trying to do basically this:
Dim ms as object = myfunction...
Dim mytype As Type = ms.GetType
Dim returnedobject = ser.Deserialize(CType(ms, mytype))
But I get an error saying "type mytype is not defined". How can I do this?
View 2 Replies
Oct 15, 2009
When I am writing a sub or function that does some calculations etc. I often need a loop or a integer variable to count.
An example:
''' <summary>
''' Compare elements with the new data and perform all necessary actions.
''' </summary>
[Code]....
As you can see, variables like timespan, nullCount and seconds are declared within this sub.
My question is, is it better to declare these in the class? I can imagine that would boost performance.
View 8 Replies
Nov 5, 2009
These two snippets do the same thing - is there one that's better than the other, or is it just a matter of preference?
Using context As MyDatabaseDataContext = New MyDatabaseDataContext()
Dim test = context.Employees.Count
End Using
vs.
Dim context As MyDatabaseDataContext = New MyDatabaseDataContext()
Dim test = context.Employees.Count
View 6 Replies
Jul 7, 2011
After many many years of using Classic ASP, I am attempting to delve into the world of ASP.Net using VB. I have gotten way to use to being able to declare variables on a page, inlclude that file and use it everywhere. I am struggling to declare a global variable. I just need
[Code]...
View 2 Replies
Oct 19, 2010
what is the difference between declaring a variable in this way
ByVal
List As IEnumerable as
a parametre in a function
Dim
[Code]....
View 1 Replies