Passing String Returned From Function?

May 2, 2012

I'm trying to establish a connection to my SqlDatabase while getting the connection string from a function. This will eventually lead to dealing with the appconfig file, but for now I'm just getting the basics established.

Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[code]....

View 13 Replies


ADVERTISEMENT

Passing String ByVal Into Function Without Changing Reference Value?

Jun 26, 2009

I know strings are immutable, so the minute you change a string reference's value .NET makes a brand new string on the heap. But what if you don't change the value of a string reference; rather, you simply pass it into a function ByVal -- does this operation copy the string value on the heap as well? My inclination is "no," but I'd like to confirm.

For example:
Public Function IsStringHello(ByVal test As String) As Boolean
Return (String.Compare(test, "Hello") = 0)
End Function

Calling program:
Dim myWord as String = "Blah"
Dim matchesHello as Boolean = IsStringHello(myWord)

I know passing myWord by value makes a copy of the reference to "Blah", but since I have not tried to change the string itself, would it make another copy of the string on the heap?

View 6 Replies

Dynamically Call A Function With Delegates By Passing A String To A Background Thread?

May 20, 2009

How do I dynamically call a function with delegates by passing a string to a background thread in VB.NET?

Currently my code is this

Public Sub invertImageBK(ByVal image As Bitmap)
Dim snxl As System.ComponentModel.BackgroundWorker = createBW()
snxl.RunWorkerAsync(New ImageProperties(image.Clone, "invertImage", Nothing))

[Code].....

View 1 Replies

Passing A Masked Telephone Number In The Form Of (999)999-9999 To A Function That 'strips' The Numbers Out And Puts Them Into A String?

Mar 10, 2009

So I'm passing a masked telephone number in the form of (999)999-9999 to a Function that 'strips' the numbers out and puts them into a string that I then use in an Update SQL statement. So far I have the code below that of course doesn't do anything:

Function StripPhone(ByVal sPhone as String) as String
Dim i as Integer
Dim sStripped as String

[code]....

View 6 Replies

How To Get Another Function's Returned Value

Apr 4, 2012

How to give another function's returned value in LINQ.[code]but in above query I should write code to store the return value of GetObjProperty Value(p) and add obj-p and returnValue combination to the dictionary.The last line below code is wrong. but please suggest me how to correct it. My intention is, I want output collection(say dictionary) of each fruitname and its color(returned by other function call) for all the fruits which the GetFruitColor is not nothing(it can be empty or valid string).[code]In above code last line is wrong. So how to put getFruitColor in k, how to correct it to save the k value and give me output as dictionary of fruit and k value.

View 1 Replies

How To Use Returned Value From Function

Sep 5, 2010

Why this code doesn't work? It returns an unexpected value actually total = 0.
total = Cscore(TextBox1.Text) * CDbl(TextBox2.Text)

When trying this
total = TextBox1.Text * TextBox2.Text
It returns the expected value but I need to pass textbox1.text to the function to get the desirable value

The function is this
Public Function Cscore(ByVal score As Integer) As Double
Select Case score
Case score = 100
Return 5.0
Case score >= 95
[Code] .....

View 4 Replies

Using Returned Value Of A Function?

Apr 2, 2011

I have many functions that perform mathematical calculations.

Here is one for example:

Public Function internaldiamofcasingpipecalculation(ByVal Externaldiameterofcarrierpipe As Double, ByVal insulationthickness As Double) As Double

[Code]....

View 8 Replies

Accessing Value Returned From Function?

Feb 22, 2010

I'm new to VB.NET and want to parameterise the SQL Connection Strings in my VB.NET App. I've added a function to my Main Form to retrieve the App.config File like:

Imports System.Configuration
Imports System.Configuration.ConfigurationSettings
Public Class MainMenu [code]....

In my other forms when i want to reference the Connection String, i get an error saying getConnStr is not declared?

