|
It can be hash or something like that, I need to convert a 12 characters long string to 12 characters long string or smaller meaningless one. Thanks for your reply.
|
|
|
|
|
In which case just use some sort of algorithm that is applied to the ascii value of the first character, then use the output from this together with the value of the second character to convert the second character and so on(this way it is a little bit harder to crack the sequence of characters).
To decode it all you need to do is reverse the process starting from the first character again.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Come on! You want to convert *any* string and reduce it to 6 or 8 digits, and then be able to convert it back again?
Well, if you find a way I'll be impressed. Not to mention that we'll be able to zip anything up in just 6 digits..!
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: we'll be able to zip anything up in just 6 digits..
That would be an incredible compression ratio if one could achieve that
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
Maybe someone can help you when you explain What it is that are trying to achieve? Why do you need to generate the 'hash' and translate it back?
|
|
|
|
|
I need to generate a meaningless code that includes last 4 characters of MAC address and a date for example; F28D31122014. Thanks.
|
|
|
|
|
Creating a meaningless code is easy, but it is impossible to regenerate a MAC address from only the last 4 characters.
Still don't understand WHY. WHAT are you trying to accomplish?
|
|
|
|
|
candogu wrote: I need to encode a string to a 6 or 8 digits hash and decode it to original string
That is not possible. And it is proven as well.
Now if you want to take a string or binary data and create another string which will only contain alphanumerics then that is fairly easy. In most cases the second string will be longer than the first. You can look to Base64 encoding to see an example of how you might do this. (Base64 is similar to but not exactly the same as what the output you are asking for is.)
|
|
|
|
|
Hi, I have c# dll and I am using that dll in c++ with the help of COM Interop by importing the corresponding .tlb file in my .cpp file(#import "com.MyIntrop.tlb") and its working absolutely fine but now I want to use same dll in my C code but because I can not use #import in C how to use same dll which I have register as COM assembly in C.
|
|
|
|
|
The .tlb file is typically created by the MIDL.exe from the .idl source file. It has an option to generate .c/.h file to be used by C programs. But since you did not create the .tlb file (I assume it was auto-created by a tool), I don't think you can do much about it.
Here's a workaround. I'm not sure if it will work. You can use OleView.exe to reverse engineer the .tlb to .idl and then use MIDL.exe to compile the .idl back to .tlb with the option to generate .c/.h files. You can then use these files in your C program.
|
|
|
|
|
Another thing you can do is make a C++ DLL that wraps the C# DLL. You would then use the C++ DLL in your C code.
That is what I have done in the past, and it makes the type conversions a lot easier.
|
|
|
|
|
Thanks for the reply. I tried this, I have creted c++ dll anr I have wrapped c# dll in c++ dll but I am not able to load that c++ dll in C code. I used "LoadLibrary" function to load the dll but it didn't work and do we need to have .h file to load c++ dll?
Thank You.
|
|
|
|
|
|
Thanks for the reply. I will tell you why do I need to use c# dll in c, see we have already written code in c which we are going to use across platforms(Windows, windows phone, iphone, android) and from that code written in c we are going to call respective functions of respective platforms to achive Bluetooth communication. Now I have written code for Bluetooth communication in c#(dll) and I want to use it in already written C code. If there is any other way to achieve this apart from using c#(dll) in C code please let me know.
Thank You.
|
|
|
|
|
|
Without even reading through the entire post it looks like you have simply dumped in your assignment notes and are hoping someone will do your work for you.
As the people who volunteer to answer questions here are (mostly) paid professionals who have to work with the graduates of the education system you are trying to wrought, do you think that they will be interested in doing your school work for you.
Do some research, make some attempts to design your solution and show that you are capable of thinking, then come back with specific question where you have attempted to solve the problems.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
Never underestimate the power of stupid things in large numbers
--- Serious Sam
|
|
|
|
|
Quote: We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
I am stealing this from you OG if you dont mind. By the way how are you? where have you been these days?
|
|
|
|
|
if i am use many like more than 50 (if{} else{}) statement use in one form he can reduce my project speed either nothing any hazards my project
please sugest me
|
|
|
|
|
If you provide some code showing what you are trying to accomplish, some one here could perhaps suggest an alternative. Using 50 if..else statements would suggest that there is a design fault.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
50 times the same conditions, just in different places? I.e. something like
if (condition1)
{
}
else if (condition2)
{
}
else
{
}
in many functions/properties?
Then you'd better go for an interface and several implementations of it; perhaps with a base class used by all of the implementations.
|
|
|
|
|
Without understanding the logic of your application ... and why you need so many if-else statements ... without seeing your code ... it's hard to try and help you.
Depending on the context there may be a way to optimize the logic. Whether your particular bunch of if/else statements reduce the performance of your application also depends on the complexity of what is evaluated (and the "cost" of that evaluation) in each if/else clause.
In general, if I see fifty if/else statements, I think code needs re-organizing, re-factoring; but, there's no way to tell if that's true for your code with such limited information.
“There are obvious things, and there are many obvious things no one tried, because no one needed to try them.” Sergey Alexandrovich Kryukov, January 1, 2014
|
|
|
|
|
Thanks sir ,
i ma drop my code i have need to check multiple condition and i want immense my code but many time i have need to wrote one line more time please check
nothing any issue regarding if else statement i am only try to make minimize my code and time if you have time please check
----------------
Dim es As Input.KeyEventArgs
If String.IsNullOrEmpty(txt_pname.Text) Then
comlibobj.msg("Please Enter Name", "Warning")
e.Handled = True
Else
cmd = New SqlCommand("", sqlcn)
cmd.CommandType = CommandType.StoredProcedure
Dim flag As String = ""
Dim schcmd As New SqlCommand("SELECT * FROM mschemst WHERE scode='" + txt_pcode.Text + "'", sqlcn)
Dim schrd As SqlDataReader = schcmd.ExecuteReader
While schrd.Read
Dim sxm As String = schrd("scode")
If sxm.Count > 0 Then
userCh = "Modify"
End If
If txt_schfree1.Text = "0" And txt_schfree2.Text = "0" And txt_schfree3.Text = "0" And txt_schqty1.Text = "0" And txt_schqty1.Text = "0" And txt_schqty2.Text = "0" And txt_schqty3.Text = "0" Then
userCh = "Delete"
End If
End While
schrd.Close()
If txt_batchcode.Text.Count > 0 Then
Batchno = txt_batchcode.Text
Else
Batchno = Batchno
End If
If userCh = "Add New" Then
flag = "A"
ElseIf userCh = "Modify" Then
flag = "M"
ElseIf userCh = "Delete" Then
flag = "D"
End If
batch = ""
batch = DirectCast(cmb_batch.SelectedItem, ComboBoxItem).Content.ToString()
txtsno.Text = Val(comlibobj.cdmaker("", "mschemst", "sno", 9999))
If cmb_batch.Visibility = Windows.Visibility.Visible Then
If cmb_batch.Visibility = Windows.Visibility.Visible And cmb_batch.SelectedIndex = 0 Then
System.Windows.MessageBox.Show("Please Select Batch If use Batch Wise Product And enable Select Bacth")
Else
If cmb_batch.SelectedIndex = 1 Then
cmd = New SqlCommand("SELECT BATCHNO FROM mbachmst WHERE BCODE='" + txt_pcode.Text + "'", sqlcn)
rdr = cmd.ExecuteReader
While rdr.Read
Batchno = rdr("BATCHNO").ToString
txtsno.Text = Val(comlibobj.cdmaker("", "mschemst", "sno", 9999))
Try
cmd.Parameters.AddWithValue("@flag", flag)
cmd.Parameters.AddWithValue("@sno", txtsno.Text)
cmd.Parameters.AddWithValue("@scode", txt_pcode.Text)
cmd.Parameters.AddWithValue("@SBATCHNO", Batchno)
cmd.Parameters.AddWithValue("@sqty1", txt_schqty1.Text)
cmd.Parameters.AddWithValue("@sfree1", txt_schfree1.Text)
cmd.Parameters.AddWithValue("@sqty2", txt_schqty2.Text)
cmd.Parameters.AddWithValue("@sfree2", txt_schfree2.Text)
cmd.Parameters.AddWithValue("@sqty3", txt_schqty3.Text)
cmd.Parameters.AddWithValue("@sfree3", txt_schfree3.Text)
cmd.Parameters.AddWithValue("@sfromdt", comlibobj.Datecheck(txt_sfromdt.Text))
cmd.Parameters.AddWithValue("@senddt", comlibobj.Datecheck(txt_senddt.Text))
cmd.Parameters.AddWithValue("@smes", txt_smes.Text)
cmd.Parameters.AddWithValue("@sminstk", IIf(txt_minstk.Text = 0, 0, txt_minstk.Text))
cmd.ExecuteNonQuery()
Catch agex As Exception
MsgBox(agex.Message)
End Try
cmd.Dispose()
End While
rdr.Close()
Me.Close()
comlibobj.upd()
ElseIf cmb_batch.SelectedIndex = 2 Then
If String.IsNullOrEmpty(txt_batchcode.Text) Then
System.Windows.MessageBox.Show("Batch Cod Field Is blank Please Select Batch")
Else
Try
cmd.Parameters.AddWithValue("@flag", flag)
cmd.Parameters.AddWithValue("@sno", txtsno.Text)
cmd.Parameters.AddWithValue("@scode", txt_pcode.Text)
cmd.Parameters.AddWithValue("@SBATCHNO", Batchno)
cmd.Parameters.AddWithValue("@sqty1", txt_schqty1.Text)
cmd.Parameters.AddWithValue("@sfree1", txt_schfree1.Text)
cmd.Parameters.AddWithValue("@sqty2", txt_schqty2.Text)
cmd.Parameters.AddWithValue("@sfree2", txt_schfree2.Text)
cmd.Parameters.AddWithValue("@sqty3", txt_schqty3.Text)
cmd.Parameters.AddWithValue("@sfree3", txt_schfree3.Text)
cmd.Parameters.AddWithValue("@sfromdt", comlibobj.Datecheck(txt_sfromdt.Text))
cmd.Parameters.AddWithValue("@senddt", comlibobj.Datecheck(txt_senddt.Text))
cmd.Parameters.AddWithValue("@smes", txt_smes.Text)
cmd.Parameters.AddWithValue("@sminstk", IIf(txt_minstk.Text = 0, 0, txt_minstk.Text))
cmd.ExecuteNonQuery()
Catch agex As Exception
MsgBox(agex.Message)
End Try
cmd.Dispose()
Me.Close()
comlibobj.upd()
End If
End If
End If
Else
Try
cmd.Parameters.AddWithValue("@flag", flag)
cmd.Parameters.AddWithValue("@sno", txtsno.Text)
cmd.Parameters.AddWithValue("@scode", txt_pcode.Text)
cmd.Parameters.AddWithValue("@SBATCHNO", Batchno)
cmd.Parameters.AddWithValue("@sqty1", txt_schqty1.Text)
cmd.Parameters.AddWithValue("@sfree1", txt_schfree1.Text)
cmd.Parameters.AddWithValue("@sqty2", txt_schqty2.Text)
cmd.Parameters.AddWithValue("@sfree2", txt_schfree2.Text)
cmd.Parameters.AddWithValue("@sqty3", txt_schqty3.Text)
cmd.Parameters.AddWithValue("@sfree3", txt_schfree3.Text)
cmd.Parameters.AddWithValue("@sfromdt", comlibobj.Datecheck(txt_sfromdt.Text))
cmd.Parameters.AddWithValue("@senddt", comlibobj.Datecheck(txt_senddt.Text))
cmd.Parameters.AddWithValue("@smes", txt_smes.Text)
cmd.Parameters.AddWithValue("@sminstk", IIf(txt_minstk.Text = 0, 0, txt_minstk.Text))
cmd.ExecuteNonQuery()
Catch agex As Exception
MsgBox(agex.Message)
End Try
cmd.Dispose()
Me.Close()
comlibobj.upd()
End If
|
|
|
|
|
Please, if you post code here, use the "code" drop down above the entry textbox to format your code. This preserves the formatting by putting the appropriate <pre> tags round it.
Without tags:
If String.IsNullOrEmpty(txt_batchcode.Text) Then
System.Windows.MessageBox.Show("Batch Cod Field Is blank Please Select Batch")
Else
Try
cmd.Parameters.AddWithValue("@flag", flag)
cmd.Parameters.AddWithValue("@sno", txtsno.Text)
With tags:
If String.IsNullOrEmpty(txt_batchcode.Text) Then
System.Windows.MessageBox.Show("Batch Cod Field Is blank Please Select Batch")
Else
Try
cmd.Parameters.AddWithValue("@flag", flag)
cmd.Parameters.AddWithValue("@sno", txtsno.Text) Which one would you rather read?
And BTW: look at the forum headings! If you want to post VB, then use a VB forum: http://www.codeproject.com/Forums/1646/Visual-Basic.aspx[^] or QA: http://www.codeproject.com/Questions/ask.aspx[^]
Posting VB in a C# forum is like posting dog-fight adverts on a vegan site...
Never underestimate the power of stupid things in large numbers
--- Serious Sam
|
|
|
|
|
As someone mentioned
* put the code indication (< pre> tags) around your code.
* use the VB forum for VB questions
my two cents of your code:
good
* use of parametrized queries
bad
* although you use parametrized queries you also still use string concatenation with user input. Here´s a good article[^]
* UI, businesslogic and DAL component code in one class and probably even within one method .
* three times the same code block...
* I added inline comments for more detailed info.
Dim es As Input.KeyEventArgs
If String.IsNullOrEmpty(txt_pname.Text) Then
comlibobj.msg("Please Enter Name", "Warning")
e.Handled = True
Else
cmd = New SqlCommand("", sqlcn)
cmd.CommandType = CommandType.StoredProcedure
Dim flag As String = ""
Dim schcmd As New SqlCommand("SELECT * FROM mschemst WHERE scode='" + txt_pcode.Text + "'", sqlcn)
Dim schrd As SqlDataReader = schcmd.ExecuteReader
While schrd.Read
Dim sxm As String = schrd("scode")
If sxm.Count > 0 Then
userCh = "Modify"
End If
If txt_schfree1.Text = "0" And txt_schfree2.Text = "0" And txt_schfree3.Text = "0" And txt_schqty1.Text = "0" And txt_schqty1.Text = "0" And txt_schqty2.Text = "0" And txt_schqty3.Text = "0" Then
userCh = "Delete"
End If
End While
schrd.Close()
If txt_batchcode.Text.Count > 0 Then
Batchno = txt_batchcode.Text
Else
Batchno = Batchno
End If
If userCh = "Add New" Then
flag = "A"
ElseIf userCh = "Modify" Then
flag = "M"
ElseIf userCh = "Delete" Then
flag = "D"
End If
batch = ""
batch = DirectCast(cmb_batch.SelectedItem, ComboBoxItem).Content.ToString()
txtsno.Text = Val(comlibobj.cdmaker("", "mschemst", "sno", 9999))
If cmb_batch.Visibility = Windows.Visibility.Visible Then
If cmb_batch.Visibility = Windows.Visibility.Visible And cmb_batch.SelectedIndex = 0 Then
System.Windows.MessageBox.Show("Please Select Batch If use Batch Wise Product And enable Select Bacth")
Else
If cmb_batch.SelectedIndex = 1 Then
cmd = New SqlCommand("SELECT BATCHNO FROM mbachmst WHERE BCODE='" + txt_pcode.Text + "'", sqlcn)
rdr = cmd.ExecuteReader
While rdr.Read
Batchno = rdr("BATCHNO").ToString
txtsno.Text = Val(comlibobj.cdmaker("", "mschemst", "sno", 9999))
Try
cmd.Parameters.AddWithValue("@flag", flag)
cmd.Parameters.AddWithValue("@sno", txtsno.Text)
cmd.Parameters.AddWithValue("@scode", txt_pcode.Text)
cmd.Parameters.AddWithValue("@SBATCHNO", Batchno)
cmd.Parameters.AddWithValue("@sqty1", txt_schqty1.Text)
cmd.Parameters.AddWithValue("@sfree1", txt_schfree1.Text)
cmd.Parameters.AddWithValue("@sqty2", txt_schqty2.Text)
cmd.Parameters.AddWithValue("@sfree2", txt_schfree2.Text)
cmd.Parameters.AddWithValue("@sqty3", txt_schqty3.Text)
cmd.Parameters.AddWithValue("@sfree3", txt_schfree3.Text)
cmd.Parameters.AddWithValue("@sfromdt", comlibobj.Datecheck(txt_sfromdt.Text))
cmd.Parameters.AddWithValue("@senddt", comlibobj.Datecheck(txt_senddt.Text))
cmd.Parameters.AddWithValue("@smes", txt_smes.Text)
cmd.Parameters.AddWithValue("@sminstk", IIf(txt_minstk.Text = 0, 0, txt_minstk.Text))
cmd.ExecuteNonQuery()
Catch agex As Exception
MsgBox(agex.Message)
End Try
cmd.Dispose()
End While
rdr.Close()
Me.Close()
comlibobj.upd()
ElseIf cmb_batch.SelectedIndex = 2 Then
If String.IsNullOrEmpty(txt_batchcode.Text) Then
System.Windows.MessageBox.Show("Batch Cod Field Is blank Please Select Batch")
Else
Try
cmd.Parameters.AddWithValue("@flag", flag)
cmd.Parameters.AddWithValue("@sno", txtsno.Text)
cmd.Parameters.AddWithValue("@scode", txt_pcode.Text)
cmd.Parameters.AddWithValue("@SBATCHNO", Batchno)
cmd.Parameters.AddWithValue("@sqty1", txt_schqty1.Text)
cmd.Parameters.AddWithValue("@sfree1", txt_schfree1.Text)
cmd.Parameters.AddWithValue("@sqty2", txt_schqty2.Text)
cmd.Parameters.AddWithValue("@sfree2", txt_schfree2.Text)
cmd.Parameters.AddWithValue("@sqty3", txt_schqty3.Text)
cmd.Parameters.AddWithValue("@sfree3", txt_schfree3.Text)
cmd.Parameters.AddWithValue("@sfromdt", comlibobj.Datecheck(txt_sfromdt.Text))
cmd.Parameters.AddWithValue("@senddt", comlibobj.Datecheck(txt_senddt.Text))
cmd.Parameters.AddWithValue("@smes", txt_smes.Text)
cmd.Parameters.AddWithValue("@sminstk", IIf(txt_minstk.Text = 0, 0, txt_minstk.Text))
cmd.ExecuteNonQuery()
Catch agex As Exception
MsgBox(agex.Message)
End Try
cmd.Dispose()
Me.Close()
comlibobj.upd()
End If
End If
End If
Else
Try
cmd.Parameters.AddWithValue("@flag", flag)
cmd.Parameters.AddWithValue("@sno", txtsno.Text)
cmd.Parameters.AddWithValue("@scode", txt_pcode.Text)
cmd.Parameters.AddWithValue("@SBATCHNO", Batchno)
cmd.Parameters.AddWithValue("@sqty1", txt_schqty1.Text)
cmd.Parameters.AddWithValue("@sfree1", txt_schfree1.Text)
cmd.Parameters.AddWithValue("@sqty2", txt_schqty2.Text)
cmd.Parameters.AddWithValue("@sfree2", txt_schfree2.Text)
cmd.Parameters.AddWithValue("@sqty3", txt_schqty3.Text)
cmd.Parameters.AddWithValue("@sfree3", txt_schfree3.Text)
cmd.Parameters.AddWithValue("@sfromdt", comlibobj.Datecheck(txt_sfromdt.Text))
cmd.Parameters.AddWithValue("@senddt", comlibobj.Datecheck(txt_senddt.Text))
cmd.Parameters.AddWithValue("@smes", txt_smes.Text)
cmd.Parameters.AddWithValue("@sminstk", IIf(txt_minstk.Text = 0, 0, txt_minstk.Text))
cmd.ExecuteNonQuery()
Catch agex As Exception
MsgBox(agex.Message)
End Try
cmd.Dispose()
Me.Close()
comlibobj.upd()
End If
In short, throw this away and start new, with n-tier development. (use this as base for the logic you tried to achieve)
hope this helps.
|
|
|
|
|