Page 1 of 2 12 LastLast
Results 1 to 40 of 48

Thread: Text Boxes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Text Boxes

    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

  2. #2
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Re: Text Boxes

    vb Code:
    1. If TextBox1.Text.Length > 6 Then
    2.     TextBox1.Text = TextBox1.Text.Substring(6, TextBox1.Text.Length - 6)
    3. End If

    Or

    vb Code:
    1. If TextBox1.Text.Length > 6 Then TextBox1.Text = TextBox1.Text.Substring(6, TextBox1.Text.Length - 6)
    Last edited by dcrew; Feb 7th, 2010 at 09:41 AM.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Text Boxes

    That implies that your string isn't at least 6 characters long.

  5. #5
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Re: Text Boxes

    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:
    1. Try
    2.     TextBox1.Text = TextBox1.Text.Substring(6, TextBox1.Text.Length)
    3. Catch
    4. End Try

  6. #6
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Text Boxes

    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)

  7. #7
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Re: Text Boxes

    Yes Thankyou for the Correction Keystone Paul

    Happy having fun with your Textbox!

    (I have corrected my code post (first post))

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    ohhh very very thanks to you and all
    and is there any good tutorials for textboxes advance ones??

  9. #9
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Re: Text Boxes

    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.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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)

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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
    Attached Images Attached Images  
    Last edited by watson123; Feb 8th, 2010 at 08:51 AM. Reason: wrong spelling

  13. #13
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Re: Text Boxes

    At the top of all your code you should see
    vb Code:
    1. Public Class Form1

    Under that add
    vb Code:
    1. Dim TxtFile1 As New TextFile1

    To append/add text
    vb Code:
    1. TxtFile1.AppendText(Environment.NewLine & "text")

    To save file
    vb Code:
    1. My.Computer.FileSystem.WriteAllText("C:\Where to be saved", TxtFile1, False)

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    ok thanks

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    its not working
    Attached Images Attached Images  

  16. #16
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Re: Text Boxes

    Change the End 'TextFile1' to 'TextFile1.txt'

  17. #17
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Text Boxes

    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:
    Code:
    Using sw As New IO.StreamWriter("C:\test.txt")
        sw.WriteLine("123456 Some text")
        sw.Flush()
        sw.Close()
    End Using
    To delete first 6 characters from a textfile do:
    vb.net Code:
    1. ' Will delete the first 6 bytes from the file "C:\Test.txt"
    2. Dim BytesToDelete As Integer = 6
    3. Try
    4.     Dim fs As New IO.FileStream("C:\Test.txt", IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.None)
    5.     Dim srcBuff(CInt(fs.Length - 1)) As Byte
    6.     fs.Read(srcBuff, 0, CInt(fs.Length))
    7.     Dim dstBuff(srcBuff.Length - BytesToDelete - 1) As Byte
    8.     Array.ConstrainedCopy(srcBuff, BytesToDelete, dstBuff, 0, dstBuff.Length)
    9.     fs.SetLength(0) ' Truncate the file
    10.     fs.Write(dstBuff, 0, dstBuff.Length)
    11.     fs.Flush()
    12.     fs.Close()
    13. Catch ex As Exception
    14.     MsgBox(ex.Message)
    15. End Try

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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

  19. #19
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Text Boxes

    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.

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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???

  21. #21
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Text Boxes

    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.

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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
    Code:
    TextBox1.Text = "Example"
    So how can i select the second line and replace anything
    I Tried

    Code:
    Textbox1.Text.Lines(3) = "Example" ' not working 
    Textbox1.Lines(2) = "This is an example" ' not working

  23. #23

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    hey can i load a SWF Image to a Picture Box or by any other way???

  25. #25

  26. #26

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    Quote Originally Posted by cicatrix View Post
    Code:
    Dim Lines() As String = TextBox1.Lines
    Lines(3) = "Example"
    TextBox1.Lines = Lines

    Hey Thanks for your help But How can i do this for all of the lines

    And
    Code:
    Dim sText() As String
            sText = Split(TextBox1.Text, ",")
            TextBox1.Text = sText(0)
    This Code Deletes after the comma (,)
    how can i delete before the comma
    Last edited by watson123; Feb 13th, 2010 at 10:07 PM.

  27. #27
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Text Boxes

    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:
    1. Dim Text As String = "ab, cd, ef, gh"
    2. 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"

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    OK thanks plz tell how to do
    Code:
      Dim Lines() As String = TextBox1.Lines
    Lines(3) = "Example"
    TextBox1.Lines = Lines
    For all the lines which are there in a textbox

  29. #29

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    I got it
    by this
    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)
    Thanks For ur Help
    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
    Last edited by watson123; Feb 14th, 2010 at 01:03 AM.

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    Ok ok i found it out by this code
    Code:
    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
    If u want any help in this topic just reply here
    thanks to all

  31. #31

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    Hey PLz tell me can i edit or see the hex of any file in vb????

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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
    Last edited by watson123; Feb 15th, 2010 at 07:28 AM.

  33. #33

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    Anyone???????

  34. #34

    Re: Text Boxes

    Hey PLz tell me can i edit or see the hex of any file in vb????
    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.

    Anyone i don't want to edit it i just want to see the first word
    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.

    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.

  35. #35

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    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
    Last edited by watson123; Feb 16th, 2010 at 08:26 AM.

  37. #37
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Text Boxes

    vb.net Code:
    1. Dim line_idx As Integer, line As String, Lines As String()
    2.  
    3. Dim AddedLines As New List(Of String)
    4. Dim Progress As Integer = 0
    5. Lines() = TBox.Lines
    6.  
    7.  
    8. For line_idx = 0 To Lines.Length - 1
    9.     Dim sText() As String = Split(Lines(line_idx), ",")
    10.     If sText.Length >= 2 Then  ' A little bit of checking never hurts
    11.         AddedLines.Add(Environment.NewLine + sText(1))
    12.     End If
    13.     Progress = CInt(line_idx / Lines.Length * 100) ' in %%
    14.     ' Add progressbar updating here
    15.     ' Something like ProgressBar1.Value = Progress
    16.     ' Do not forget to allow the application to update the usercontrols
    17.     ' Though it slows down the execution a little - it's a price for progressbar:
    18.     Application.DoEvents
    19. Next
    20. Tbox.Lines = AddedLines.ToArray

    Should work, but I wrote that w/o IDE so there might be some errors.

  38. #38

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    Quote Originally Posted by cicatrix View Post
    vb.net Code:
    1. Dim line_idx As Integer, line As String, Lines As String()
    2.  
    3. Dim AddedLines As New List(Of String)
    4. Dim Progress As Integer = 0
    5. Lines() = TBox.Lines
    6.  
    7.  
    8. For line_idx = 0 To Lines.Length - 1
    9.     Dim sText() As String = Split(Lines(line_idx), ",")
    10.     If sText.Length >= 2 Then  ' A little bit of checking never hurts
    11.         AddedLines.Add(Environment.NewLine + sText(1))
    12.     End If
    13.     Progress = CInt(line_idx / Lines.Length * 100) ' in %%
    14.     ' Add progressbar updating here
    15.     ' Something like ProgressBar1.Value = Progress
    16.     ' Do not forget to allow the application to update the usercontrols
    17.     ' Though it slows down the execution a little - it's a price for progressbar:
    18.     Application.DoEvents
    19. Next
    20. Tbox.Lines = AddedLines.ToArray

    Should work, but I wrote that w/o IDE so there might be some errors.

    Sorry Dude Not Able to understand you????

  39. #39
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Text Boxes

    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).

  40. #40

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    120

    Re: Text Boxes

    well very thanks for your code it works very faster than mine
    can i know the reason??

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width