|
Hi all,
I would be really thankful to you all if I could help me to slove my the following problem.
I've written following code to tokenize my string in VB.NET which use " " i.e space as delimiters.
Dim data(100,100) as string
Dim value As String = "&&&&&&&&&&&&&& Tech&&&&&&&&&Repu &&&& blic.com" # Input string where & is a space. I used & as space while posting message since space was ignored while posting message
Dim pattern As String = " " # delimiters
sites = value.Split(pattern)
k = 0
For Each s In sites
If s <> pattern Then
data(0, k) = s
outFile.WriteLine(data(0, k))
k = k + 1
Else
MessageBox.Show(" Space found")
End If
Next s
According to my understanding, the program should ignore the space and assign
data(0,0)=Tech
data(0,1)=Repu
data(0,2)=blic.com
But unfortunately, else part of code is never executed and some spaces are stored on dataarray along with the string.
Can anybody help me to achieve me my goal or any other advise for me?
My Goal is to assign:
data(0,0)=Tech
data(0,1)=Repu
data(0,2)=blic.com
hsprasain
|
|
|
|
|
Because your using spaces as your delimiter it was probably hard to notice but the values that will be contained in 'sites' are not spaces, they are empty strings. Take a look at this code:
Dim value As String = "A,,B,C"
For Each s As String In value.Split(","c)
Console.WriteLine(s)
Next
You'll notice the values returned by the split function are 'A','','B','C' where '' is an empty string. It doesn't return the delimiter. In your loop you should test that the string is not empty.
|
|
|
|
|
Thanks a lot friend!!! I appreciate your help. It works well now.
|
|
|
|
|
Also you could use a regular expression to do the splitting. It will allow you to remove all the white space between values so you only get the actual text. Take a look at this.
Dim value As String = "A B C"
Dim regex As New System.Text.RegularExpressions.Regex("\s+")
For Each s As String In regex.Split(value)
Console.WriteLine(s)
Next
|
|
|
|
|
Hey,
I'm creating a program that can control my media player.
My keyboard has special buttons like play, pause, next, previous and they work with every program.
How can I do this in vb.net?
Greets,
Stijn Janssen
|
|
|
|
|
The same way you would hanld e any other keypress on your form. Enable the KeyPreview property on your form, then in the form's KeyDown event, check for the appropriate key. You can find the list of Keys in the docs for the Keys Enumeration[^] docs.
|
|
|
|
|
Hello,
VS 2005
My program will download files from a server that is on a local network. I would like to monitor the download by using the progress bar.
Currently the files are downloaded using a separate thread. I am just wondering how would I display a progress bar, as the progress bar will be on the UI thread and the files will be downloaded on a separate thread.
The method I use to start my thread to download the files is as follows.
<br />
_updaterThread = New Thread(New ThreadStart(AddressOf _updater.StartUpdater)) <br />
_updaterThread.Start()
I am thinking of having another windows that will popup with the progress bar and monitor the download from there.
So the user will click on a button on the form, this progress bar window will display showing the current download progress.
Many thanks for any code or suggestions to get my going.
Steve
|
|
|
|
|
This might help
http://support.microsoft.com/kb/315577
|
|
|
|
|
First the setup
My Code:
<br />
Imports System.Data.SqlClient<br />
Imports System.Text<br />
Public Class Form1<br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
<br />
Dim myConnection As New SqlConnection()<br />
Dim myDataSet As New DataSet()<br />
Dim myDataAdapter As SqlDataAdapter<br />
Dim myUpdateCommand As SqlCommand<br />
Dim myNewStr As String<br />
<br />
'create connection string<br />
myConnection.ConnectionString ="Server=.;Database=TestDB;UID=steve;pwd=password;Trusted_Connection=yes;"<br />
<br />
'open connection to DB<br />
myConnection.Open()<br />
<br />
'setup data adapter <br />
myDataAdapter = New SqlDataAdapter("select TEXT from SCRIPTS WHERE ID=1", myConnection)<br />
<br />
'Initialize the SqlCommand object that will be used as the DataAdapter's UpdateCommand.<br />
'Note that the WHERE clause uses only the CustId field to locate the record that is to be updated.<br />
myUpdateCommand = New SqlCommand("UPDATE SCRIPTS SET TEXT=@pNewText FROM SCRIPTS WHERE ID =@pMyID", myDataAdapter.SelectCommand.Connection)<br />
<br />
'Create and append the parameters for the Update command.<br />
myUpdateCommand.Parameters.Add(New SqlParameter("@pNewText", SqlDbType.VarChar))<br />
myUpdateCommand.Parameters("@pNewText").SourceVersion = DataRowVersion.Current<br />
myUpdateCommand.Parameters("@pNewText").SourceColumn = "TEXT"<br />
<br />
myUpdateCommand.Parameters.Add(New SqlParameter("@pMyID", SqlDbType.Int))<br />
myUpdateCommand.Parameters("@pMyID").SourceVersion = DataRowVersion.Original<br />
myUpdateCommand.Parameters("@pMyID").SourceColumn = "ID"<br />
<br />
<br />
'Assign the SqlCommand to the UpdateCommand property of the SqlDataAdapter.<br />
myDataAdapter.UpdateCommand = myUpdateCommand<br />
<br />
'call the fill method to populate our dataset<br />
myDataAdapter.Fill(myDataSet, "SCRIPTS")<br />
<br />
'present the current entry in database<br />
MsgBox("Script before updating" + vbCrLf + Encoding.Unicode.GetString(myDataSet.Tables("SCRIPTS").Rows(0)("TEXT")))<br />
<br />
'modify current with replace to update field<br />
myNewStr = Replace(Encoding.Unicode.GetString(myDataSet.Tables("SCRIPTS").Rows(0)("TEXT")), "hello", "steve")<br />
<br />
'now convert our replaced field to a byte array<br />
Dim dBytes As Byte()<br />
dBytes = StrToByteArray(myNewStr)<br />
<br />
'set the dataset table row to our converted byte array<br />
myDataSet.Tables("SCRIPTS").Rows(0)("TEXT") = dBytes<br />
<br />
'call the update method to write back to DB<br />
myDataAdapter.Update(myDataSet, "SCRIPTS")<br />
<br />
'close connection<br />
myConnection.Close()<br />
<br />
End Sub<br />
<br />
Public Shared Function StrToByteArray(ByVal str As String) As Byte()<br />
<br />
'converts string to byte array<br />
Dim encoding As New System.Text.ASCIIEncoding()<br />
Return encoding.GetBytes(str)<br />
<br />
End Function<br />
<br />
End Class<br />
DB SETUP
-----------
Column Name Data Type
ID int (primary key)
TEXT image
DB Records:
ID=1
TEXT =
1040101010801080111033013010010301110111010009801210101033013010083011609701140116033013010010201050110011501050104033013010010401010108010801110330
(
when converted to string is:
hello!
goodbye!
Start!
finsih!
hello!
)
My code works perfect up until the point of the update method
myDataAdapter.Update(myDataSet, "TP_SCRIPTS")
Once I hit this line, i get an error saying :Failed to convert parameter value from a Byte[] to a String.
Help please!
-steve
|
|
|
|
|
svanwass wrote: 'Create and append the parameters for the Update command.
myUpdateCommand.Parameters.Add(New SqlParameter("@pNewText", SqlDbType.VarChar))
You created this parameter as a string, not as a binary type. This is where the error is comming from.
|
|
|
|
|
I am working on a project trying to get my DB and VB.NET skills up to speed. I have established a connection to my database and linked a combobox to the database thusly:
ComboBox1.DataSource = techDataSet.Tables("tblEmployee")
ComboBox1.DisplayMember = "EmployeeName"
However this puts the first record into the "textbox" portion of the ComboBox. I would prefer the ComboBox "textbox" portion to be empty and all the database information be in the dropdown...
Any help would be appreciated.
My goal in life is to be the kind of person my dog thinks I am.
|
|
|
|
|
All you need to do is set the SelectedIndex of the ComboBox = -1. That will take care of it.
|
|
|
|
|
Excellent,thanks.
My goal in life is to be the kind of person my dog thinks I am.
|
|
|
|
|
Hi!
I have this code:
<br />
Dim mailMsg As New MailMessage("webmaster1@myhost.com", "webmaster2@xxxxxxxxx.com", "Test", "Test and Spam")<br />
Dim mysmtp As SmtpClient<br />
mysmtp = New SmtpClient("mail.myhost.com")<br />
<br />
Try<br />
mysmtp.Send(mailMsg)<br />
MessageBox.Show("Sended!", _<br />
"Email Send Status", MessageBoxButtons.OK, _<br />
MessageBoxIcon.Information)<br />
Catch exp As Exception<br />
MessageBox.Show("Error:" & exp.Message, _<br />
Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)<br />
End Try<br />
In Microsoft Visual Studio 2005, VB.NET
How I can use also a username and the passwoed?
Thanks!
My site: www.logicpc.co.il
|
|
|
|
|
I have added one line to your code for username and password
'Your Code
Dim mailMsg As New MailMessage("webmaster1@myhost.com", "webmaster2@xxxxxxxxx.com", "Test", "Test and Spam")
Dim mysmtp As SmtpClient
mysmtp = New SmtpClient("mail.myhost.com")
Try
'Add this code
mysmtp.Credentials = New System.Net.NetworkCredential(username, password)
'
mysmtp.Send(mailMsg)
MessageBox.Show("Sended!", _
"Email Send Status", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Catch exp As Exception
MessageBox.Show("Error:" & exp.Message, _
Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
|
|
|
|
|
Thanks for you! Worked.
My site: www.logicpc.co.il
|
|
|
|
|
i have a table that has no Triggers and all the Fields in my table are nullable and have an Identity Column that is no giving me problem.
am inserting data from my vb.net frontend to my table. sometimes users dont have anything to input, so i want to allow my Adapter to input Null in the dataset when the user has not inserted in data in the text. i used the dragg and drop technique(draging table into the form) here is my SQl statement
<br />
SELECT NUM_KEY, EXTENSION, CELL_ID, ACTUAL_EXTENT, PROP_CATEGORY_ID, LIS_KEY, FUNC_KEY, RATEABLE, GEOCODE, NON_DISCREET_VALID, PROPERTY_ID FROM PROPERTY<br />
i want all this fields to accepts null values in the dataset, because i know that when i run the update function, my table wont complain because all this fields accepts Null values.
Thanks
Vuyiswa
|
|
|
|
|
You should validate your form and avoid null in the DB where-ever possible.
Why do you want null and not an empty string ?
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 )
|
|
|
|
|
Am Sorry to put it that way, i meant Empty string, but the thing sometimes the user might enter something, what if the user does not enter anything?
Vuyiswa
|
|
|
|
|
Then the user has actually entered an empty string. An empty string is entered into the database exactly the same as a string of length greater than 0.
An empty string is most certainly not null.
|
|
|
|
|
Thanks Dave,
i have solved the Problem , by converting everting input from a user to string, if the user enters nothing then, it wil be converted to empty String , and in my table it will be null.i have put this code in the Textchanged event
<br />
<br />
me.Tostring<br />
<br />
Thanks
Vuyiswa
|
|
|
|
|
Vuyiswamb wrote: me.Tostring
Uhhh...Me refers to the instance of the class it appears in. If you used Me inside a Form class, you executed .ToString() on a Form .
|
|
|
|
|
i made a delegate of one sub and sent its method.methodhandle.value to a sub in a VisualFortran Dll.
the sub in VisualFortran creates an interface to work with this sub and calling it from fortran.
this works in vb6 when i send the (addressof sub) to visual fortran but it does not work when the delegate.method.methodhandle.value in vb.net is sent to the fortran dll.
i know intptr is not even a CLS-Comapliant but i recieve the error "protected memory ..."
A.E.K
|
|
|
|
|
Without seeing your code that declares the delegate, the function your calling, and the callback function in your code, it's kind of hard to diagnose. This[^] is about the only thing anyone can recommend.
|
|
|
|
|
This is the code in VB.NET
Private Declare Function dll1 Lib "FileAddress" (ByVal ptr As Integer) as Single<br />
Public Delegate Function del1(ByVal p As Single) As Single<br />
Dim g1 As del1 = AddressOf proc1<br />
Function proc1(ByVal p As Single) As Single<br />
Return p ^ 2<br />
End Function
Here is the function Call(in.Net):
dll1(g1.Method.MethodHandle.Value)
and here the code in VisualFortran:
Real function dll1(F)<br />
!dec$ attributes dllexport ::dll1<br />
!dec$ attributes alias :'dll1'::dll1<br />
<br />
interface <br />
real function F(x)<br />
real x<br />
end<br />
end interface<br />
<br />
end
and I recieve this Error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Notice that i call back a function in .Net from Visual Fortran (not another .Net)
thanx a lot
A.E.K
|
|
|
|