Loop And Increment The Function?

Sep 24, 2011

A common mathematical function is the Factorial function. The factorial function takes an integer input of "n" that is greater than or equal to 1 and computes n* (n-1) * ... * 2 * 1. In mathematical texts, factorial is denoted with an exclamation point, as in n!.For this exercise,write a function called Factorial that takes a single Integer input and returns an Integer corresponding to the factorial of the inputted parameter. To help get you started, your function will look like this:

[code]...

After you have written this Factorial function, add a Page_Load event handler that calls the function, displaying on the ASP.NET web page the values of 1! through 5!.Hint: The Factorial function will need to contain a looping construct from 1 to n, where, at each iteration, a variable is multiplied by the value of the looping variable.Now I'm not asking anyone to solve this for me but rather if you could help me understand how I should go about it. I'm not really understanding how I would loop and increment this function. Would I make the variables 1! through 5! equal to the given values and have them called to the equation and then loop it and increment it as so? I'm not even sure I'm thinking this out correctly.

View 10 Replies


ADVERTISEMENT

C# - For Loop With A Non-integer Increment In .NET?

May 28, 2010

Can a VB.NET For loop be constructed that mimics this C# code?

TimeSpan oneDay = TimeSpan.FromDays(1.0);
for (DateTime d = startDate; d < endDate; d += oneDay) {
// some code
}

Obviously you could do it without a For loop (i.e., with a While); I'm just curious if there's a certain syntax to construct a VB.NET For loop with a non-integer increment that I'm not aware of.

View 1 Replies

Change Increment Variables Causes For Loop To Go Over Limit?

Nov 4, 2010

In my loop I am trying to remove items from a list that have a certain name. I can't do this with a for-each, so I tried a regular for-loop. It seems the for loop is not working as expected. It always goes over the limit. I had to put an if-then to break out of the loop (very ugly solution). I'm trying to find the correct way to accomplish this. [code]...

View 1 Replies

Function To Take Fixed Value And Increment Another Cell

Jun 22, 2010

I am trying to create a function that will take a fixed value, and increment another cell. It does this until another cell using a formula equals the fixed value. You can see what I have below, but this is my first VBA programming ever so I dont know exactly how to declare everything.

Function meetMargin(Margin, calcM, nrc)
Dim x0 As Double, x1 As Double, x2 As Double, t1 As Double
t1 = 0.05
Do While t1 >= 0.01
x0 = Range("Margin").Value
x1 = Range("calcM").Value
[Code] .....

View 1 Replies

VS 2008 Difference Of Sleep Function And Pause Function (using Timer) Between A Loop

Aug 20, 2009

Hi. what is the difference of sleep function and pause function (using timer) between a loop.

View 12 Replies

Use Post Increment And Pre Increment Operators

Mar 17, 2008

Do we have increment operators in VB.Net? I want to use post increment and Pre increment operators in VB.Net.I want touse the statement like, i++ and ++i.

View 5 Replies

Use A While Loop And MID$ Function Instead Of The Split Function?

Dec 30, 2011

How do i use a while loop and MID$ function instead of the split function?

i'm trying to have the input (textbox) compared to a list(array) in a text document

View 6 Replies

Performance Of Function Using For Next Loop

Jul 12, 2011

I am calculating the average of an array(double) using a known (smaller) array of integers, which contains the indices for the larger array to give the values for the average. Below is the function:

'
'NumLoops = Ubound(LookupList)+1 !
' i always >0
Function Mean(ByRef Y() As Double, ByRef LookupList() As Integer, ByVal NumLoops As Integer) As Double
Dim res As Double
[Code] .....

Stand alone performance (through a win32 project) form is very good for my project. e.g. a Y() = 50000 entries, LookupList=1000 entries, calculating the mean 1000 times take about 5 ms.

That beats a c++ function accessed through a rcw quite easily (takes >300ms). However, when I plumb this function into a larger project the performance drops off significantly, taking (typically) 50ms for the same test. Also if (say) I make Y bigger (say, 100 000 elements) with everything else the same I see a tiny overhead in the stand alone test (of order 1 ms), yet I see a close to linear increase in the calculation time in the larger project. The larger project is not so big (a few MB) as to make we worry about resource constraints.

View 5 Replies

Use Loop And MID Function To Reverse A Name?

Feb 21, 2012

I am fairly new to VB and I am struggling with not using the Reverse string.I need to take a persons name from a text box and print the name backwards in a label using lop and the MID function.I have this, but it doesn't use the MID Function, how would I change it.

Private Sub convertButton_Click(sender As System.Object, e As System.EventArgs) Handles convertButton.Click, ClearToolStripMenuItem.Click
Dim Name As String = ""

[code].....

View 17 Replies

