Textbox problem

I'm trying to make an application which communicates with windows command prompt and I have 3 questions:

1)  How can I subtract last character from a textbox Text1 and show the rest of chars(except that last one) in txtbox Text2?
For example:If this is written in Text1: "This is test line1" how can I subtract its last character so I get this in Text2: "This is test line" ?
I've tried this:
Dim a
b="1"
a = Len(Text3.Text) - b
Text4.Text = a(the number of chars without that last one is shown in text4.)

2) How can I "find" the group of certain characters(a word for example) among other characters(other words) in textbox and then delete that certain group of chars?

For example:
Text written in textbox Text1 is: "cmd /c cd..&&cd&&dir&&cd ASDF&&cd"
Now, how can I select a word "dir" in that line in Text1 and delete it without changing the rest of that line?

3)  how can I achieve that when I type "cd.." the program automatically adds "&&cd" anywhere in that textbox(not only in the beginning of the line)?
vbr666Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinnyd79Commented:
1-
Text4.Text = Mid$(Text3.Text, 1, Len(Text3.Text) - 1)

2-
Text1.Text = Replace(Text1.Text,"dir","")

For #3, do you want to add it to a specific position?

0
fsaimsCommented:
For Problem No.1 Use this

Text4.Text = Mid$(Text3.Text, 1, Len(Text3.Text) - 1)

For Problem No.2 Use this

Text1.Text = Replace$(Text1.Text, "dir", "")

For Problem No.2 Use this

if you want change the group "cd" that must come before "..", then use this syntax

Text2.Text = Replace$(Text1.Text, "cd..", "&&cd..")
0
zzzzzoocCommented:
1.)

Left/Right functions may be more appropriate instead of Mid:

Private Sub Form_Load()
    Text1.Text = "Testing"
    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub

2.)

To find strings within a string you can use the InStr() function. The return value of the function is the position of the found string (returns 0 if not found):

    Dim sTemp As String, iPos As Integer
    sTemp = "Testing"
    iPos = InStr(1, sTemp, "ing")
    MsgBox "String found at: " & iPos

To simply "remove" that line then the above examples provided already should work (replacing with nullstring):

    Dim sTemp As String
    sTemp = "Testing"
    sTemp = Replace(sTemp, "Test", vbNullString)
    MsgBox sTemp

3.)

Not sure what you are asking by "add anywhere in that textbox".

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

vbr666Author Commented:
Problem 3 is not important, I solved it.
I've got another problem.
If this:
Private Sub Text1_Change()
Dim cc As String
Text2.Text = Text1.Text
bb = Text2.Text
cc = Replace$(bb, "xx", "yy")
If Right(Text1.Text, 2) = "xx" Then
  cc
End If
End Sub

Then I get "Expected Sub, Function or Property" error.
Why? How to solve it?
0
vbr666Author Commented:
ok no need answering i found the "problem"
0
vbr666Author Commented:
i'm gonna give you all points but when i finish what im doing now.that will be soon i think
0
vbr666Author Commented:
Problem  #5
When I send command prompts output(I've created a client/server application which communicates with cmd) from client to server after executing "dir" command( and the list of files is long) the first part of the list in textbox is erased and i cant use scrollbar to scroll to the beginning. That happens only when I send the cmd's output from client to server but in client application's textbox I can scroll to the beginning  normally. Why is this happening? How to solve this?
Problem #6
When I type a command in a txtbox in which multiline is disabled and press enter to enter the command in command prompt the windows plays annoying "beep" sound trying to tell me there is no another line(multiline=false), but when I type command and press enter in a multiline txtbox the sound isn't played and that's ok but problem is that I'm sending that command from server to client and when I press enter it sends the enterkey sign(two parallel lines, something like "ll") in vb to the client and the command can't be recognized. I tryed to "repair" this by sending text without last character but program works wrong. It sends "ll" but doesn't send the last char from command I really wanted to send.
To make it clearer:
if I write "dir" and press enter it would send "dirll" and command wouldn't be recognized but if I subtract last character it would send "dill"(without r).
How can i get rid of anoying sound and stupid enterkey sign("ll") and send the real command in whole?!?

I'M GIVING THE EXTRA POINTS FOR THIS SO PLEASE HELP!  
0
vinnyd79Commented:
To get rid of the beep,try something like this on the Textboxes keypress event:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
   ' Send Textbox Text
   KeyAscii = 0
End If

End Sub


To get rid of the || ,Try using replace to replace a carriage return with a zero length string:


Text1.Text = Replace(Text1.Text, vbCr, "")

or maybe:
Text1.Text = Replace(Text1.Text, vbCrLf, "")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vbr666Author Commented:
Thanx for the code above,it solved problem 6,but do you have any ideas about problem 5?
0
vbr666Author Commented:
Ok I solved problem 5 but I have one more and final question.
Im having trouble sending all of the command prompt's output text and I need to send the last 64K(65536 bytes).
How can I send via winsock or just transfer from one txtbox to another the last 64K of text data or some other amount of data?
0
vbr666Author Commented:
CAN ANYBODY HELP?!
0
vbr666Author Commented:
I've learned that txtbox can hold 32Kbytes of text and I think that winsock can send only about 2KB of data in a single send event but I know that sending larger files can be achieved using chunks of data and I've successfully sent a larger file and that's ok but how can I send text in chunks(I want to send a text from one txtbox on a client's form to another on a server's form in a chunks of perharps 2KB)? Can you give me a hint or some link of a possible solution? Please help.


Is this code for reading txt files ok?

Dim filenumber As Integer, length As Long
    filenumber = FreeFile
    Open "c:\log.txt" For Input As filenumber
    length = LOF(filenumber)
    If length < 32767 Then
        Text1.Text = Input$(length, filenumber)
    Else
        MsgBox "This file is longer than 32Kb"
    End If
    Close filenumber
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.