Solved

Textbox problem

Posted on 2003-11-01
12
881 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
12 Comments
 
LVL 28

Expert Comment

by:vinnyd79
Comment Utility
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 20 total points
Comment Utility
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 20 total points
Comment Utility
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
 

Author Comment

by:vbr666
Comment Utility
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
Comment Utility
ok no need answering i found the "problem"
0
 

Author Comment

by:vbr666
Comment Utility
i'm gonna give you all points but when i finish what im doing now.that will be soon i think
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:vbr666
Comment Utility
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 113 total points
Comment Utility
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
Comment Utility
Thanx for the code above,it solved problem 6,but do you have any ideas about problem 5?
0
 

Author Comment

by:vbr666
Comment Utility
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
Comment Utility
CAN ANYBODY HELP?!
0
 

Author Comment

by:vbr666
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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.

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now