|
Written for console app....
static void Main(string[] args)
{
int[] testvals = { 89, 95, 72, 83, 99, 54, 86, 75, 92, 73, 79, 75, 82, 73 };
int avg = calc_avg(testvals);
Console.WriteLine("The average value is : " + avg);
int var = calc_var(testvals);
Console.WriteLine("The variance is: " + var);
Console.ReadLine();
}
private static int calc_avg(int[] testvals)
{
int tmpSum = 0;
for(int x = 0;x<= testvals.Length - 1;x++)
tmpSum += testvals[x];
return tmpSum / testvals.Length;
}
private static int calc_var(int[] testvals)
{
int[] tmpVal = testvals;
int tmpSqr = 0;
int tmpAdd = 0;
int avg = calc_avg(testvals);
//subtract average from each value
for (int x = 0; x <= testvals.Length - 1; x++)
tmpVal[x] = testvals[x] - avg;
//square each value in tmpVal
for (int x = 0; x <= tmpVal.Length - 1; x++)
{
tmpSqr = tmpVal[x] * tmpVal[x];
tmpVal[x] = tmpSqr;
}
//Add the values up
for (int x = 0; x <= tmpVal.Length - 1; x++)
tmpAdd += tmpVal[x];
//Divide result buy number of elements in testvals
return tmpAdd / testvals.Length;
}
|
|
|
|
|
Congratulations! You just did his homework for him!
Now, he hasn't learned a damn thing and will copy and paste you code into a project, turn it in as his own work, and get a failing grade for it! I hope your proud of yourself!
On top of that, this is the VB.NET Forum, not C++ or C#.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 11:51 Tuesday 25th October, 2005
|
|
|
|
|
Your right Dave I did do his homework and hopefully he will get a failing grade for it to.
The code posted was written as an example. If cut and pasted into his assignment, most likely it will not match the requirements of the assignment. As far as him learning something, it would be a lesson. A lesson that teaches not to copy someone's examples but to study them and learn from the example provided. Books do this all the time, at least the ones I read.
I do appologize for posting in the incorrect forum!
Cheers
|
|
|
|
|
Here's something funny. I dunno how well the code that was posted works, but he's chosen not to use it, he's asked the same question again in the C# forum.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I strongly advise you to either start doing your own homework ( and at least learn to read, this is the VB.NET forum ), or practice saying 'do you want fries with that' in front of the mirror.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I want to create a datagrid having only single row, editable too. because I want to create a filter type application where user can specify text to filter in the grid.
The problem is whenever user write anything in the first row, second row appears automatically, which is not required.
Plz help
|
|
|
|
|
Sounds like you should use a textbox vs. a datagrid.
|
|
|
|
|
Hi
I have to set the name of the file which is to be set for printing. the name is appearing as document(1) in pending documents dialog which is showing in system tray.
When i am watching print preview after that when i press print button from print preview it should dislay print dialog. what is the procedure plz help me.
Thanks in advance.
|
|
|
|
|
set printdocument.documentname property to NAME
|
|
|
|
|
Hi
I want to set the name to a file which is selected for printing. That name should appear in pending documents which is shown in system tray and another thing is i am able to see the print preview. When i am in Print Preview if i press print it should display printer dialog then i can select the printer options.
Plz help me.
|
|
|
|
|
Hi,
I just want to ask.
Do you have any idea how to communivate the ASP with SAM server?
Actually I am doing the smart card programming using VB 6.0. Later on, I =
will create an Active X for the VB programming. But I need to used the =
ASP to run my application. How am I going to connect the ASP with SAM =
server with considering of the session expired?
Thank You.
Regards,
Izyani
yani
|
|
|
|
|
I need to get a list of funtions(names) from a project based on the class modules and forms in the project. How to get this ?
|
|
|
|
|
google vb.net reflection, and you should find what you need.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I have this code below and I want to get the sum of the amount of the "441210" and "441110". Please show me the code. thanks.
Case "441210"
amt = Mid(strLine, 93, [20])
Range("I10").Select
Range("I10").Value = amt
Case "441110"
amt = Mid(strLine, 93, [20])
Range("J10").Select
Range("J10").Value
Range("J10").Value = amt
Thanks
|
|
|
|
|
You're kidding, right ?
Use Convert.ToInt32 to get ints, then use the + operator to add them.
Your code is pretty messy, if you know the values, why are you calling Mid, or is that not what this is doing ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I use Mid function because the value is from my source which is text file and it automatically extract the data from it.
|
|
|
|
|
The Case blocks are separate blocks of code - in other words the case for handling "441210" does NOT drop through to case "41110". What you'll need to do as create a separate variable to hold the sum of these cases viz:
<br />
Dim totalAmt as Integer<br />
totalAmt = 0<br />
<br />
Select Case ....<br />
<br />
Case "441210"<br />
amt = Mid(strLine, 93, [20])<br />
Range("I10").Select<br />
Range("I10").Value = amt<br />
totalAmt = totalAmt + amt<br />
<br />
Case "441110"<br />
amt = Mid(strLine, 93, [20])<br />
Range("J10").Select<br />
Range("J10").Value<br />
Range("J10").Value = amt<br />
totalAmt = totalAmt + amt<br />
<br />
End Select <br />
The variable totalAmt will hold the sum of the two cases and you can then use this in your program.
...Steve
|
|
|
|
|
Hi,
I have my source file containing numbers and link to my excel. There is some cell that the value of the number must be in negative value but in my source, it is in positive value.
Please show me the code on how to convert negative value to positive value, vise versa when it is transferred to my excel template.
More thanks.
|
|
|
|
|
x = -x
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Multiply your value by negative one, this will convert a positive to a negative and a negative to a positive.
x *= -1
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
Hi. Anyone knows which is the name of desktop applications that uses an embedded web ui to interact with the user, like McAfee security center, etc. Any link to a tutorial or article about that kind of applications!?
Thanks in advance...!
|
|
|
|
|
Given that a web UI is limited compared to a Winforms UI, why would you do such a thing ? You can easily simulate a web UI in winforms, seeing as winforms does so much more.
The only reason I can think of to do this is to reuse the UI on the web, and then host IE in your winforms app. I still don't like it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Perhaps you should take a look at HTA. (Search MSDN for it.)
Basically, it allows you to run an HTML file (with embedded java/VB script) just like an app. But like Christian said, it is a more limitted user interface.
|
|
|
|
|
Hi. here is my prob.
I have this treeview under Vb Net that is filling itself at each start fron my database(access) i can add nodes, delete, save, rename, reload, Expand, collaspe up to here it's ok, the problem start here from the same database which has also a table name Products consisting of 7 fields, i whould like when i click on any treenode to be able to fill the listview. I been searching and reading a lot but i am still going nowhere, if someone whould be kind enough to show me or direct me towards a web site or whould have an example that he could share i be most appreciative, in mean time thank you for reading me. Andy38
|
|
|
|
|
Andy,
I think what you need to do is to trap the TreeView's ItemSelectChange event and populate the listview within it.
A sample of code from an old VB 6.0 program shows the method, but you'll need to find the exact name of the event to trap in VB.NET (look at the help for the TreeView class). Note that this example uses slightly different classes but the method is the same.
Hope this helps.
Private Sub tvIDMTreeView_ItemSelectChange(ByVal Item As Object, ByVal ObjType As IDMTreeView.idmObjectType)
'
' Populate the ListView with the database query.
' I did this in a separate Sub but you could place your
' code in here.
'
Call PopulateListView(Item)
End Sub
Private Sub PopulateListView(ByRef oItem As Variant)
lstIDMListView.ClearItems
If Not oItem Is Nothing Then
If TypeOf oItem Is idmobjects.Folder Then
lstIDMListView.AddItems oItem.SubFolders, -1
lstIDMListView.AddItems oItem.GetContents(idmFolderContentDocument), -1
End If
End If
End Sub
...Steve
|
|
|
|