22 Replies - 683 Views - Last Post: 11 February 2013 - 09:55 PM
#1
Char edit in a text box
Posted 05 February 2013 - 12:18 PM
Textbox1.Text = "Red Roses"
Textbox2.Text should then be "102ed 102oses"
and if that is posible i want to set all the char to a value
Between each char should be "_"
Space = +
e = 01
s = 23
d = 1
o = 00
Red Roses then must be : "102_01_1+102_00_23_01_23"
Then I would like to do the opposite : "102_01_1+102_00_23_01_23" = Red Roses
Please and thanks
Replies To: Char edit in a text box
#2
Re: Char edit in a text box
Posted 05 February 2013 - 12:29 PM
Create an empty string
Loop through each character of the text
Look up the replacement character in the dictionary
Append the replacement to your (initially) empty string
To reverse the process you might use the same dictionary, but I would probably consider just creating a second dictionary.
(The reverse process is more complicated because you will not be replacing individual characters.)
Just my initial impression
#3
Re: Char edit in a text box
Posted 06 February 2013 - 12:58 AM
#4
Re: Char edit in a text box
Posted 06 February 2013 - 03:42 AM
maj3091, on 06 February 2013 - 12:58 AM, said:
Hello. I was referring to VB6. Yes, a Collection is directly available but it is straight-forward to add-in a Dictionary - see the link I provided - which has advantages:
Quote
The option to specify a comparison method for Keys. This allows for a case-sensitive Key, for example.
A method for determining if an object exists in a Dictionary.
A method for extracting all of the Keys into an Array.
A method for extracting all of the Items into an Array.
A method for changing a Key value.
A method for removing all items from the Dictionary.
Dictionary Keys are not limited to String datatype.
It just requires adding a reference to the Microsoft Scripting Runtime.
This post has been edited by andrewsw: 06 February 2013 - 03:47 AM
#5
Re: Char edit in a text box
Posted 06 February 2013 - 05:24 AM
I am still new to this so I don't know how to create a Dictionary and I use VS 2012(the closest object to VS was the VB 06 link)
So know I know it is possible, but where to start?
Create a Dictionary and set the values/keys.
But can someone maybe please direct me to a link where i can see how to create it (it's was hard for me to find something that was close to my idea and I didn't get any positive results of how and what to use.
At least I now know I must use a Dictionary but I need to know how to create and call it as well as set the values and edit a specific char like all the "R" in a text box
I am really new to this..So forgive me if I don't understand all the info you have provided to me.
After I created a Dictionary I should make a loop you say..like a timer? or?
Please, if you like to give me a little bit of your time (I know I must give some of the code to you but I don't know where to start and I don't want to look stupid..
Please and thanks
#6
Re: Char edit in a text box
Posted 06 February 2013 - 06:21 AM
andrewsw, on 06 February 2013 - 10:42 AM, said:
maj3091, on 06 February 2013 - 12:58 AM, said:
Hello. I was referring to VB6. Yes, a Collection is directly available but it is straight-forward to add-in a Dictionary - see the link I provided - which has advantages:
Quote
The option to specify a comparison method for Keys. This allows for a case-sensitive Key, for example.
A method for determining if an object exists in a Dictionary.
A method for extracting all of the Keys into an Array.
A method for extracting all of the Items into an Array.
A method for changing a Key value.
A method for removing all items from the Dictionary.
Dictionary Keys are not limited to String datatype.
It just requires adding a reference to the Microsoft Scripting Runtime.
Thanks Andrew, didn't even know it existed in VB6!
#7
Re: Char edit in a text box
Posted 06 February 2013 - 06:26 AM
VB.NET has dictionaries, lists, arrays, and many other collections. But it appears that your knowledge of Visual Basic is limited. I suggest you start by reading through a few tutorials - there is a Tutorials link at the top of this page.
@maj3091
Quote
No worries! It should really be native to VB6, rather than added as a reference, as it is so useful
#8
Re: Char edit in a text box
Posted 06 February 2013 - 06:37 AM
FWIW When we add a reference to Microsoft Scripting Runtime we also have access to a TextStream object.
VBScript
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, ts, fileObj, TextLine
Set fso = CreateObject("Scripting.FileSystemObject")
' Create the file, and obtain a file object for the file.
FileName = "c:\testfile.txt"
fso.CreateTextFile FileName
Set fileObj = fso.GetFile(FileName)
' Open a text stream for output.
Set ts = fileObj.OpenAsTextStream(ForWriting, TristateUseDefault)
' Write to the text stream.
ts.WriteLine "Hello World!"
ts.WriteLine "The quick brown fox"
ts.Close
' Open a text stream for input.
Set ts = fileObj.OpenAsTextStream(ForReading, TristateUseDefault)
' Read from the text stream and display the results.
Do While ts.AtEndOfStream <> True
TextLine = ts.ReadLine
document.Write TextLine & "<br />"
Loop
ts.Close
MSDN
This post has been edited by andrewsw: 06 February 2013 - 06:39 AM
#9
Re: Char edit in a text box
Posted 06 February 2013 - 09:30 AM
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As String = ""
If TextBox1.Text.Contains("A") Then
If TextBox1.SelectedText = "A" Then
For Each a In (TextBox1.SelectedText)
TextBox2.Text = TextBox2.Text + "010"
TextBox1.SelectedText = ""
Next
End If
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim Search As String
Dim Where As String
' Get search string from user.
' Find string in text.
Where = InStr(TextBox1.Text, "A")
If Where Then
TextBox1.Focus()
TextBox1.Selectionstart = Where - 1
TextBox1.SelectionLength = Len("A")
Else
MsgBox("String not found.")
End If
End Sub
End Class
So my problem is when I take the "A" and make it "010" the text loses order eg. "ABCDA" then text2 = "010010" and the "BCD"
So how can i still keep the char location eg. "ABCDA" first A = 1 and last A = 4 so it will be "010BCD010"
#10
Re: Char edit in a text box
Posted 06 February 2013 - 09:56 AM
Anyway, just in case it helps, the following code changes "ABCDA" to "010BCD010".
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sCoded As String = ""
For Each ch As Char In TextBox1.Text.ToUpper
If ch = "A"c Then
sCoded += "010"
Else
sCoded += ch
End If
Next
TextBox1.Text = sCoded
End Sub
#11
Re: Char edit in a text box
Posted 09 February 2013 - 12:36 PM
#12
Re: Char edit in a text box
Posted 09 February 2013 - 12:38 PM
#13
Re: Char edit in a text box
Posted 09 February 2013 - 12:40 PM
#14
Re: Char edit in a text box
Posted 09 February 2013 - 12:49 PM
Rjjvv, on 09 February 2013 - 12:40 PM, said:
That is trickier. You still have to loop through all the characters, but use IsNumeric() to discover if the current character is a number. If it is, then save it in a string and keep appending to it until the next character that is not a number. Good luck!
#15
Re: Char edit in a text box
Posted 09 February 2013 - 01:08 PM
eg: If the following 3chars are = to 010 then TB2.text = A
It is quit hard, to use this when the char > than 1
I see I can do it easy the same way if I make A = @(a 1 char)
|
|

New Topic/Question
Reply



MultiQuote





|