|
Heloo i want ro make a radix sort for a ashort project. i want to get the input from the user and also it will be in integer in visual basic
if possible give me guidence .. or send the radix sort code
faisal manzoor
|
|
|
|
|
If you would have Googled for "radix sort"[^], you would have found that the first hit is a good explanation of the algorithm, and contains sample implementations.
---
b { font-weight: normal; }
|
|
|
|
|
How can I do a calculation based on a formula entered via text box? Basically, I'm reading the result of a Analog to Digital Converter reading (ADC_Value)via RS232.
Examples of different formulas that need to be applied:
(LM60 Temperature) Result = 6.25/(ADC_Value - 424)
(LM50 Temperature) Result = 10/(ADC_Value - 500)
(A/D Voltage) Result = ADC_Value/1023 * 5
Basically I'd like to save the different formulas in a Database, each with a short description, and then load these into a combo. Then request the ADC_Value via RS232, take that value and manipulate it according to the combo selection, and display the result.
The reason I don't want to hard code the formulas is that should use a defferent sensor on the A/D Converter, then I would have to manually add this to the application.
Is there some sort of control that can build an expression from a string?
|
|
|
|
|
I don't know of any control that does that in VB.NET but I think you may have answered your own question...
RichardBerry wrote: Basically I'd like to save the different formulas in a Database, each with a short description, and then load these into a combo. Then request the ADC_Value via RS232, take that value and manipulate it according to the combo selection, and display the result.
That shouldn't be too hard.
After doing that you could create your own class that takes those values and performs the calculations. Think of all the variables you'll be using in the calculation and use those as arguments in functions that return the value. Those same varibles could be saved in your database and called, changed, inserted, deleted, whatever.
Just an idea. Or have i misunderstood you?
|
|
|
|
|
Mmm I'm not really understanding you. Take this as an example:
Dim ADC_Value as Integer
Dim Result as Double
Dim TextBoxFormula as String
ADC_Value = GetADC
Lets say the TextBox contains: "6.25/(ADC_Value - 424)"
How can I change the above STRING into an experession that can be evaluated.
i.e. Result = 6.25/(ADC_Value - 424)
Function GetADC() as integer
Code to get ADC Value
Return Value
End Sub
|
|
|
|
|
Ah, I see now. I assumed that the textbox would only hold the value "6.25" and a combobox or another control would hold the ADC_Value (is the 424 a constant?). Then what you would have is something like...
'an event to call the function
Private Sub btnCalc_Click.....
'get the ADC value and add it to a label
Label1.Text = CStr(GetADC(Textbox1.Text, cboADC.Text)
End Sub
'the variables used in this function could be stored in a database
' and called when necessary. the "Value" argument is the 6.25 from the
' textbox.
Public Function GetADC(ByVal Value as Double, ByVal ADC_Value as Double) As Double
Dim dblADC As Double 'variable to return
dblADC = Value * (ADC_Value - 424) 'do the calculation
Return dblADC 'retun the result
End Function
If the 424 is also a variable, it could also be stored in a database and added as an additional argument to your function, or you could create an overloaded function if it's not always required.
Using this kind of method your users won't have to remember the formula as you build it for them. All they'd have to change is the value in the textbox which would make it far more user-friendly. Also, you could then validate in code that the value supplied in the textbox (6.25 in your example) was in fact a valid datatype which will prevent your app from breaking and generally improving it's stability. See where I'm going with this?
At the end of the day tho, it's your project and your clients. I'm only trying to give you another perspective on how to tackle it. From my approach, the class you'd write would be more of a "Formula Engine" which builds the formulae that users would need without them having to remember it, flexible enough to accomodate variations on the formula (using overloads, possibly) but still robust enough that your results are reliable.
There are a couple of ways you could go about this... interesting. Thanks.
|
|
|
|
|
Thanks for your input. I think I've overcomplicated things a bit. If I look at the formulas I'm using:
ADC_Value = (6.25/Temperature) + 424
I read the ADC_Value, and want to calculate the Temperature. But the above equation is a linear equation in the form y= ax + b, so all I really need is two text boxes, one for 'a' and one for 'b', y is the value returned via RS232 and I can solve for 'x' (or Temperature in this case). I can also then add the required validation on the textboxes as you suggest.
|
|
|
|
|
So your problem is solved? yes? no?
|
|
|
|
|
Yes thanks my problem is solved
|
|
|
|
|
|
That's a very interesting article - thanks . A point though, the last paragraph of that article reads
Of course, dynamically generating, compiling, and running code in this way is not a good solution when you need maximum performance. But you will agree with me that the flexibility of this approach could be decisive in a lot of situations.
Considering that Richard's app is getting data through RS232 feeds, he's probably incurring some performance loss already and will most likely want to keep the rest of his app's performance as high as possible. Apart from that, it's really only a simple calculation that needs doing and my personal opinion is that implementing dynamically created and compiled code is going a bit overkill (still is a great article though).
Just an opinion.
|
|
|
|
|
This gives me an error and I've tried changing the values and formats within the brackets.
Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb"<br />
Dim Sql As String = "Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')"<br />
Dim Sql2 As String = "Insert into tblTransaction values()"<br />
Dim conn As New OleDbConnection(strconn)<br />
Dim cmd As New OleDbCommand(Sql, conn)<br />
conn.Open()<br />
cmd.ExecuteNonQuery()
Is this pretty far off how you do an insert statement ?
|
|
|
|
|
have you tried inserting the fields?
"Insert into tblTransaction values(#12/05/06#,1,1,100,'this is it')7"
"Insert into tblTransaction (field1,field2 ....) values(#12/05/06#,1,1,100,'this is it')7"
GUERVEN
Truth or Consequence
|
|
|
|
|
|
|
Also the newrow statement falls over with "null reference" when I code the dataadapter but not when
I add in a dataadapter from the wizard. So what should the sql be here ? or the command so that I can creat a new row ?
Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb"<br />
Dim conn As New OleDbConnection(strConn)<br />
Dim Sql As String = "select * from tblTransaction"<br />
Dim adapter As OleDbDataAdapter<br />
adapter = New OleDbDataAdapter(Sql, conn)<br />
Dim ds As New DataSet<br />
Dim intc As Integer<br />
Dim str As String<br />
intc = adapter.Fill(ds)<br />
' str = ds.Tables(0).Rows(0).Item(4)<br />
Me.Text = str<br />
<br />
<br />
Dim newrow As DataRow = ds.Tables("tblTransaction").NewRow
Please if you can help ?
ml
-- modified at 5:24 Thursday 27th July, 2006
|
|
|
|
|
You didn't tell the DataSet what the name of the tables are. Try: ds.Tables(0).NewRow
|
|
|
|
|
HI.
from the flow of the code I assume you want to fill a datatable and then create a new row from it.
you can directly fill a datatable without using a dataset. Here I replaced some of the code.
With this method, you have a direct access to the dattable.
Dim strConn As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VilliageDatabase\Ainslie.mdb"<br />
Dim conn As New OleDbConnection(strConn)<br />
Dim Sql As String = "select * from tblTransaction"<br />
<br />
<big>Dim TblTrans as new datatable</big><br />
<br />
Dim adapter As OleDbDataAdapter<br />
adapter = New OleDbDataAdapter(Sql, conn)<br />
<br />
conn.open()<br />
<br />
intc = adapter.Fill(<big>TBLtrans</big>)<br />
<br />
Dim newrow As DataRow = <big>TBLtrans.NewRow</big>
furthermore, you can filter the datatable using its defaultview without using an extra dataview.
TblTrans.DefaultView.RowStateFilter=DataViewRowState.Added <br />
Datagrid1.datasource = TBLtrans.defaultview
GUERVEN
Truth or Consequence
|
|
|
|
|
Hi guys,
i'm going to implement one windows project in VB.net,
actually i'm new to vb.net, i decided to use advance controls in vb.net which should more user friendly
could any one tell me about the advanced controls in vb.net 2003
|
|
|
|
|
I have a unbounded grid and 1 of the column...columns style is combobox binded to a table.
I want to handle the selectedvalue change event of the combobox.
How it can be done easily
Please help as i am relatively new to .Net
Thanx
Riyaz Zujer Patanwala
I.T.Programmer
Al Jaber Energy Services
P.O.Box 47467
Abu Dhabi
U.A.E.
|
|
|
|
|
I am looking quite a while to find the source code for copying an entire folder + contents to a target folder.
Can anyone help me?
Because if i dont have that code, the program im working on can't be finished.
Thanks, Zaegra
--Zaegra--
|
|
|
|
|
From MSDN (http://msdn.microsoft.com)
The following example determines whether a specified directory exists, deletes it if it does, and creates it if it does not. This example then moves the directory, creates a file in the directory, and counts the files in the directory.
[Visual Basic]
Imports System
Imports System.IO
Public Class Test
Public Shared Sub Main()
'Specify the directories you want to manipulate.
Dim path As String = "c:\MyDir"
Dim target As String = "c:\TestDir"
Try
' Determine whethers the directory exists.
If Directory.Exists(path) = False Then
' Create the directory.
Directory.CreateDirectory(path)
End If
If Directory.Exists(target) Then
' Delete the target to ensure it is not there.
Directory.Delete(target, True)
End If
' Move the directory.
Directory.Move(path, target)
'Create a file in the directory.
File.CreateText(target + "\myfile.txt")
'Count the files in the target.
Console.WriteLine("The number of files in {0} is {1}", _
target, Directory.GetFiles(target).Length)
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
|
|
|
|
|
Im reading data from a PIC Micro-controller that is sent to the PC via RS232. I read a voltage with the micro, that is returned as a two byte value. The bytes are sent to the PC LSb first, so I need to 'flip' the byte around. Eg: 1011000 I needs to be converted to 0001101. I need to then concatenate the two bytes after they have been reversed, and use this value in a calculation.
At the moment, I receive the data as two bytes, convert them to binary strings (Convert.tostring(byte, 2)), use a for loop to reverse the order of each string byte, concatenate them, and then convert that back to a double to do my calculation
Is there an easier way of doing this?
|
|
|
|
|
Yep - string reverse function.
Assuming you have the string in a label...
'reverse the string in Label1
Label2.Text = StrReverse(Label1.Text)
Simple as. Nifty eh?
|
|
|
|
|