Hey anyone can tell me how can i delete the first 6 letters from a line in any TextBox???
Plz Can u tell me i need help
Printable View
Hey anyone can tell me how can i delete the first 6 letters from a line in any TextBox???
Plz Can u tell me i need help
vb Code:
If TextBox1.Text.Length > 6 Then TextBox1.Text = TextBox1.Text.Substring(6, TextBox1.Text.Length - 6) End If
Or
vb Code:
If TextBox1.Text.Length > 6 Then TextBox1.Text = TextBox1.Text.Substring(6, TextBox1.Text.Length - 6)
thanks for ur fast reply but when i tried i got this error Index and length must refer to a location within the string. Parameter name: length
That implies that your string isn't at least 6 characters long.
Well that ill be because if the TextBox doesn't have more than 6 characters it will not work as when I began to learn VB I asked for this and got this error was because of that!
Try wrapping it in Try tags
vb Code:
Try TextBox1.Text = TextBox1.Text.Substring(6, TextBox1.Text.Length) Catch End Try
You shouldn't wrap it in try..catch blocks - you should just check the length first.
Actually though the problem is that the example is wrong... it should be
Code:If TextBox1.Text.Length >=6 Then TextBox1.Text = TextBox1.Text.Substring(6, Textbox1.Text.Length-6)
Yes Thankyou for the Correction Keystone Paul
Happy having fun with your Textbox! :)
(I have corrected my code post (first post))
ohhh very very thanks to you and all
and is there any good tutorials for textboxes advance ones??
You could try..
Google Search
Youtube Videos
or
Search the Forums
Hope you can get all you need! Anything you need to know on textboxes you can ask me! I know alot as I am a 3.5 Year VB Programmer.
Everyone else is probably better but I can help you. :)
well thanks for ur helping spirit :)
so how i can i do like theres a text box in that i have selected some paths to load on line 1 a path on the second another path so and every path i to be used by an button so how can i do to load the 1st button 1st line of the text box (that means its select a path) and 2nd button select second line and so on
I hope you understand with it
no problem i got the working code
Code:Dim b As String() = Split(TextBox2.Text, vbNewLine)
TextBox1.Text = String.Join(vbNewLine, b, 2, b.Length - 2)
So as the image says how can i write to that txtfile which is added by the Vb it self so the advantage would be that nobody could see the file
plz help need serious one
At the top of all your code you should see
vb Code:
Public Class Form1
Under that add
vb Code:
Dim TxtFile1 As New TextFile1
To append/add text
vb Code:
TxtFile1.AppendText(Environment.NewLine & "text")
To save file
vb Code:
My.Computer.FileSystem.WriteAllText("C:\Where to be saved", TxtFile1, False)
ok thanks
its not working
Change the End 'TextFile1' to 'TextFile1.txt'
Adding an empty textfile to your project is pointless. Usually such text files contain some side notes or documentation or something else and their contents are not modified within the code.
If you simply want to create a textfile then just use IO.FileStream:
To delete first 6 characters from a textfile do:Code:Using sw As New IO.StreamWriter("C:\test.txt")
sw.WriteLine("123456 Some text")
sw.Flush()
sw.Close()
End Using
vb.net Code:
' Will delete the first 6 bytes from the file "C:\Test.txt" Dim BytesToDelete As Integer = 6 Try Dim fs As New IO.FileStream("C:\Test.txt", IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.None) Dim srcBuff(CInt(fs.Length - 1)) As Byte fs.Read(srcBuff, 0, CInt(fs.Length)) Dim dstBuff(srcBuff.Length - BytesToDelete - 1) As Byte Array.ConstrainedCopy(srcBuff, BytesToDelete, dstBuff, 0, dstBuff.Length) fs.SetLength(0) ' Truncate the file fs.Write(dstBuff, 0, dstBuff.Length) fs.Flush() fs.Close() Catch ex As Exception MsgBox(ex.Message) End Try
ok no problems if the text file is not editable
is there anyway else by which we can save the text file but it should not be visible to the user
and can i replace those 6 characters from the textbox or
i think we could delete those and add something to the start of every line that would be more easier
Though I cannot imagine why would you want one, but you can add a textfile as a resource to your .exe.
Go to menu Project / Properties / Resources tab
From the 'Add resouce' dropdown select Add new text file.
Bear in mind that you wouldn't be able to modify the contents of your text file once it's been added as a resource.
can i replace those 6 characters from the textbox or
i think we could delete those and add something to the start of every line that would be more easier???
Replacing is easier (you don't have to change the length of a file).
By the way, can you tell us what EXACTLY you are trying to achieve? Knowing this it'd be easier to help you.
well i'm looking for the code to replace those 6 characters from the textbox
and add something else more than 6 or less and do this process to everyline
and how can i select the 2nd line only and add something
for example
we use
So how can i select the second line and replace anythingCode:TextBox1.Text = "Example"
I Tried
Code:Textbox1.Text.Lines(3) = "Example" ' not working
Textbox1.Lines(2) = "This is an example" ' not working
Code:Dim Lines() As String = TextBox1.Lines
Lines(3) = "Example"
TextBox1.Lines = Lines
hey can i load a SWF Image to a Picture Box or by any other way???
Either you should use some component from Adobe or use Webbrowser control.
This code does not delete anything. Split function just splits your string into several using comma as a delimeter. The resulting array (sText) will contain all parts of the text.
For example:
vb.net Code:
Dim Text As String = "ab, cd, ef, gh" Dim sText() As String = Split(Text, ",")
After this, your sText array will have the following members:
sText(0) = "ab"
sText(1) = "cd"
sText(2) = "ef"
sText(3) = "gh"
OK thanks plz tell how to doFor all the lines which are there in a textboxCode:Dim Lines() As String = TextBox1.Lines
Lines(3) = "Example"
TextBox1.Lines = Lines
I got it
by thisThanks For ur HelpCode:For Each line As String In TBox.Lines '<- array created here
Dim Text As String = line
Dim sText() As String = Split(Text, ",")
TextBox1.Text = TextBox1.Text & vbCrLf & sText(1)
I just Wanted to know
How to search for for a name like if in the textbox contains ".at3"
Then it could show me the line number or something like that??
And how to search for a word
Ok ok i found it out by this code
If u want any help in this topic just reply hereCode:For Each line As String In TextBox1.Lines '<- array created here
Dim f As String = line
Dim s As String = f.Substring(f.LastIndexOf(".") + 1)
If s = "at3" Then
TextBox2.Text = Textbox2.Text + vbCrLf + line
End If
thanks to all
Hey PLz tell me can i edit or see the hex of any file in vb????
Anyone i don't want to edit it i just want to see the first word
where the extension is given?
And can i add dummy data to the end of file
Anyone???????
A StreamReader returns the ASCII values of any file that's read. Granted, if you read more than a text file you'll probably get mostly garbled data that has no ASCII equivalent.Quote:
Hey PLz tell me can i edit or see the hex of any file in vb????
The "first word" is very...vague. First word of what? The first word of the line you're reading, or the name of the file you're reading? It could be anything that you're asking.Quote:
Anyone i don't want to edit it i just want to see the first word
As for adding dummy data to the end of the file, you have to manipulate the file in such a way to read to the end, then start writing at the end of the file. One more note, don't bump your topic within 4 hours on the same day. It clogs up the forums. It's generally given that you should wait 24 hours before "bump"ing your post.
ok sorry formlesstree4
the "first word" Means the first offset in the hex editing where the extension is given
And has anyone succeded in Eugene Pavlov Hex Editor Ocx??? if yes plz tell me how did u open a file with it???
http://www.codeproject.com/KB/edit/hexeditor.aspx
i have some codes here it works fine but if the text file is long and big it does not respond and after showing not responding for some time it works I think it keep processing the files
So i wanted to have a progress bar and it would work properly
its a program for removing some words (LBA) from a file list which is seperated by comma so as i said if the file list is long it hangs so i want some tips from you i wanted to have a progress bar
I think if i count the number of lines and then do something like when it has done 1% of the total lines it would increase value by 1
And it does not show not responding
here are my codes
Code:For Each line As String In TBox.Lines '<- array created here
Dim Text As String = line
Dim sText() As String = Split(Text, ",")
TextBox1.Text = TextBox1.Text & vbCrLf & sText(1)
Next
Tbox.Text = TextBox1.Text
TextBox1.Text = Nothing
vb.net Code:
Dim line_idx As Integer, line As String, Lines As String() Dim AddedLines As New List(Of String) Dim Progress As Integer = 0 Lines() = TBox.Lines For line_idx = 0 To Lines.Length - 1 Dim sText() As String = Split(Lines(line_idx), ",") If sText.Length >= 2 Then ' A little bit of checking never hurts AddedLines.Add(Environment.NewLine + sText(1)) End If Progress = CInt(line_idx / Lines.Length * 100) ' in %% ' Add progressbar updating here ' Something like ProgressBar1.Value = Progress ' Do not forget to allow the application to update the usercontrols ' Though it slows down the execution a little - it's a price for progressbar: Application.DoEvents Next Tbox.Lines = AddedLines.ToArray
Should work, but I wrote that w/o IDE so there might be some errors.
It's an equivalent of the code you posted, but mine reports a progress to a progressbar.
Drop a progressbar (named ProgressBar1) onto a form and uncomment:
ProgressBar1.Value = Progress (see comments).
well very thanks for your code it works very faster than mine
can i know the reason??
Ok ok i got it
Now can anyone plz tell me how can i search a particular word in a line of a textbox
For example one line of the file list is
"PSP_GAME\USRDIR\nis\Convoy\Ryak_1_es.ssg"
There are many lines like this so now i have to find that if the consists of 'es' then it will give me a message (well i have to add it to a line i'll do that myself)
I know how to replace but in this case i don't want to replace i just want to find
if u have any better codes plz replyCode:Dim MyPos
MyPos = InStr(TextBox1.Text, TextBox2.Text)
MsgBox(MyPos)
If MyPos = 0 = False Then
MsgBox("its having it")
Else
MsgBox("Its Not having ny language Files")
End If
its not working
plz give any other codes
If you do not need to know the position of the found string token (if any) then you can use .Contains method:
vb.net Code:
If TextBox1.Text.Contains(TextBox2.Text) Then ' String found Else ' String not found End if
hi i wanted to know the in 0*00000000 offset in a textbox
Hey i wanted to do something like if the answer comes 23 which is 2 digit and i want in 6 digits so when i press a button i get 000023
or if i get 456 i should get 000456
and so on plz can u give me some help
Ok i got itCode:Label1.Text = Len(TextBox1.Text)
If Label1.Text = 1 Then
TextBox1.Text = "00000" + TextBox1.Text
ElseIf Label1.Text = 2 Then
TextBox1.Text = "0000" + TextBox1.Text
ElseIf Label1.Text = 3 Then
TextBox1.Text = "000" + TextBox1.Text
ElseIf Label1.Text = 4 Then
TextBox1.Text = "00" + TextBox1.Text
ElseIf Label1.Text = 5 Then
TextBox1.Text = "0" + TextBox1.Text
End If
And i have this codes i hangs sometimes plz if you have anything better plz tell me
Code:Dim AddedLines As New List(Of String)
Dim Lines As String()
Dim line_idx As Integer
Lines = TextBox1.Lines
Dim Progress As Integer = 0
For line_idx = 0 To Lines.Length - 1
Dim sText() As String = Split(Lines(line_idx), ",")
Dim b As String() = Split(TextBox1.Text, vbNewLine) ''Deletes a line
TextBox1.Text = String.Join(vbNewLine, b, 1, b.Length - 1)
Label5.Text = TextBox1.Lines.Length ' Calculate the number of lines
Dim ssText() As String = Split(Lines(line_idx), ",")
Dim Final As Integer
Final = ssText(0) - "1"
Dim se As String
se = sText(0) & " " & Final
AddedLines.Add(se)
Progress = CInt(line_idx / Lines.Length * 100)
ProgressBar1.Value = Progress
'Loop
If Label5.Text = "1" Then 'I have to stop if there is 1 line left
TextBox2.Lines = AddedLines.ToArray
Exit Sub
End If
Next
anyone?? how to get this offset 0*00000000
hey guys please help me out
i need to find out a word with continous 4 letters and then continues 5 numbers like
four1245
plz suggest me something what can i do????