VB Function Returning Null?
Apr 3, 2009is it possible for a VB.net function with a return type of integer to return null ?
View 3 Repliesis it possible for a VB.net function with a return type of integer to return null ?
View 3 RepliesI am trying to call an external C++ function using VB.NET (answers in C# are fine, I can convert back) which returns a list of device names. This comes in the form of a pointer to a null-terminated array of null-terminated char arrays (correct me if I've misunderstood what I'm dealing with) with a function signature:
long GetNames(char*** names)
Most of the answers to similar questions I've found have involved something more like:
long GetNames(char** names, int length)
It appears from what I've read that I need to give it an IntPtr but I'm uncertain as to how this should be initialized, and in my case I don't know the length of the array. At the moment, in the VB module, I have:
<DllImport("MyExternal.dll", CallingConvention:=CallingConvention.Cdecl)> _
Function GetNames(ByRef names as IntPtr) As UInteger
End Function
I've tried calling the function by passing an IntPtr initialized as IntPtr.Zero or using Marshall.AllocHGlobal, but I always get an AccessViolationException.
Any ideas on how I should be calling this function and how I get the return value into a managed string array would be greatly appreciated.
EDIT: I've found a sample function call in native C as follows:
char **tmplist;
GetNames(&tmplist)
My brain may just be fried since it's the end of the semester, but my teacher kicked this back to fix and resubmit...she said that I am "returning the name of your function rather than your variable name".
Here is my code for all 3 forms.
code:
These are forms to calculate the cost of getting a cell phone package.
Public Sub checkemail()
sqlcheckemail = "select Email from WEBUSER where Email='" + TBEmail.Text + "'"
Dim dscheckemail As New DataSet
[Code]....
if u see the one that i've commented is the one i already googled at tested...so now if the email address exist in the db..everything works wonderful..but if it doesn't exist the code should process the one that does not satisfy the first if statement...but now i'm getting the result as "There is something" eventhough the email does not exist in the db...
This may seem like a dumb question, but how do you set a default date for the datetimepicker or set today's date as default in the table?
For some reason the control (every instance I've inserted so far) returns a null value when I try to update rows without selecting or entering a specific date while the program is running. The date columns are required, and in at least one case I need the date to automatically return today's date.
In the properties I have chosen "values" for today's date, past dates, even future dates, but I keep getting the following error:
A first chance exception of type 'System.Data.NoNullAllowedException' occurred in System.Data.dll
When I review the details, VS tells me that the date column in question does not allow nulls. If I select a date while running the program, I don't get this error, so it seems like the default value is not getting set.
I have this function correctly linked in an external .js file...
function SubmitAge(age, UpdatePanelID, HiddenAgeID) {
$get(HiddenAgeID).value = age;
__doPostBack(UpdatePanelID);
}
and am calling it like this from an onClick of an a href="#" ... html tag (tags removed, please scroll right as stackoverflow has the greatest difficulty in displaying simple content, 7th display related edit,
[Code]...
Why on earth is HiddenAgeId, clearly passed just like UpdatePanelID, is returning an "Undefined identifier Error"??? its perplexed me to the point where i have no room to move! have i missed something guys?edit: Update: turns out it works perfectly (as it should) when i load it up in FireFox, but has the resulting error in Internet Explorer, this is not a browser compatibility issue, it should also work in IE, but it doesn't!
Having trouble importing a value from a .csv file to a .csv file. This this done because data needs to be massaged and the data file renamed. This is a user interface. Do not want to have the user touch the .csv in any way except upload to the application so the applicaiton can do manipulation. Either way here is the issue.
There is a column in the original .csv file that contains a zip code. The first row of the .csv has a value of 17003 in the zip code column. In the second row of the .csv the zip code column has a value of 11746-9984. The value in the zip code column from the second row always comes back as a Null value. My guess is that the OleDbDataAdapter is defining some kind of Schema. Again, the first row containing the zip code column probably insists the value must be numeric. When the data table field is established it probably gets defined as numeric. If that is true and the second row of the .csv zip code column is not numeric that must cause the zip code value to be Null.[code]...
I am still a newbie with VB. If I return a number the if statement works fine, with opening the new form and updating it as needed. Id the if statement returns a Null from the database it crashes.
[code]...
I have this function correctly linked in an external .js file...
function SubmitAge(age, UpdatePanelID, HiddenAgeID) {
$get(HiddenAgeID).value = age;
__doPostBack(UpdatePanelID);
}
and am calling it like this from an onClick of an a href="#" ... html tag (tags removed, please scroll right as stackoverflow has the greatest difficulty in displaying simple content, 7th display related edit, thanks stackoverflow)
a href="#" onclick="SubmitAge(24, 'ctl00_MainContent_arFrom_upAgeRange', 'MainContent_arFrom_HiddenAge')" runat="server" 24 /a
yet, i am getting this error, and its being called on the first line of the SubmitAge function (line with $get(HiddenAgeID)... etc...)
Error:Microsoft JScript runtime error: 'null' is null or not an object
i've copied and pasted my WATCH windows in visual studio .net (vs2010 beta 2 using vb.net & c#) while the execution breaks inside teh SubmitAge .js function...
age 53 Number
UpdatePanelID "ctl00_MainContent_arTo_upAgeRange" String
HiddenAgeID Undefined identifier Error
Why on earth is HiddenAgeId, clearly passed just like UpdatePanelID, is returning an "Undefined identifier Error"???
edit: Update: turns out it works perfectly (as it should) when i load it up in FireFox, but has the resulting error in Internet Explorer, this is not a browser compatibility issue, it should also work in IE, but it doesn't!
I am finding this weird issue. When I do this > activities.Where(Function(a) (Not a.IsDeleted And a.ParentId = 100) It returns an in-memory query & when I try opening it up, it throws a object not set exception. This only happens when there were no items which satisfied the condition. Shouldn't it be returning an empty set? When there are items satisfying the condition, then it returns a list & works all good.
View 1 RepliesIn my VB.NET application when I try to get the image location using picturebox.ImageLocation (path), it is returning null. I have to use that path string in filestream's parameter to open it. Since it is returning null, I couldn't open the file (image) in filestream. The following error is coming:
"Path cannot be null"
This is my code:
Dim path As String = Picturebox1.ImageLocation
Dim filestrm As FileStream = New FileStream(path, FileMode.Open)
Dim arry(filestrm.Length - 1) As Byte
filestrm.Read(arry, 0, filestrm.Length)
My code seems to behave a way I don't understand. Sometimes it returns null as expected and sometimes it returns a value when its supposed to be null. How can someone explain this? Here is the code that selects from access and displays the result in a messagebox:
cmd5.Connection = cnn
cmd5.CommandText = "SELECT receipt_num " & _
"FROM brought_coffee, farmer where crop_year= " & yr & " and " & _
"brought_date=#" & dtt & "# and farmer_centre='" & ctr & _
[code]....
returning a function value? I have a simple function that returns an integer. This function works fine when executed in SQL Developer but, when called from my apps, it always returns 2 regardless of anything. I have checked it over and over again, I cant seems to find where I am going wrong.
[Code]...
what changes I need to make to the code so that when no value for intPosition is found the textbox txtRoomNumber remains blank? At the moment a value is being entered into the textbox when no value for intPosition is found.
Code:
Private Sub btnFindRoom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindRoom.Click
Dim strRoomType As String
Dim intRoomNumber As Integer
[code].....
Just come across the following snippet:
Public Function Checked() As Boolean
Return applyChange 'this is a string!
End Function
Whats going on here? How can a function with return type Boolean actually return a string? I'm assuming theres some implicit conversion going on here, which I'd rather not have.
I am hopeing someone can help me here with a recursive function I have that is not returning either true or false as I would have espected it to. The function loops through a Active Directory group for its members and then calls itself if it encounters any groups within the membership in order to gets its members as well. I am trying to return either true or false based on if any errors were encountered but not haveing any luck at all. It appears to just hang and never return back to the primary calling sub that starts the recursive function. Below is my code I am using:
[Code]...
If an object is created inside a function and the function returns that type of oject how is the memory handled.
Example:
Public Function GetEmployee(employeeid as integer) as employee
Dim oEmployee as new employee
oEmployee.FirstName="Bob"
[code]....
Does the variable that receive the object still a pointer to the memory location that was used inside the function?What about when you do a oEmployee2=oEmployee.Is oEmployee2 just a pointer? And any changes to oEmployee will now affect the other. Just trying to understand it from a memory perspective and how that scope works?
Function returning different datatype
View 4 RepliesI have stored procedure which I will execute its result and pass it into a Dataset and return it but at the same time I have a Output parameter in my stored procedure which I also want to return, how can I return both the dataset and the integer output value with my function, or is there a more 'appropriate way' to handle such situation?[code]
View 5 RepliesI need to return an array but the array size will change from one call of the function to another so I need away to storing the returned array. The function is as below, and as you can see the returned array will be of different sizes:
[Code]...
Im overiding getRolesForUser() I have 2 columns i return from the query IAdapter.GetRolesByUserName(userName) returns two columns (roleID, formID) How can I return them and access the two columns data? 2 dimensional array?
[Code]....
Is it possible to return more than one value from a function? Like two integers, or an integer and a boolean, or any other data type combination. I understand I could use a sub and set these values in a variable but I was wondering if I could avoid declaring more variables by using a function.
View 28 RepliesFunction test(ByVal res As Integer) As Integer
res = 2
Return res
[code].....
I'm attempting to create a function that will get the User Accounts from the registry. I then need to loop through those users and commit specific actions on each one.Here's my function:
VB .NET
ublic Function UserAccounts() As String
Dim userskey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWAREMicrosoftWindows
[code].....
I've got this MustInherit class called ViewerElement, from which derive classes like ViewerLine, ViewerImage, etc.Then, in the main program I have a collection of different elements (Images, Lines, etc.). What I want to do is something like the following:
[Code]...
I'm getting desperate to implement this Clone method without getting errors. How should this be de done?
Ok simply my code doesnt want to output the correct number. I'm working on the project euler probems to expand my knowledge in VB.net and the current question I am working on is asking to work with triangle numbers. while researching I found that a triangle number can be calculated by using the formula:
[Code]....
How could I call a module or something else to return data to me after its ran. I don't want to make my form1 code all messy.
Public Function Test() As String
Return "Tes34t"
End Function
[code]....
i being ordered to change my function skill to returning value by using struct but not using pointer. may i know what is the pro and con between this 2?
View 1 RepliesI'm having trouble finding out how define this function so I can return the arrayRight now I am defining the returnobject as 'object' but I would like to do it properly.The Function goes something like this:
View 2 RepliesHow do i return a value from a function that i can copy to a queue?I imagine that value must also be a queue.
View 4 Replies