Calling A Random Function In A For Loop?

Apr 9, 2012

I have a random function and a for loop which sets those random numbers to an integer

For i As Integer = 1 To 4
nums(i) = Randomfunc(0, 100)
Next

[code].....

View 5 Replies

Read Hex At The Same Time Loop The Function?

Oct 29, 2011

I'm a newbie in VB.. I'm editing a file that sets the click-able area of a button in a game.

[Code]....

View 6 Replies

VS 2008 Private Function With A Loop?

Aug 20, 2009

i made this code

VB.NET
Dim iString As String
If My.Settings.IPBank.Count = 30 Then
MsgBox("You alredy have the maximum amount of IP Addresses stored, delete one to add another.", MsgBoxStyle.Information, "Program Error")

[Code]...

I want it to check all of the items in the my.settings.ipbank which is a stringcollection. Before it adds and if it already exists in my.settings.ipbank then i want it not to add it. But it just adds when i run it. And then once its added it says: "Collection was modified; enumeration operation may not execute." But also before i run it. There is a warning saying: Function 'AddTo_IPBank' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. Is this something to do with it? I think i have the Next in the wrong place .

View 4 Replies

Loop Function - Iteration Not Working As Intended

Jan 18, 2012

I'm using a DO interation to loop a function I'm using to test for internet connectivity. The code is working fine, except that when one of the tests is satisfied the loop stops. I want this to continue in the background while the program is running. How can I get this to work?

Private Sub checkInternet()
Dim InetChecker As Boolean
InetChecker = CheckForInternetConnection()
Do While LabelCount.Text <> ""
Thread.Sleep(10)
[Code] .....

View 3 Replies

Stalling A Loop While Waiting For A Function To Complete?

Dec 18, 2011

I'm looping through items in a listview. For each item, it deletes a file containing information stored and re-writes it with new information from the listview item.

View 5 Replies

VS 2005 Nested Loop Vs Recursive Function?

Aug 18, 2010

I'm trying to make a simple game tree.Previously I used nested loops:

[Code]...

View 10 Replies

An Infinite Loop In A Recursive DirInfo.GeDirectories Function?

Oct 25, 2010

I am descending all the directories of my C drive to get a complete list of all extensions.When I get to: C:Windows.oldDocuments and SettingsAll UsersApplication Data

the program goes into a loop: C:Windows.oldDocuments and SettingsAll UsersApplication Data Application Data Application Data until the path exceeds maximum length (248 characters for the directory).

[Code]...

View 3 Replies

Saving Items In A Collection To A Database Using A Loop Function?

May 12, 2011

I would like to be able to save to a db and send task to email or as text msg for instance nevermind that.. I have two variables of type ArrayList they are "_mList1" , "_mList2" and "_mList3"

_mList1 stores the list of Telephonenumbers , _mList2 stores the list of StaffIDs and _mList3 Some concatenated string.

theses variable lists will hold some data in runtime as explained and i would like to use them to populate a DB table again mentioned

tblTask (TaskID(PK), Action, StaffID(FK), AssignedBy, TelephoneContacted, NotesCotent)
tblStaff (StaffID(PK), FirstName, Surname, Telephone, Address etc..)

[Code]....

View 1 Replies

Use The Timer_Tick Function, To Loop A Data Read From A COM Port?

Jul 2, 2011

I should use the Timer_Tick function, to loop a data read from a COM port. The object i call uses a method that closes the thread after a fixed timeout.

obj.Read(N byte) //--> if no data come within 500ms close the thread

My question is: considering that the Timer_Tick function will be called every (for example) 100ms, How long does the total execution last? Timer_tick time + Thread Timeout (100ms + 500 ms = 600ms) or just the Timer_Tick time (100ms) causing the anticipated thread closure/crash?

View 7 Replies

VS 2005 Function Loop - Each Distance Calculation Is Being Obliterated

Feb 20, 2011

I am using the following code to get distance between two propertys. The problem i am having is each Distance Calculation is being obliterated and I am only geting back the last Calculation instead of each calculation/distance

[Code]...

View 4 Replies

Sqlite - Loop Through Selected Records And Pass Each Record As A Parameter To Another Function?

Jun 5, 2010

I have a sqlite table with following fields:

Langauge level hours
German 2 50
French 3 40
English 1 60

[code]....

I want to loop through the records based on language and other conditions and then pass the current selected record to a different function.So I have the following mixture of actual code and psudo code. I need help with converting the psudo code to actual code, please. I am finding it difficult to do so.

Here is what I have:

Private sub mainp()
Dim oslcConnection As New SQLite.SQLiteConnection
Dim oslcCommand As SQLite.SQLiteCommand
Dim langs() As String = {"German", "French", "English"}