Private Sub UpdDept_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
myconnection = New SqlConnection(getConnStr()) <=============
Dim mycommand As New SqlCommand()

why i get this when i've declared the Function as Public?

View 1 Replies

Handle Nothing Returned From Function?

Mar 18, 2009

When the AlertsSettings.xml is not present the Appsettings is assigned to nothing. The variables that follow that definition rely on the existance of that information which will normally be set by the load method. But when there is a problem and either of the variables do not get a value how do I handle that in the code that relies on those values. The Settings class deserializes an xml document and assigned values to properties.

Sub Main()
Dim Appsettings As Settings = Settings.Load("AlertsSettings.xml")
Dim AlertsServer As String

[Code].....

View 1 Replies

Object Returned By Reference From Function?

Aug 5, 2011

This should be a fairly common question, but I haven't found a straightforward answer anywhere.

If I instantiate an object within a function in VB.NET and return it, does it return it be reference or by value. IE - should I be worried about performance if I write something like this:

Public Function ret_obj_func() As big_object
Dim ret_obj As New big_obj(<lots of stuff>)
Return ret_obj
End Function

If I call this function from somewhere else, will it instantiate the object in the ret_obj and then create a deep copy to pass back a copy to the caller, Or will it just pass back a reference?

View 2 Replies

Set Combobox Displaymember To A Returned Value Of A Function?

Jul 2, 2009

Combobox with bound rowsource, but I want to change the displaymember to a string returned by a procedure. In Access/VBA I would have a little function to build the string, then simply code the recordsource of the cbo as:

"SELECT ClientIDS, fnGetName([ClientIDS]) AS ClientName FROM tblPerson ORDER BY fnGetName([ClientIDS])".

Pretty straightforward, but I've messed around with this for hours in VS2005/VB to no avail.SELECT ClientIDS, fnGetName

View 1 Replies

[2005] Is An Obejct Returned By A Function By Ref?

Feb 25, 2009

I have a 2 dimensional array of groupboxes that I use to populate a form setup so the first indice is a tab number and the second is the groupbox number.The user can dynamically add tabs to the tabcontrol but I need to add and populate groupboxes to the new tabpage and I can use existing groupbox data in the array for default values.I understand I have to code a deep clone of the source groupbox as it has textboxes in it so I want to add a cloneGBox function that returns a new, populated groupbox when I pass in the x,y indices for the source groupbox in my array.

dim gbx as groupbox = cloneGBox(x,y)
and code cloneGBX as
public function cloneGBox (byval x as integer, byval y as integer) as groupbox

[code].....

View 7 Replies

Setting A Radio Button Value According To String Returned From Database. String Is 'Yes' Or 'No'

Jul 24, 2009

I have a radio button control on a web form. The members of my ListItem collection are
assigned the following.

Text No
Value 0

Text Yes
Value 1

So what I need to do, is to readd a varchar value from my database and if the column value returned equals 'Yes' then I need to select the radio button that has the assigned value of 1. Otherwise if the value read from the database is 'No', then I need to select the radio button assigned a value of 0

So how can I set the value for my radio button? I experimented and could not figure it out. The 'Yes' or 'No' value is stored in my database in the field ds.Tables("employee").Rows(0).Item("answer")

So I tried something like this which is not correct:

RadioButtonList1.Items.FindByValue(ds.Tables("employee").Rows(0).Item("answer") = "Yes").Equals(True)

View 2 Replies

Accessing Cursor Data Returned By PL/SQL Function?

Jul 16, 2009

I am calling an Oracle function PKGDummy.F_EMPDATA using vb.net.

View 1 Replies

Convert Strings Returned From A Function To Numbers

Jul 27, 2010

I have the code below. The code returns a string in (IntersectingPoints) for X and Y. I need X and Y values to be in single and stored in an array to deal with later.[code]...

View 11 Replies

LINQ To EF Sum Function Error When No Records Returned

