|
-
Sep 9th, 2000, 09:59 AM
#1
Thread Starter
Frenzied Member
I want my program to search for the next " " (space) after 100 characters and then add an "a" to it. I need it to do that every 100 characters
how do I do that?
NXSupport - Your one-stop source for computer help
-
Sep 9th, 2000, 10:08 AM
#2
Frenzied Member
Code:
Private Sub Text1_Change()
i = i + 1
If i = 100 Then
i = 0
Text1.SelText = " a"
End if
End Sub
Did you meant that or didn't I understand ya?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 9th, 2000, 10:11 AM
#3
Hyperactive Member
I haven't checked it really, but that should be the guide line ..
Dim Mystr As String
Dim Counter As Integer
Dim CounterFromLastSpace As Integer
CounterFromLastSpace = 0
Mystr = "bla bla lbadfdsf df dsfsdf sdfdsfsdfdsf dsff gfhfghghgfgfg ghgfh gfh fghgf fghfgh fgh gfh fgh fgh fgfgh fghfgh fghfgh fgh fgh fgh fgh fgh fgh fghg hfgh fgh fgh fgh fgh fgh fgh ...."
For Counter = 0 To Len(Mystr)
CounterFromLastSpace = CounterFromLastSpace + 1
If Mid(Mystr, Counter + 1, 1) = " " Then
If CounterFromLastSpace = 100 Then
Mystr = Left(Mystr, Counter) & " a " & Right(Mystr, Len(Mystr) - Counter)
CounterFromLastSpace = 0
End If
End If
Next
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 9th, 2000, 10:12 AM
#4
Thread Starter
Frenzied Member
I tried that , what I need is so that every 100 characters it adds a " a" to the thing and it will do the same for the 200th 300th 400th 500th 600th
I hope this time was more clear
NXSupport - Your one-stop source for computer help
-
Sep 9th, 2000, 10:12 AM
#5
Hyperactive Member
sorry, the if statment should be:
If CounterFromLastSpace >= 100 Then
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 9th, 2000, 10:15 AM
#6
Thread Starter
Frenzied Member
I'm sorry, that still doesn't work
NXSupport - Your one-stop source for computer help
-
Sep 9th, 2000, 10:28 AM
#7
Hyperactive Member
o.k, so maybe I did't understand you ...
lets see.
if you have:
"here is my code for the program that you want"
and lets say that you want to add "a" every 10 char, do you mean:
"here is my a code for a the progra a m that you a want"
OR
"here is my a code for a the program a that you a want"
??
And I think I know what is the problem with my fornext loop, I keep changing the length of the variable, you should change it a bit something like:
Dim Mystr As String
Dim Counter As Integer
Dim CounterFromLastSpace As Integer
dim until as integer
CounterFromLastSpace = 0
Mystr = "bla bla lbadfdsf df dsfsdf sdfdsfsdfdsf dsff gfhfghghgfgfg ghgfh gfh fghgf fghfgh fgh gfh fgh fgh fgfgh fghfgh fghfgh fgh fgh fgh fgh fgh fgh fghg hfgh fgh fgh fgh fgh fgh fgh ...."
until=Len(Mystr)
For Counter = 0 To until
CounterFromLastSpace = CounterFromLastSpace + 1
If Mid(Mystr, Counter + 1, 1) = " " Then
If CounterFromLastSpace >= 100 Then
Mystr = Left(Mystr, Counter) & " a " & Right(Mystr, Len(Mystr) - Counter)
CounterFromLastSpace = 0
End If
End If
Next
End Sub
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 9th, 2000, 10:32 AM
#8
Thread Starter
Frenzied Member
this is what I would like:
"here is my a code for a the program a that you a want"
now is that the code for it in your last post?
NXSupport - Your one-stop source for computer help
-
Sep 9th, 2000, 11:05 AM
#9
Hyperactive Member
yes,
Again, I havenet fully tested it but it should work , or at least the logic is there .. :-)
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 9th, 2000, 11:20 AM
#10
Frenzied Member
Code:
'This'll work!
For x = 0 To Len(Text1.Text) Step 100
Text1.SelStart = x
Text1.SelLength = 1
If Text1.SelText = " " Then
Text1.SelStart = x
Text1.SelText = " a"
End If
Next x
I think it's faster because it doesn't do it char by char but Step 99 it does 99 at a time. (not sure if it's faster by the way and I'm not taking down your code or saying mine is 'better')
[Edited by Jop on 09-09-2000 at 12:31 PM]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 9th, 2000, 11:30 AM
#11
Hyperactive Member
first of all THANK YOU !
1. I never used this property of a text box (never new it exists) !.
2. Your code looks nice, but I don't think it handles if there is no space exactly in the 100th character ... then it just skips it (correct me if I am wrong I just read it).
maybe a combination of both our code will help him, he can
check if it is not a " " than move one forword etc ... until it is " " and then add the "a" ..
sounds good ?
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 9th, 2000, 11:33 AM
#12
Frenzied Member
My code had some flaws 
Code:
For x = 100 To Len(Text1.Text) Step 98
Text1.SelStart = x
Text1.SelLength = 1
If Text1.SelText = " " Then
Text1.SelStart = x
Text1.SelText = " a"
End If
Next x
I believe this has no flaws! (but I may be wrong hehe)
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 9th, 2000, 11:40 AM
#13
Hyperactive Member
what about the case in which there is no " ", will it put it at the next " " ?
that's the way I understood he want it ..
:-)
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 9th, 2000, 11:51 AM
#14
_______
<?>
Code:
Option Explicit
Private Sub Command1_Click()
Dim intCre, intCharCount, intStringLen, _
sTextString, sCharHolder, sNewTextString
'load up some junk for testing making sure no letter a is involved
'as it's easier to test if the field is bare
For intCre = 1 To 400
Text1.Text = Text1.Text & intCre
Next intCre
'load string and get length
sTextString = Text1.Text
intStringLen = Len(sTextString)
'for the length of the string count every 100 spaces
'and create the new string as you go
For intCre = 1 To Len(sTextString)
sCharHolder = Left(sTextString, 1)
intCharCount = intCharCount + 1
sNewTextString = sNewTextString & sCharHolder
'if the count is 100 and an "a" as asked and reset the counter
If intCharCount = 100 Then
intCharCount = 0
sNewTextString = sNewTextString & "a"
End If
'continue on through the string
sTextString = Right(sTextString, intStringLen - intCre)
Next intCre
'when finished with the loop add the new string to text2.text or
'whatever you want to do with it
Text2.Text = sNewTextString
''this is just for checking to see it the above works (and it does)
'validation of process
sTextString = Text2.Text
intStringLen = Len(sTextString)
intCharCount = 1
For intCre = 1 To Len(sTextString)
sCharHolder = Left(sTextString, 1)
'if we find an a let's count them
If Asc(sCharHolder) = 97 Then
intCharCount = intCharCount + 1
End If
'continure on
sTextString = Right(sTextString, intStringLen - intCre)
Next intCre
'how many letterw were found.
'should be the same as the string length /100
MsgBox intCharCount & " letters a involved"
MsgBox Fix(intStringLen / 100)
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 9th, 2000, 11:58 AM
#15
Frenzied Member
Oh, **** my code, it sucks, don't use it.
This'll do better I think 
Code:
Dim Counter As Integer
Dim foundat As Long, foundatL As Long
Dim x As Long
Text1 = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 "
For Counter = 1 To Len(Text1)
foundat = InStr(foundat + 1, Text1, " ")
If foundat > foundatL + 98 Then
Text1 = Left(Text1, foundat) & "a " & Right(Text1, Len(Text1) - foundat)
foundatL = foundat
End If
Next
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 9th, 2000, 03:09 PM
#16
Thread Starter
Frenzied Member
Thanks to everone for your help, I really appriciate it. and one more time THANKS!!!
NXSupport - Your one-stop source for computer help
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
|