[code]....

View 3 Replies

Evaluates Loop Condition In Do...Loop Statment To Determine Whether Loop Instructions Should Be Processed

Mar 14, 2011

Makes the following statement about the code below:

**"The computer evaluates the loop condition in the Do...Loop statment to determine whether the loop instructions should be processed. In this case, the inputsales <> String.Empty condition compares the contenst of the input sales variable to the String.Empty value. As you know the String.Empty value represents a zero length, or empty, string if the inputsales variable is empty, the loop condition evaluates to True and the computer process the loop instructions. *If on the other hand the inputsales variable is not empty, the loop condition evaluates to false and the computer skips over the loop instructions.

Based on the code I think it is the opposite: ...that while the inputsales value is not empty it should evaluate to true and process the loop and if it is empty it should evaluate to false and skip the loop?

See below.

Option Explicit On
Option Strict On

Imports System.Globalization

[CODE]...

View 2 Replies

Create A (in Excel ) Variable Table (database) Inside A Function Which Could Be Called For Filling And Reading Through "for To Next" Loop Module?

Feb 4, 2012

i just got 1 question how do u create a (in excel ) variable table (database) inside a function which could be called for filling and reading through "for to next" loop module

View 2 Replies

How To Pass A Function To A Function Is Functors/function Objects Avaiable In VB2010

Oct 12, 2011

I want to make an numerical integration method with takes in an analytic function and integrate it over a specific interval. For the numerical integration procedure I want to use some procedures in nr.com. The problem is that these are programmed in C++ and they uses functors to pass a function to the integration method. How can I do this in VB 2010?

I want to initialize the function (i.e. set a=1,b=0 for function y(x)=a*x+b) and then pass the function to the integration method. Then when the integration method call the function it only calls the function with one parameter (i.e. x since a,b is already set)

What is the best way to do this in VB2010?I want to make a general integration method where I can pass any single valued function and integration limits.

I have just started using VB, and from what I have found so far it seems like the tools you have is

- to us a delegate for the function
- to use a lambda expression for the function
- send a pointer/adressOf
- to create a function class/structure and submit this to the function

As for now I am most inclined to create a function-class. But I am not really sure how.F.ex. I make different classes for each "uniqe function" I want to integrate, but how can I pass them to the integration function when I need to specify the argument type in the integration-function-call?This seems like a basic problem which applies to many Math operations, so I think it would be very useful to clarify this.

View 2 Replies

C# - No Increment Operator In .net?

Jun 14, 2011

came across this issue while converting a for loop in C# to VB.net I realized that the increment operators are not available in vb.net (++ and --)whereas i was able it do something like cnt +=1 .In VB, a STATEMENT cannot be just an EXPRESSION. why this doesn't work in the same way as it does in C#.

View 4 Replies

Code An Increment Of 1?

Nov 16, 2011

What code do I have to program to make this possible:

If Button1 is clicked, the number in Label1 increases by 1.

If Button2 is clicked, the number in Label2 increases by 1.

I don't want it to start off at 0. I don't want there to be any text in Label1 and Label2 at the start of the program.

View 6 Replies

How To Increment Scores

Apr 10, 2011

I want it to increment by 1.I have this code from net but I found hard to understand the first line :

If Decimal.TryParse(TextBox1.Text, userAnswer) Then
If answer = userAnswer Then
score += 1
TextBox2.Text = score

[code]....

View 7 Replies

Increment A Date By 1 Day ?

Apr 14, 2011

If I have a textbox1 and button1, where in textbox1 the date will display as 01-Apr-2011, I want to click on button and have the date in textbox1 increase by 1 day.So, if textbox1s date is 01-Apr-2011 then in textbox1 after clicking the button, textbox1s date will be 02-Apr-2011, a further click will get 03-Apr-2011 and so on.How do I do this using VB.NET?

View 3 Replies

Increment A Row In A Datagrid?

Aug 25, 2009

I am trying to use a datagrid in the absence of a basic grid control. I need to be able to increment the rows. i tried[code]...

View 1 Replies

Increment A Value Automatically?

Jun 20, 2012

im doing a project like now a simple. how can i increment a value automatically im using an ms access.

my data type for that is a number i have a ID no. Field and when i add a record i want to automatically add a ID no. after i add a record the ID no. will become this 12-001 and add another one the id no. will automatically become 12-002 i have no textbox in the form.

View 2 Replies

Increment A Value By 1 Between The Rows?

May 4, 2009

Can any body send me the code for incrementing a value by 1 between the rows Ex: I have 3 columns say ID,Date,PO_NO

ID DATE PO_NO
1 getdate() 112
1 getdate() 113
1 getdate() 114

[code]...

View 1 Replies







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