Jun 1, 2012

Have seen some solutions for C# but do not know how to solve the issue in VB.NET.

Query:

Dim Query = (From t In myEntities.Bookings
Where(t.Ref = Someid)
Select t.People).Sum()

t.Ref field is an Int and so is t.People.

The SomeId value is the primary key of the related table. This issue is that there will not always be records in the Bookings table with a Ref value of Someid - so the query throws the following error.

I have seen others have got around this problem with catching the error, but from reading up on this and as per the error information it seems there should be a solution (in VB.NET) to cast the query or some of the fields in the query to nullable types?

Error is as follows:

The cast to value type 'Int32' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.

View 1 Replies

Asp.net - Declare Return Type Of The Function When There Are Two Possible Returned Types

Jan 25, 2010

I have the following statement, I want to turn it into a Public Shared Function :

If isEmployee Then
Dim employeeInstance As New Employee
employeeInstance = GetEmployeeInstanceByUserId(userId)

[Code]....

Public Shared Function GetWorkerInstance(Byval isEmployee as Boolean) As ...(not sure what to write here)...

There two possible return Type. I'm not sure what I should declare for the function return type.

View 2 Replies

Deep Copy - Is Object Returned By Reference From Function ?

Aug 5, 2011

If I instantiate an object within a function in VB.NET and return it, does it return it be reference or by value. IE - should I be worried about performance if I write something like this:

Public Function ret_obj_func() As big_object
Dim ret_obj As New big_obj(<lots of stuff>)
Return ret_obj
End Function

If I call this function from somewhere else, will it instantiate the object in the ret_obj and then create a deep copy to pass back a copy to the caller, Or will it just pass back a reference?

View 3 Replies

DataGridViewComboBoxCell Not Correctly Displaying Objects Returned By GetValue Function

Jul 14, 2009

I have a Class MessageIndex which holds an integer. I have a custom DataGridViewComboBoxCell which has a MessageIndex variable. If the MessageIndex is not set, the cell acts as a normal DataGridViewComboBoxCell; if the MessageIndex is set, then the GetValue and SetValue methods of the DataGridViewComboBoxCell are overridden so as to return the value of the object from its DataSource at the index of the integer stored in the MessageIndex.

As far as I can tell from stepping through the code, that actually works fine. The object returned by the GetValue function is fetched from the DataSource, based on the integer stored in the MessageIndex.

The problem is that when the DataGridView is displayed, all of the cells are blank. The values of the cells can then be set using the ComboBox dropdown, which appears to work fine.

But why are the initial selections not being displayed? As I say, as far as I can tell, the correct information is being retrieved by the GetValue function of the DataGridViewComboBoxCells when the form is initially displayed. It's just not ending up on the screen.

View 1 Replies

OOP - Declare Two Datatables And Fill Them Both From A Datatable Returned By A Function In Class

Sep 27, 2010

When I declare two datatables and fill them both from a datatable returned by a function in class, that when i filter the one it seems to filter the other aswell?

For example:

I declare the datatable and initiate my class:

Dim DatatableOne As New Datatable
Dim DatatableTwo As New Datatable

Dim MyClass As New MyClass

I then call the function that returns a datatable and apply it to datatable1 and 2 Then fill two DataGrids with the table:

DatatableOne = MyClass.GetTable()
DatatableTwo = MyClass.GetTable()

DatatableOne.DefaultView.RowFilter = "Name = 'Tom'"

[CODE]...

For some reason i don't understand but both grids end up with the filtered data?

View 3 Replies

Time To Call A Function To Change Data Being Returned From Database?

Jun 28, 2009

I have two functions written in VB.NET:

1) The first function (call it GetValues()) returns values in a SQL database as a list via a stored proc. One of the fields is DateTimeSubmitted. All of this data is displayed on my webpage using a repeater control. It works fine.

2) The second function (call it NiceDate()) I created to change the DateTimeSubmitted to a nice date such as "one minute ago" or "yesterday".

