Can a function return a value byref instead of the default byval? That is to say, allow me to directly edit the variable that it is retrieving instead of just giving me a copy of that variable.Right now I'm trying to write a function that will return, based on what the user has selected through a combobox, a particular setting (eg. My.Settings.somethingHere). I then want to be able to edit the setting directly through just calling the function. Is that at all possible?
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?
I'm making this program that opens the same forder in every pc but it identifies the pc name to do it.
Public Class cv7import Private Sub cv7import_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
[Code]...
but I want it to do it with the pc's name and I'm not sure how the environment.systemdirectory works, or even if it's the right one to use. Is it the right thing to use or is there a better solution.
Just as a secondary question, usually I reduce: -(ByVal sender As System.Object, ByVal e As System.EventArgs) to just () for most occurrences of auto-generated subroutines. Is there any harm in doing this? I cant see any reduction in performance but do get more readability.
In Visual Studio 2008 I am using :Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long To stop input from occuring during a search-replace operation.
BlockInput(True) ' do not allow input during search and destroy Dim cursorIcon As Cursor cursorIcon = Cursor Cursor.Current = Cursors.WaitCursor
Then setting it to false at the end of the operation. It did not work, so I thought maybe it was because I was calling it from a child window, so I created a function in the mainwindow, and ran it like this:
FrmMain.BlockFrmMainInput()With these functions is the Main window:
[Code]...
It did not solve the problem. I thought maybe it was because I was running under the debugger, so I tried compiling and running it debugger-free, but that did not do any better. I am still getting input when I double-click the mouse on either form.
I am trying to understand why the two code samples behave differently. I always believed the If() function to mimic the If language feature. Or am I looking at a behavior of Nullable(Of Integer) that is causing this?
Sample #1: If Not String.IsNullOrWhiteSpace(PC.SelectedValue) Then Dim pcFilter1 As Integer? = CInt(PC.SelectedValue) Else
I need top create a function that gets the next integer in the sequence of 1 to 60. Each time the function is called, I need it to increment from what the last value was and return the next number as the result. It also cannot return the same integer in 2 consecutive calls. When the count gets to 60, the sequence needs to reset back to 1. I would like to function to have no parameters.
I have created a function that does this using the cache to store the last value that was returned, but I am worried that with concurrent calls to the function that it might not work as I expect and 2 calls could get the same integer.
Is cache blocking the correct method to use in this instance or is there something other method I am not thinking about?
Also, stuck using .Net 3.5 and this is a web application.
I just wrote this function based on using SyncLock. Any obvious problems with it that I don't see? I am using the Cache to save the last value that was returned.
Private Shared Function GetNextNumber() As Integer Dim o As Integer Dim r As Integer
I am doing a project.."Some Password". the criteria is that the password should have 1 numeric and 1 non numeric and atleast 6 characters. The code I worked on..(below)
Function CheckPass as Integer Dim blnContainNumber As Boolean Dim blnCotainNonNumeric As Boolean [Code] .....
When I compile this code...it gives me a Messagebox error that I wrote.."Password Invalid" even though I type the password that meets the criteria. I think the problem is that I don't have..."if atleast one numeric then" and "if atleast one non numeric then"...
I don't think I fully understand passing values from a sub to a module. Here is what I'm trying to do (problem is at the '****):
[Code]...
I think I've seen something like this before - where the actual function returns a value. Is this possible? Or would I have to pass an integer variable from the sub to the function, and then return it back to the sub?
I'm writing this program to determine deterioration after X amount of years and i keep getting that same error.ive tried redetermining and revaluing variables.
Public Class Form1 Dim Anldep As Double Dim endval As Double
This function doesn't work if I change the input argument 'pdu' from a string to an int.Would someone please help me figure out what to do here so that the checksum does not add the ascii value of the int argument but rather the actual integer value?I took out a few lines of the actual function but it adds the input argument to a packet sent out via TCP protocol.This function shows the integer value just fine in the string that gets encoded as a byte array. the checksum is wrong.!
''Public Function buildpacket(pdu As Integer) is what I want. Public Function buildpacket(pdu As String) Dim packet As String
I am very confuse over a Raise Events example and using delegate as a function pointer: I am clear with this function pointer example program below which creates a generic sort function for sorting integer arrays without changing the main sort function. ' Returns True if need to swap Delegate Function CompareFunc(ByVal x As Integer, _ ByVal y As Integer) _ As Boolean
Here are two alternative target methods for the delegate - one for an ascending sort and one for a descending sort: Function SortAscending(ByVal x As Integer, ByVal y As Integer) As Boolean If y < x Then SortAscending = True End If End Function Function SortDescending(ByVal x As Integer, _ ByVal y As Integer) As Boolean [Code] .....
i'm accessing an access database and want to execute the following query
INSERT INTO sometable (date, field1, field2) SELECT ( ? AS Expr1, field1, field2) FROM othertable
? is a date i generate in code and field1,field2 belong to othertable i put it in a tableadapter and execute it by me.tableadapter.queryname(calculated date) but i get the error : Too many arguments to 'Public Overridable Overloads Function queryname() As Integer' Also if i try to generate the date in the query builder in the form dateserial(year(now),month(now),1-1)the query builder does not accept it?
I'm following this tutorial: [URL]..except I'm connecting to my own data source - a MS Access database.This is the query I have setup with the dataset:
SELECT Terminal_ID, SUM(Transaction_Quantity) AS Total FROM tblTransaction WHERE TransactionType_ID=3 and Transaction_DateTime>[@fromdate] GROUP BY Terminal_ID
The debug fails immediately because it needs the extra parameter so I change the code from:
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'tetrisDataSet.tblTransaction' table. You can move, or remove it, as needed. Me.tblTransactionTableAdapter.Fill(Me.tetrisDataSet.tblTransaction)
[code].....
The error I get on build is:Too many arguments to 'Public Overridable Overloads Function Fill(dataTable As tetrisDataSet.tblTransactionDataTable) As Integer
...I gave it the extra parameter, so what gives? Something special I need to do as it's a datetime field?
I have a project to make a "3x3 magic square" and I'm not quite sure how to begin. A magic square is a 3x3 table of 9 values where the sum of the values along any row, column, or either diagonal all add up to the same value.I have to use listboxes to create a form displaying a table of 3 rows and 3 columns whose elements can be individually updated. The solution should have the following features:
- a procedure that initializes a Listbox to hold the value "?", representing the value "undefined", in each of its locations. The number of locations should be provided as a n additional parameter.
- a procedure that will update the contents of a listbox by replacing the currently highlighted entry with a value provided as a second argument. The program should at most have at most one entry among the listboxes highlighted.
I am trying to use a Function that returns an integer value: -1 if not all the elements on the table contain values, 0 if the rows/columns/diagonals don't sum up to the same value, or the sum common to all the rows columns, and diagonals is returned if everything is alright.The user will enter a 3x3 set of numbers. The program will monitor the status of the table as values are entered and displays the status in a textbox that describes if a magic square currently exists. If not all the entries have been made to the table, then the textbox should display a message indicating so.
I am creating a dll with all the functions and subroutines that I use all the time and I decided to create a function that I can pass different types of array to so the function obviously (or not) would have an array of type object. Now I no you can pass any type into an object type but when I pass an integer array into an object array I get an error.
value of type '1-dimensional array of integer' cannot be converted to '1-dimensional array of object' because 'integer' is not a reference type.
Shared Function CompareArray(ByVal FirstArray() As Object, ByVal SecondArray() As Object, Optional ByRef ErrorMessage As String = "") As Boolean Dim IntArrayOne() As Integer = {1,2,3,4,5} Dim IntArrayTwo() As Integer = {1,2,3,5,6} Dim IsSame As Boolean = False IsSame = CompareArray(IntArrayOne(), IntArrayTwo())
ive got some simple problem i cant understand how to solve.
str(1) is an array and integer(or double, tried both) a(1) is an array and integer (or double, tried both) a(1) = a(1) + 1 Label1.Text = str(1) + a
the big part is where i get: operator '+' is not defined for types 'integer' and '1-dimensional array of integer'.why do i get that message and what does it mean? how do i make the code do what i want?
I'm trying to create a linked list of an array of integers. Why is the following implicit conversion required?
When I run the code that contains that conversion, I get the following error.
As a real-time data acquisition user control data (a packet of an array of bytes) arrives every second, is converted into an integer array and inserted into a linked list.
The most recently arrived data is painted as coordinates on a grid at the right of a PictureBox using Graphics.DrawLine (pen,X1,Y1,X2,Y2).
The oldest data (arriving 120 seconds ago) will be drawn at the leftmost portion of the Picturebox.
Why a linked list rather than a list? To display 120 views of time sequence data, the draw routine the most recently inserted node to a node that points to Nothing. How do I limit the length of the linked list to 120 nodes and always ensure that the last node points to Nothing?
Do While Not item Is Nothing item = item.NextItem Loop
I am a newbie in VB and I got a piece of code which can display the current running program. I need to use that in VB2005 and I got the below error message. Can anyone help how to fix it?[code]