Go Premium for a chance to win a PS4. Enter to Win


Textbox problem

Posted on 2003-11-01
Medium Priority
Last Modified: 2013-11-13
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
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)?
Question by:vbr666
LVL 28

Expert Comment

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

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

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


Assisted Solution

fsaims earned 80 total points
ID: 9662957
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..")
LVL 17

Assisted Solution

zzzzzooc earned 80 total points
ID: 9665597

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


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


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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 9666195
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
End If
End Sub

Then I get "Expected Sub, Function or Property" error.
Why? How to solve it?

Author Comment

ID: 9666361
ok no need answering i found the "problem"

Author Comment

ID: 9666365
i'm gonna give you all points but when i finish what im doing now.that will be soon i think

Author Comment

ID: 9667333
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?!?

LVL 28

Accepted Solution

vinnyd79 earned 452 total points
ID: 9667417
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, "")

Author Comment

ID: 9669963
Thanx for the code above,it solved problem 6,but do you have any ideas about problem 5?

Author Comment

ID: 9670703
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?

Author Comment

ID: 9672855

Author Comment

ID: 9683127
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)
        MsgBox "This file is longer than 32Kb"
    End If
    Close filenumber

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question