|
Hello,
You have not mentioned the format of the data in the text file. Is the data in the form of
tab/comma separated values or simple text lines. If you wish to display all the lines in a text
box as separate items in the Listbox, then you can use the given code. This uses the Stream Reader
object to read the lines into the Listbox. You have to import the file System.IO.
Dim stream As New StreamReader(<filename path="">)
Dim str As String
While Not stream.EndOfStream
str = stream.ReadLine
ListBox1.Items.Add(str)
End While
I am unable to understand your second requirement. Can you explain it more.
Regards,
Allen Smith
Software Engineer
ComponentOne LLC
www.componentone.com
|
|
|
|
|
Thanks Allen for the help. The 2nd requirement is that currently when I click add the data appears in the listbox like this:
1223
Joe Smith
Manager
Some Address
SSN
I want it to input like this:
1223 Joe Smith Manager Some Address SSN
|
|
|
|
|
Hello,
In this case, what you can do is concat each of the textbox values in a string object and then
add them in the Listbox. For example, you input all the above values separately from TextBox1 to
Textbox5. Now on button click, you can use the following code.
Dim str As String = ""
str = str & " " & TextBox1.Text & " " & TextBox2.Text & " " & TextBox3.Text & " " & TextBox4.Text & " " & TextBox5.Text
ListBox1.Items.Add(str)
I believe this should resolve your issue.
Regards,
Allen Smith
Software Engineer
ComponentOne LLC
www.componentone.com
|
|
|
|
|
Thanks Allen for the help. Now that sent that to me it seems so easy that I should ahve gotten it.
|
|
|
|
|
hi,i have made an application in C# and vb.net,it working fine in C#, now when converting for C# to vb.net there is situation in which i have to call thread with 2 parameters, in C# i have used anyomous method here is code of that
ThreadStart st = delegate { ParseURL(strURL, this); };<br />
Thread th = new Thread(new ThreadStart(st));<br />
th.Start();
i am trying to convert that code in vb.net but it did not work
dim st as ThreadStart = delegate( ParseURL(strURL, Me))
Dim th As New Thread(New ThreadStart(AddressOf ParseURL))
th.start()
then i used but i accept only one parameter not 2 parameters.
<br />
Dim th As New Thread(New ParameterizedThreadStart(AddressOf ParseURL))<br />
th.IsBackground = True<br />
th.Start(strURL)<br />
plz tell me how to pass 2 parameters to thread in vb.net
Regards.
Tasleem Arif
|
|
|
|
|
The C# code actually doesn't send any argument at all when starting the thread. The values are put in the delegate object instead.
As anonymous methods are not available in VB.NET, you can't use this trick, so you have to use a different one.
Create a class that has two member variables and a method (or add them to an existing class). Create an instance of the class and put the values in the variables and use the method to start the thread. That way the method has access to the values.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
In VB6 i used to start my project from a Sub Main() which resided in a module.
This codei n sub main then initialised many things and called various forms, ie splash screen and so on.
However i cannot get the VB.NET windows application to start in this way. The property settings require that the start up be a form, unless i use a different app type (ie console app or other).
I'm new to VB.NET so would appreciate any best practice advise on this matter and how other developers are currently handling this.
Many Thanks
|
|
|
|
|
Every Class has a constructor and If you don't create one .NET will create one for you. As form is also a Class so it has its own Constructor it calls whenever we create an object of it so the best place to initialize things is the Constructor and in VB.NET its name is 'New' you can find the Constructor of your form inside 'Windows Form Generated Code'.
For Example:
Sub New
'Initialize Code here
End Sub
Hope it helps !
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
I'm having difficulty finding the windows generated code. I can see the code from the forms designer but that does not contain the constructor.
|
|
|
|
|
When you click on the '+' sign besides "Windows Form Designer generated code" means when you expand it you'll see the code e.g.
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'Your code goes here....
End Sub
I think you should buy a book because It'll really help you to clear your concepts !
hope it helps !
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
AliAmjad
Thanks, i do have a book and have seen the code you mention before. But for some reason it is not in my current form.
When i select 'show all files' im the solution explorer, a plus sign appears next to my form which, if expanded, show me a Form.Designer.vb file and a Form.resx file.
I can see some code with 'Mybase.Disposing' in the Form.Designer.vb file but cannot find the form constructor anywhere.
I can create a constructor, with the same code as your comment and the IDE doesn't complain, but i would like to know why it is'nt there in the first place.
I have also tried adding in another form, just in case the code was accidentily deleted but this was the same.
|
|
|
|
|
first create a Start up module I alway call it mMain and than create the Main() sub.
than from the project menu select properties then from the application tab select the
startup object as sub Main()
in sub Main you should put the following code at the end:
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(MainFrm)
|
|
|
|
|
When i uncheck the 'Enable application framework' though what implication does this have?
|
|
|
|
|
Hi everybody,
I'm having some problems to code something. I want to execute a function stored in a "string". I think that is easiest to understand with an example:
Public Function GetCurrentValue() As Integer<br />
Return 67688<br />
End Function<br />
<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim methodName As String = "GetCurrentValue"<br />
Dim result As Integer<br />
result = ExecuteFunction(methodName)<br />
End Sub<br />
The result value should have 67688. Anybody knows how can code the "ExecuteFunction" function?
Thank you everybody
Regards,
JosBerb
|
|
|
|
|
You in need of using Delegates as they are safe type function pointers here's how to use it:
Delegate Function DelFunc() As Integer
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim InvDelfunc As New DelFunc(AddressOf MyFunction)
Dim result As Integer = InvDelfunc.Invoke()
MsgBox(result)
End Sub
Function MyFunction() As Integer
Return 8786
End Function
Hope it helps !
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
Thank you for your answer but the problem with delegates is that only know the name of the function in execution time.
The reflection mode works properly.
Regards,
JosBerb
|
|
|
|
|
|
nlarson11 wrote: research reflection
Thank you a lot for your answer.
The reflection was a perfect solution for my problem.
Regards,
JosBerb
|
|
|
|
|
Hello,
I have a requirement where I need to use Encryption/Decryption in ASP and ASP.NET application visa versa.
I have used a Blowfish .NET dll and tried to use it but on Windows 2003 SERVER backward compatibility fails.
Please help to get a VB code through which I can encrypt and decrypt a string using a Key.
Regards,
Pavas
-----------------------
[http://longjump.com/]
Dynamic business applications that manage and coordinate teams and information
-----------------------
|
|
|
|
|
You should look at System.Security.Cryptography Namespace which contains a bunch of classes use one which suits your need.
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
This is very simple but it works!
Public Class CL_EnCrypt
Private sPsw As String = "XAN4519CEAN4719"
Private sBox(255) As String
Private sKey(255) As String
Public Property Password() As String
Get
Return sPsw
End Get
Set(ByVal sVal As String)
sPsw = sVal
End Set
End Property
Public Function DeCrypt(ByVal sWord As String) As String
If sPsw = "" Then
MsgBox("Error you must set a password first.", MsgBoxStyle.Information, "Password not set")
Return ""
End If
Return EnDeCrypt(sWord)
End Function
Public Function EnCrypt(ByVal sWord As String) As String
If sPsw = "" Then
MsgBox("Error you must set a password first.", MsgBoxStyle.Information, "Password not set")
Return ""
End If
Return EnDeCrypt(sWord)
End Function
Private Sub RC4Initialize()
Dim sSwap As String = ""
Dim A, B As Integer
Try
For A = 0 To 255
sKey(A) = Asc(Mid$(sPsw, (A Mod sPsw.Length) + 1, 1))
sBox(A) = A
Next
B = 0
For A = 0 To 255
B = (B + sBox(A) + sKey(A)) Mod 256
sSwap = sBox(A)
sBox(A) = sBox(B)
sBox(B) = sSwap
Next
Catch ex As Exception
MessageBox.Show("Encription Error - " + ex.Message, "Encription Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Function EnDeCrypt(ByVal sPlainTxt As String) As String
'This routine does all the work. Call it both to ENcrypt and to DEcrypt your data.
Dim A, I, J, K As Integer
Dim sCipherBy, sCipher, sTemp As String
Try
sCipherBy = ""
sCipher = ""
sTemp = ""
I = 0
J = 0
RC4Initialize()
For A = 1 To sPlainTxt.Length
I = (I + 1) Mod 256
J = (J + sBox(I)) Mod 256
sTemp = sBox(I)
sBox(I) = sBox(J)
sBox(J) = sTemp
K = sBox((sBox(I) + sBox(J)) Mod 256)
sCipherBy = Asc(Mid$(sPlainTxt, A, 1)) Xor K
sCipher = sCipher + Chr(sCipherBy)
Next
Return sCipher
Catch ex As Exception
MessageBox.Show("Encription Error - " + ex.Message, "Encription Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return ""
End Try
End Function
End Class
|
|
|
|
|
Thanks for the reply,
But I need to use the code in VB and .NET so it should work on both ASP and ASP.NET.
Hence I am looking for a code that is in VB and it has forward compatability.
Backward compatability gives issue in Windows 2003 server. So i want some tuhing with forward compatability
Regards,
Pavas
-----------------------
[http://longjump.com/]
Dynamic business applications that manage and coordinate teams and information
-----------------------
|
|
|
|
|
Below is an encryption/decryption class I have written and use.
To Encrypt, pass the the encrypt method the text to encrypt and an encryption key. As a result a string is returned with the encrypted text.
To decrypt pass the encrypted text to the decrypt method along with the original encrytion key and as a result you should now have the original text returned by the method.
Public Class Cryptography<br />
<br />
Public Shared Function Encrypt(ByVal Text As String, ByVal Key As String) As String<br />
Dim sEncrypted As String = ""<br />
Dim iKey As Integer = 0<br />
If Key.Trim.Length = 0 Then Throw New Exception("An encryption key is required")<br />
<br />
For iChar As Integer = 0 To Text.Trim.Length - 1<br />
Dim iTextChar As Integer = Asc(Text.Substring(iChar, 1))<br />
Dim iKeyChar As Integer = Asc(Key.Substring(iKey, 1))<br />
Dim iCharacterIndex As Integer = iTextChar + iKeyChar + iChar<br />
<br />
While iCharacterIndex > 255<br />
iCharacterIndex = iCharacterIndex - 255<br />
End While<br />
<br />
sEncrypted &= Chr(iCharacterIndex)<br />
iKey += 1<br />
If iKey > (Key.Trim.Length - 1) Then iKey = 0<br />
Next<br />
Return sEncrypted<br />
<br />
End Function<br />
<br />
Public Shared Function Decrypt(ByVal EncryptedText As String, ByVal Key As String) As String<br />
Dim sDecrypted As String = ""<br />
Dim iKey As Integer = 0<br />
If Key.Trim.Length = 0 Then Throw New Exception("An encryption key is required")<br />
<br />
For iChar As Integer = 0 To EncryptedText.Trim.Length - 1<br />
Dim iTextChar As Integer = Asc(EncryptedText.Substring(iChar, 1))<br />
Dim iKeyChar As Integer = Asc(Key.Substring(iKey, 1))<br />
Dim iCharacterIndex As Integer = iTextChar - iKeyChar - iChar<br />
<br />
While iCharacterIndex < 1<br />
iCharacterIndex = iCharacterIndex + 255<br />
End While<br />
<br />
sDecrypted &= Chr(iCharacterIndex)<br />
iKey += 1<br />
If iKey > (Key.Trim.Length - 1) Then iKey = 0<br />
Next<br />
Return sDecrypted<br />
<br />
End Function<br />
<br />
End Class
Regards
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
Hi Steve,
I strongly recommend you take a look at the System.Security.Cryptography namespace. "Homebrew" cryptographic algorithms are almost never secure, and are often vulnerable to the most trivial of cryptanalysis.
If you need to protect data then pick a reputable algorithm.
|
|
|
|
|
is it possible to use a WebBrowser control to open an existing web page and populate the text controls on the web page from VB.NET code? NOTE: the web page could be any existing page. For example www.google.com. Browse to Google and put some search text into the text control and press the Search button.
mcnewsxp
|
|
|
|