|
Hi,
I want to make an encryptation to a string but the result to be places in a textbox.
I tried the cryptostream class but it work only with stream.
thanks
|
|
|
|
|
You should be able to write out the stream to a byte array and then convert the byte array to a string.
Here are some methods I have used, sorry they are in C# They should be easy to re-write in vb.net
public static String MemoryStreamToString(MemoryStream p_ms)
{
return MemoryStreamToString(p_ms, Encoding.Default);
}
public static String MemoryStreamToString(MemoryStream p_ms, Encoding p_encoding)
{
return ByteArrayToString(p_ms.GetBuffer(), p_encoding);
}
public static MemoryStream StringToMemoryStream(String p_string)
{
return StringToMemoryStream(p_string, Encoding.Default);
}
public static MemoryStream StringToMemoryStream(String p_string, Encoding p_encoding)
{
return new MemoryStream(StringToByteArray(p_string, p_encoding));
}
public static Byte[] StringToByteArray(string p_str)
{
return StringToByteArray(p_str, Encoding.Default);
}
public static Byte[] StringToByteArray(string p_str, Encoding p_encoding)
{
return p_encoding.GetBytes(p_str);
}
public static string ByteArrayToString(byte[] p_byteArray)
{
return ByteArrayToString(p_byteArray, Encoding.Default);
}
public static string ByteArrayToString(byte[] p_byteArray, Encoding p_encoding)
{
int numberOfBytes = p_byteArray.Length;
return p_encoding.GetString(p_byteArray, 0, numberOfBytes);
}
Hope that helps.
Ben
|
|
|
|
|
Hello friends.
Please tell me what the job of function (InstrReverse) and function (Instr)with examples.
Thank you so much.
|
|
|
|
|
<code>
if instr("read the help or google it","google") > 0 then
Success = true
else
PutSomeEffortInBeforePostingOnAForum = true
end if
if InStrReverse exists then
LookItUp = true
else
StopWastingOtherPeoplesTime = true
end if
</code>
-- modified at 9:07 Wednesday 15th August, 2007
You always pass failure on the way to success.
|
|
|
|
|
LOVE IT!
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
|
i need to make a scheduling system for a guesthouse. (9 rooms). i need a way to scroll through the database (Sql 2005) and view room bookings relative to dates and rooms.
Calendar function and rooms thanks!
|
|
|
|
|
Basically, you need to write a database, in SQL, and then you need to write a simple program that displays your information, and calls the database methods. Smells like homework to me.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have a user input form in which user enters some rich text in a rich text box. I store the rtb1.rtf into database. Now all what I need is to concate all input i.e. concate rtf from all rows (in database) but what happens when the output appears the only text from the first row appears. But I need to prepare whole rtf document containing data from all rows. Please help me in this regard and also let me know if the scenario is not clear
Salman Sheikh
|
|
|
|
|
|
Thanx a lot sir but i am using SQL Server 2000 and using text type to store rtf. here comes exactly the same text returned by the Richtextbox control's rtf Property.
Also i couldn't read the complete article you told for i am not registered user of that site.
Salman Sheikh
|
|
|
|
|
hi
have you tried creating an invisible richtextbox and then apppeding the database rows to the richtectbox
sort of
for eachatabase row
RichTextBox1.Rtf = RichTextBox1.rtf + <db rows="" rtf="">
next
then at the end to get the plaintext just do
val = richtextbox1.text
not elegant but will probably work
HTH
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
first of all thanx everybody.
yes i tried the same way you told but this didn't work. the thing actually is that every record contains the rtf document start elements. so i removed it from every record but the first and i removed ending bracket from every record but the last and this worked well..
once again thanx a lot for your kind reply
Salman Sheikh
|
|
|
|
|
I'm writing an app in which a process(the vb .net component) is executed and a progressbar is updated simultaneously thru a do .. while loop . What i want to do is to add a cancel/stop button. In the stop button event code ,i've written code to 'kill' the running process . But when i execute the form ,the stop button (or for that matter any button) is not clickable,when the process and the do-while-loop code are running .Please Advice.
Regards,
Vivek
|
|
|
|
|
|
the control works only for c#,it doesn't work in vb,can u give me example code for creating threads.
|
|
|
|
|
I have come across the same situation you describe and using threads I coded it something like this:
<code>
Public scanInformThread As Threading.Thread
scanInformThread = New Threading.Thread(AddressOf Me.scanInformThreadProc)
scanInformThread.Priority = Threading.ThreadPriority.Lowest
scanInformThread.Start()
While scanInformThread.IsAlive = True
check if cancel button is pressed
if it is pressed then scanInformThreadProc.Abort()
Yadayada Blahblah
make a cuppa coffee
End While
Sub scanInformThreadProc()
Yadayada Blahblah
do something useful like surf the web
end sub
</code>
Please excuse the pseudocode.
Also note that this is not thread safe so you will need to put:
Control.CheckForIllegalCrossThreadCalls = False
at the beginning of your code to stop the compiler from whining at you.
I hope this helps.
Guy
-- modified at 8:02 Wednesday 15th August, 2007
-- modified at 8:06 Wednesday 15th August, 2007
You always pass failure on the way to success.
|
|
|
|
|
hey
you dont need to do the loop . just start the thread and end the function
then on the buttons onclick event do a scanInformThreadProc.Abort()
HTH
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
You're right.
I just hacked this out of my memory.
Regards
Guy
You always pass failure on the way to success.
|
|
|
|
|
thanks , i will try this
|
|
|
|
|
I am using datatable in my application to show the data in gridview.Now what I want is that when user enter a new line application should check the datatable.if the record exists then it should show a warning otherwise add a new row in datatable.
I am using the following code to check the datatable through loop.
Dim x As DataRow
For Each x In mydatatable.Rows
If x.Item(1).ToString = Me.TextBox1.Text Then
Me.Label1.Text = "Exist"
End If
Next
With the above code I am getting error 'Object reference not set to an instance of an object.' at the first row of the for loop
Ejaz
Ejaz
|
|
|
|
|
ejaz_pk wrote: If x.Item(1).ToString = Me.TextBox1.Text Then
I think this line is causing the issue. Does your datatable has column 1?
Mubashir
Software Architect
Storan Technologies Inc, USA
Every job is a self portrait of the person who did it.
|
|
|
|
|
Here is coding for the application
I am getting error message when click on button1_click event
Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Dim MYDT As DataTable
Dim mydatatable As DataTable
Private Function CreateDataTable() As DataTable
mydatatable = New DataTable()
Dim myDataColumn As DataColumn
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "id"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "username"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "firstname"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "lastname"
myDataTable.Columns.Add(myDataColumn)
Return myDataTable
End Function
Private Sub AddDataToTable(ByVal username As String, ByVal firstname As String, ByVal lastname As String, ByVal myTable As DataTable)
Dim row As DataRow
row = myTable.NewRow()
row("id") = Guid.NewGuid().ToString()
row("username") = username
row("firstname") = firstname
row("lastname") = lastname
myTable.Rows.Add(row)
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack = False Then
MYDT = New Data.DataTable()
MYDT = CreateDataTable()
Session("myDatatable") = MYDT
Me.GridView1.DataSource = (CType(Session("myDatatable"), Data.DataTable)).DefaultView
Me.GridView1.DataBind()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.TextBox1.Text.Trim() = "" Then
Me.Label1.Text = "You must fill a username."
Return
Else
Dim x As DataRow
For Each x In mydatatable.Rows
If x.Item(1).ToString = Me.TextBox1.Text Then
Me.Label1.Text = "Exist"
End If
Next
AddDataToTable(Me.TextBox1.Text.Trim(), Me.TextBox2.Text.Trim(), Me.TextBox3.Text.Trim(), CType(Session("myDatatable"), DataTable))
Me.GridView1.DataSource = CType(Session("myDatatable"), DataTable).DefaultView
Me.GridView1.DataBind()
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.Label1.Text = ""
Me.TextBox1.Focus()
End If
End Sub
End Class
-- modified at 5:43 Wednesday 15th August, 2007
|
|
|
|
|
You have several issues here
1 - you're giving all your variables names that obsfucate your code. Give them real names
2 - you need to learn how to use the debugger, you should set a break point or two in your code, and examine your data source to see what's going wrong
3 - you have two datatables as members, called MYDT and myDataTable ( or something ). More bad naming
4 - SQL is what you use to filter a data source. What you're doing is not the right way to go about filtering data.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks Christian for reply. Actually this is my test code and not using in the application. This is my first test by using datatable in asp.net
|
|
|
|