.net - Function That Always Returns The Next Integer In A Sequence
Feb 10, 2012
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 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 working with some VB.Net code that seems to be casting a boolean value to an integer using CInt(myBoolean). The odd thing that is happening is that it returns -1 if the value is true. For example:
CInt(True) // returns -1 CInt(False) // returns 0
Is this common in other languages? I thought that a boolean would be 1 if true and 0 if false. Also, is there a way to make VB assign 1 to true instead of assigning -1?
Then you have to take that same range and find the product of all odd numbers between said sequence. I figured out how to find the product but only if the lowest number is also an odd number. For example, if I put in the values 1 and 7 the product is 105 which is correct. But if I put in 2 and 5 the product somehow becomes 10, when it should be 15.I have to use the MOD function to distinguish between even and odd numbers, which I know how to do however it's still not working out correctly for some reason and I'm completely stuck. This is the part I'm having trouble with. Go down for full source)
For counter = intX To intB intX = intProduct If intY Mod 2 = 0 Then
I am working on networks. My work involves finding out what nodes connected to a specific node (Source node). I have developed a code which does this using a recursive function. The only problem that I have I need to record the path. For example shown in the picture below, my program give me the following results[code]...
I am working on networks. My work involves finding out what nodes connected to a specific node (Source node). I have developed a code which does this using a recursive function. The only problem that I have I need to record the path. For example shown in the picture below, my program give me the following results:
1 Node 3 is conncted to 1 via 1 2 Node 5 is conncted to 1 via 3 3 Node 4 is conncted to 1 via 1
I have to cut down the amount of code in my blackjack program so im trying to use a function however the function always returns a value of 0 I have tried putting in "return cardvalue" but it still comes out as 0 I dont know where I went wrong or if the code im using can even be used as a function.
Function Values(ByVal deal() As Integer, ByVal counter As Integer, ByVal cardvalue As Integer) As Integer If deal(counter) = 1 Or deal(counter) = 2 Or deal(counter) = 3 Or deal(counter) = 4 Then
I wrote a vb program that would prompt the user to enter a number and then enter the exponent value they wanted the number raised to. When they clicked button 3 it did the calculation. everything worked perfectly.
Now I need to change the program. I must create a function in a module and then call that function from button3 click event. I have tried several different ways and even though it seems to "work", it keeps returning an incorrect value![code]...
I have to create dinamcly a Table ( not a DataTable) and I need to write the Functions in other class... so I need to create a function that Returns a Table to make possible I just atribuite the Table to my <asp:Table> control.
I have a function that returns a bitmap meant to be used as background in a panel, and occasionally I'd have to call it to create a new background based on parameters
How can I call individual parts of this function? I would like to call return Gallons and decPaintCostperRoom as individual entities with a single function.
i hav two openfilefialogs(1 and 2). So i also have a listbox. the files opened with the openfiledialogs will be added to the listbox. and when i need to open the files i need to see if they are from which openfiledialog. so
it is like this.
Path.GetDirectoryName(OpenFileDialog1.FileName) & "" & Form3.ListBox1.SelectedItem.ToString 'if this returns a null then go to this Path.GetDirectoryName(OpenFileDialog2.FileName) & "" & Form3.ListBox1.SelectedItem.ToString
So I have a class called Transactions and I put all my functions there. The problem is, when I try to call that specific function and assign it to a variable, there is a "ByRef Argument Type mismatch" error that keeps on bugging me.
Public Function GetUserID(name As String) As Integer Dim gotID As Integer Dim rec As Recordset Call connectDB sSQL = "select ID from User where Name ='" & name & "'" Set rec = CurrentDb.OpenRecordset(sSQL) [Code] ......
I have just received some documentation for an Interface and a class implementation, and I had a question about the return type defined in the interface. here is the function from my interface (I have abbreviated the parameter list in the SearchAddress function).my concern is the SearchAddress function.
Public Interface IAddress Property AddressID As Long Property AddressTypeID As Long
i am trying to write a function which should return a 2D array , please advise what is wrong with.
vb.net Public Function Cursor(ByVal SQL As String, Optional ByVal PARA1 As String = "", _ Optional ByVal PARA2 As String = "") As String(,) Dim Cols, roWES, I, J As Integer
Im making a login system that encrypts and decrypts the username and password. My encryption code is:
Private Shared Function enc(ByVal targetString As String, ByVal maskvalue As String) As String Dim Index As Integer = 0 Dim ReturnValue As String = ""
[code]....
The enc function works for both encrypting and decrypting (I've tested with a MsgBox alert. The problem I'm having is when the program loads, it reads the file and decrypts it. However, instead of properly working, it returns one character in the first textbox and nothingin the other without any error being thrown.
I am working on a project that requires me to hop into to separate DB's. So I have figured that I need to have multiple functions inside of my VB page. The only problem I am having,is I am not to sure how to get this all accomplished. So far I have figured out the overall structure, just need to implement that structure.
Here is my idea: The main Function would call two other functions. We can Call them Sub Function 1 and Sub Function 2. So, the main Function takes the saved sessions information for the E-mail address and dumps in into Sub Function 1. It needs to open up a new connection to the db/stored procedure and RUN the following procedure and then return the result. Here is the stored procedure and what I think is correct.
CREATE PROCEDURE WEB_User (@EMAIL_ADDRESS varchar(80) = [EMAIL_ADDRESS]) AS SELECT MEMBER_NUMBER FROM WEB_LOGIN WHERE EMAIL_ADDRESS = @EMAIL_ADDRESS
So my question is, what is the function suppose to look like? how do I send the session information to the procedure? and finally, how do I return the stored procedure results and push back into the main function so it can be carried into sub function 2?
In our code base there is a function which should return either an object or nothing. The exact code is this : Return NothingThe calling method looks something like thismyObj = theClass.function()if myObj <> nothing then // fails
I call a function (SaveChanges) to access my business / data layer and save any changes to fields that are marked as an Add or Update and are marked to be processed. This function used to work fine up until 60+ minutes ago. What is happening is that suddenly the function is returning false. After debugging through the code, when it hits Return the local boolean is set as True but when it gets back to the calling method (and uses the return value) it is now False. As I said I went through line by line and debugged it, then I added a watch to it. The funny part is that there is one spot that sets the Boolean to false, and when I put a breakpoint on that spot it is never reached.
Here is the function: Private Function SaveChanges() As Boolean Dim blnSaved As Boolean = True Dim saveableRows As List(Of DataRow) = (From d As DataRow In _listData.Tables(0).Rows _ Where Not d("Marking") = "Duplicate" _ And d("Process") = True _ [Code] ....
[VB.Net 2008 Express Edition]I have a 2D array of Integers called Map(0 to 79, 0 to 79)In this array I store IDs for tiles to be loaded later.I'm trying to write a module to generate a random dungeon every time it starts by making a room 10x10 tiles in the middle, picking a wall, making a hallway from that wall, and adding a room to the end of that hallway.From there it picks a random wall anywhere in the map, adds a hallway and a room, and repeats until the number of floor tiles is high enough [400 atm] The problem is that when the rooms and hallways are made, it first runs a function to return whether or not that space is empty. The problem is that even when I know for a fact the space is empty, it returns false. I don't understand why. Here's the Clear function.
Code: Public Function Clear(ByVal Top As Integer, ByVal Left As Integer, ByVal Height As Integer, ByVal Width As Integer) As Boolean 'Returns whether a rectangle is empty 'used to loop through a rectangle of the map array Dim introw As Integer
This same (Identical ) code works well in another program but does not in windows service... Returns 0 for window handle ...?
Public WindowStr As String = "ImagSrvWindow" Protected Overrides Sub OnStart(ByVal args() As String) 'necessary to get control to paint Pic&Txt boxes in stream of Browser navs
Code Block 1 First I am calling my function to obtain a pixel color at a specified coordinate.[code]The odd part is while looking at the results as a string they appear to be the same, but while using If Not TheColor.Equals() in code block 2 the program returns that they are different. Before threading code block 2 this was not a problem so I can only assume the threading is causing the problem. I'm unsure as to how I can fix this... Additional unrelated problems I am having are:
- On WindowsXP the colors being read are not the actual color as which the mouse is located.
- While using print-screen there seems to be a bit of lag and some times unreliability, is there another method to get a pixel color at a specified location? Note that GetForegroundWindow works on Vista/7 but not XP, and GetActiveWindow is unreliable.
I have a several form elements that I am dynamically creating with javascript when a user changes a number value in a textbox, by filling the innerHTML of a div like so:
Then, in the aspx.vb code behind, when the user clicks the Save button, I run through a series of Requests to try and add the values that are in these form elements to a SQL string:
Dim DFTestValue1 As String DFTestValue1 = Request("textbox" & c.ToString)
where c is a loop counter to the # of textboxes created (the input value mentioned above that triggers the create) The problem here is that this code works in Internet Explorer but not in Firefox or Chrome. The Request() value returns null and nothing is saved. I hope I've explained this well enough.
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]...
I am trying to format a Function Code so that it returns a 4 digit result no matter the entry by the user (i.e. they enter 540, stores 0540 in the database). While looking online, I've found the format function, but when I use it, it returns 540, regardless if I enter 540 or 0540. [Code]