|
-
May 7th, 2000, 03:53 AM
#1
Thread Starter
Member
Hi!
I'm using VB6 in Win98. How is it possible to remove e.g. seven (7) characters (also spacebar hits are counted) from the beginning part of the textbox's text-property. For example how can I convert "eGtg12 Hello You All" to "Hello You All"?
And is there any kind of way to change all the first leters of the words in textbox to capitals. Like "a man who walks" -> "A Man Who Walks"?
RieBBo
-
May 7th, 2000, 05:32 AM
#2
Addicted Member
Gee, it seems like I'm the only one answering your questions
tonight, cool! I'm a Guru by default 
Here's the code you asked for:
Code:
'To remove a certain number of characters from a string.
'Note: You must add 1 to the number of characters that you
'want removed because the Mid function uses a base
'character position of 1.
Text1.Text = Mid$(Text1.Text, 8)
To capitalize all of the first characters of words in a
string is a little more complicated, use this little
function that I just wipped up:
Code:
Private Function CapitalizeChars( _
sOrigString As String) As String
Dim bytChars() As Byte
Dim idx As Integer
Dim bToCapitalize As Boolean
ReDim bytChars(Len(sOrigString) - 1)
bytChars = StrConv(sOrigString, vbFromUnicode)
bToCapitalize = True
For idx = 0 To Len(sOrigString) - 1
If bytChars(idx) < 65 _
Or bytChars(idx) > 122 _
Or (bytChars(idx) > 90 _
And bytChars(idx) < 97) Then
bToCapitalize = True
Else
If bToCapitalize = True Then
bytChars(idx) = Asc(UCase(Chr(bytChars(idx))))
bToCapitalize = False
End If
End If
Next idx
CapitalizeChars = StrConv(bytChars, vbUnicode)
End Function
Call the function like this:
Code:
Text1.Text = CapitalizeChars(Text1.Text)
Hope that this helps
Dan PM
Analyst Programmer
VB6 SP3 (also VB4 16-bit sometimes  )
-
May 8th, 2000, 06:53 AM
#3
Gee what version of vb are you using
For capitilisation of first letters in a string of words
have a look at the strconv function, one line of code will resolve your requirement. 
This works for vb5 & vb6
Sorry only just got to your post, after destroying "I Love You" crap.
-
May 8th, 2000, 04:53 PM
#4
Thread Starter
Member
Okay.....
And how can I remove the last threee characters from the TextBox.text?
The long code above which mr. SonGouki nicely posted works fine, but not with scands, like ä and ö and å.....how to make these also work?
RieBBo
-
May 8th, 2000, 09:31 PM
#5
To remove last 3 characters:
Code:
Text1 = Left(Text1, Len(Text1) - 3)
Can you be more specific with your second question???
-
May 9th, 2000, 09:45 AM
#6
Addicted Member
Hey lkivik,
I've been busy the past couple of days, here's my original
code, slightly modified to capitalize scands as well. Enjoy!
Code:
Private Function CapitalizeChars( _
sOrigString As String) As String
Dim bytChars() As Byte
Dim idx As Integer
Dim bToCapitalize As Boolean
ReDim bytChars(Len(sOrigString) - 1)
bytChars = StrConv(sOrigString, vbFromUnicode)
bToCapitalize = True
For idx = 0 To Len(sOrigString) - 1
Select Case bytChars(idx)
Case 97 To 122, 224 To 255
If bToCapitalize = True Then
bytChars(idx) = bytChars(idx) - 32
bToCapitalize = False
End If
Case Else
bToCapitalize = True
End Select
Next idx
CapitalizeChars = StrConv(bytChars, vbUnicode)
End Function
Dan PM
Analyst Programmer
VB6 SP3 (also VB4 16-bit sometimes  )
-
May 9th, 2000, 09:25 PM
#7
Thread Starter
Member
I tried your new modified code, SonG: Why does it convert always the two first characters to capitals...not just one... eg. BIg REd HOuse
.. Can it have something to do with if the word's first character is already capitalized ..??
[Edited by lkivik on 05-10-2000 at 10:27 AM]
-
May 10th, 2000, 05:33 AM
#8
You can use StrConv function that will convert each first charater to Proper Case:
Code:
MsgBox StrConv("this is a small text that will be converted to propert case.", vbProperCase)
-
May 10th, 2000, 07:32 PM
#9
Thread Starter
Member
Hey that (strconv-function) works, also with scands !!!
but still I have one thing in my mind...
Let's take an example: around_the_corner . How to convert it to Around_The_Corner ? I want to make the function handle "_"-marks like they would be spacebar hits....
-
May 10th, 2000, 08:26 PM
#10
Fanatic Member
Try this.
This function will convert the first character of every word into upper case. At the minute if there is a non aplha-numeric number the following letter will be converted to upper case.
e.g.
"hello out-there>world" will become
"Hello Out-There>World"
I am sure you can change it to suit your needs.
Code:
Option Explicit
Private Sub Command1_Click()
Text2.Text = convertUpper(Text1.Text)
End Sub
Private Function convertUpper(strInput As String) As String
Dim i As Long
Dim blUpper As Boolean
Dim strChar As String
convertUpper = UCase$(Mid$(strInput, 1, 1))
For i = 2 To Len(strInput)
strChar = Asc(Mid$(strInput, i, 1))
If blUpper = True Then
strChar = Asc(UCase$(Chr(strChar)))
blUpper = False
End If
'if the char is not 0 - 9
If (strChar < 48) Or (strChar > 57) Then
'if the char is not A - Z
If (strChar < 65) Or (strChar > 90) Then
'if the char is not a - z
If (strChar < 97) Or (strChar > 122) Then
blUpper = True
End If
End If
End If
convertUpper = convertUpper & Chr(strChar)
Next i
End Function
Iain, thats with an i by the way!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|