My problem is I have no idea which is the best part of the process to do the conversion (at point of data extraction or in pageload etc.) or in fact how to do the conversion.

View 4 Replies

Ado.net - Convert The Ado Recordset To Xml And Returned A String

Jan 26, 2012

In my webservice I have converted the ado recordset to xml and returned a string.In my application I managed to convert it back to the ado recordset but now I need to convert that recordset to dao as I need to use some of the functions provided by dao that ado does not have.

View 1 Replies

Interface And Graphics :: Why Are String Not Being Returned

Oct 15, 2008

Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _

[code]......

View 2 Replies

How To Add String To A Text Box, Returned From Another Form That Has A List Box

Dec 15, 2011

how to add a string item to a text box, returned from another form that has a list box?

I have two forms. on the first form I have a button which calls another form that has a List Box.

When I select the value from the list box and click on the apply button then the value should be

passed to the first form that will also have a text box. The text box should contain the value of

list box.

View 3 Replies

Passing A Value To A Function?

Mar 22, 2011

I have a question concerning some homework. Here is my answer:

Dim intResult As Integer
intResult= Square(4)
lblResult.Text = CStr(intResult)

Now, if I understand functions correctly, this statement should pass the value 4 to:

Function Square( ByVal intValue As Integer ) As Integer
Return intValue^2
End Function

...and assign it's return value to "intResult".

View 6 Replies

Base64 - Decrypt The String Returned Back From SagePay?

Jan 25, 2011

I have been having some problems trying to decrypt the string returned back from SagePay.I used their asp.net kit which included the encrypt and decrypt functions using base64 - sending the information to SagePay is not a problem but I am having a number of problems trying to descrypt the string.Here is the function I am using to descypt:

Private Function base64Decode(ByVal strEncoded As String) As String
Dim iRealLength As Integer
Dim strReturn As String
Dim iBy4 As Integer

[code]....

I don't think the web server is trying to encode anything as there are no + symbols within the url string and I have just glanced over the two to compair they are the same.This returns a blank string whereas when I use the sections commented out in the first loop i get a really weired string back and when I use their simpleXor function it just returns complete nonsense.

View 1 Replies

Passing A Value Of A Function Into A Text Box?

Feb 21, 2010

Private Function Token() As String

Dim Length As Byte
Length = 10
Dim Chars As Char() = New Char() {"a"c, "b"c, "c"c, "d"c, "e"c, "f"c, _

[code]....

is the above bolded line a correct .. it s not working too and the above code is used to generate a random password for users which should be displayed on the text box?

View 3 Replies

Passing Arguments To A Function?

Aug 3, 2011

I am having a problem figuring this out. The text that is bold is where the problem is.

Imports Microsoft.Win32
Console.WriteLine(WMILookup("Win32_Bios","SerialNu mber"))
Private Function WMILookup(ByVal WMIClass as String,ByVal WMIItem as String) As String

[Code].....

View 2 Replies

Passing Double Value To Function

Sep 8, 2010

I have a .aspx webform, with code behind to handle data entered by user, most fields are in double.At business layer, at other class, let say there is a function: [code]I just wondering whether this is the correct way of writing it? And if I have more than 20 fields of double value, then I should declare additional 20 double value?

View 2 Replies

Passing Textbox Value To Function

May 27, 2010

I have a function that search database based on the 2 textbox value. I have a difficulty to call the function and pass the text box value to the function. This is my function: So I get this error:
{"Object reference not set to an instance of an object."}

Function getname(ByVal SearchedName As String, ByVal SearchedFirstName As String) As String
Dim temp As New System.Data.SqlClient.SqlCommand
Dim temp2 = ""
Dim sSQL = " select SearchedName, SearchedFirstName from student where SearchedName =@SearchedName AND SearchedFirstName = @SearchedFirstName"
[Code] .....

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved