Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Textbox problem

Posted on 2003-11-01
12
Medium Priority
?
920 Views
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
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)?
0
Comment
Question by:vbr666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9662840
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
 
LVL 1

Assisted Solution

by:fsaims
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..")
0
 
LVL 17

Assisted Solution

by:zzzzzooc
zzzzzooc earned 80 total points
ID: 9665597
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:vbr666
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
  cc
End If
End Sub

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

Author Comment

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

Author Comment

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

Author Comment

by:vbr666
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?!?

I'M GIVING THE EXTRA POINTS FOR THIS SO PLEASE HELP!  
0
 
LVL 28

Accepted Solution

by:
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, "")
0
 

Author Comment

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

Author Comment

by:vbr666
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?
0
 

Author Comment

by:vbr666
ID: 9672855
CAN ANYBODY HELP?!
0
 

Author Comment

by:vbr666
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)
    Else
        MsgBox "This file is longer than 32Kb"
    End If
    Close filenumber
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

721 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