We're working hard on the next version of Developer Fusion. Let us know what you think
we should be up to!
Members
Technology Zones
Articles
Hosted By
Info
|
[69] String Functions
Last post 01-14-2007 5:00 PM by KöllMorgan. 24 replies.
-
-
-
Smile005


- Joined on 06-17-2001
- United States

- Points 5,575
|
I don't think there's any point in trying. I'm sure with a few spare months you could get it to work but you'd be much better off learning C++ in those months and adding DLL. (C++ allows dynamic DLL loading if you didn't guess)
Also, you might have mistaken the answer i gave you. You can't fill a text file with VB code and expect it to run. The CallByName lets you call a function by it's name which is in a string. This means you can only run what is in the sub/function.
You can use this to create a scripting language and you'll have to program the entire interperator. If you can't see doing this then try the VBScript control (it should be there somewhere, it's an ocx in the list) This will let you write files of pure VBScript (as you can guess it's similar to VB  ) and run them. There should be a few articles out there on the VBScript control.
Hope it helps!
[1]  -==-==---==-=--=-==-===--===-=-=-====----===--=--==-====-==---==-==-=-==-===--==[/b][/1] [2] "No trees were destroyed in the creation of this site, however, a significant number of electrons were terribly inconvenienced." - [black] Smile005[/black] :) ( [orange]Nexus005@yahoo.co.uk[/orange])[/b][/2][1] Chat by MSN: [/1] Nexus005@yahoo.co.uk[/b][/1], My new site: [orange]Marc Pritchard[/orange][/b], My joke site: [orange]www.rofljokes.co.uk[/orange][/b]
|
|
-
-
-
Smile005


- Joined on 06-17-2001
- United States

- Points 5,575
|
VB is not the language to do this in.
With C++ you could load a DLL named in a string but you can't with VB. There's no point dreaming about loading DLL's dynamically through VB.
Also VB you could create controls at run time but it would be harder than writing it in C++. You'd have to subclass the form and it would get very difficut.
I haven't got much time at the mo, but i'll post back with more in a day or two.
Hope it helps!
[1]  -==-==---==-=--=-==-===--===-=-=-====----===--=--==-====-==---==-==-=-==-===--==[/b][/1] [2] "No trees were destroyed in the creation of this site, however, a significant number of electrons were terribly inconvenienced." - [black] Smile005[/black] :) ( [orange]Nexus005@yahoo.co.uk[/orange])[/b][/2][1] Chat by MSN: [/1] Nexus005@yahoo.co.uk[/b][/1], My new site: [orange]Marc Pritchard[/orange][/b], My joke site: [orange]www.rofljokes.co.uk[/orange][/b]
|
|
-
-
-
fatwalrus


- Joined on 02-17-2005

- Points 5
|
Another way of removing excess spaces
I included a code extract here but you have to click on "read comments" to see it all.
Basically it just searches the text string for 2 spaces in row, and replaces it with one space, then repeats until theres arent any double spaces left.
Private Sub MyString_AfterUpdate()
Dim MyString
Dim Done
MyString = " " & MyString 'adds a space at the start and end of the string (important but difficult to explain)
Do Until Done 'removes excess spaces in the text string
If InStr(1, MyString, " ") = 0 Then
Done = True
Else
MyString = Replace(MyString, " ", " ")
End If
Loop
MyString_len = Len(MyString)
MyString = Right(MyString, MyString_len - 1) 'removes any spaces at the front, there should always be one at this point (thats why we added one at the start).
MyString = UCase(MyString) ' converts to uppercase (optional)
Me.MyString = MyString
End Sub
I know it is a long winded way of doing it, but the advantage is that it removes the spaces; before, after, and reduces any excess spaces within a string down to just 1 space each time. " camel dog fish cat " to "camel dog fish cat". Yep im sure my repeated use of "MyString" as a variable is "bad" but it works.
|
|
-
-
-
KöllMorgan


- Joined on 01-13-2007

- Points 15
|
Re: [69] String Functions
Hello!
Wonderful, helpful site, by the way...
I am working on a small program for a friend and noticed the below code. Works flawlessly, accept that it is not selecting the first word in a Text. I have attempted different tactics to get it to do what I would like to no avail. Can you assist me?
Sub Command1_Click() ' Get the first occurrence of the string StringPos = InStr(1, txtSearchString, txtFindString, vbTextCompare) If StringPos = 0 Then ' If StringPos returns 0, then the string is not found Msgbox "String not found" Else ' Get the length of the string to find StringLen = Len(txtFindString) ' Set the starting position of the selection txtSearchString.SelStart = StringPos ' Set the selection length txtSearchString.SelLength = StringLength End If End Sub
- txtSearchString collects, for instance, "Watch out for those manhole covers, they're loose; the woman before you almost fell in"
- txtFindString holds the text to find, thus "Watch"
I am not able to get the code to grab "Watch". If woman is searched, it is found. Is there anything else I need to do tom force VB 6.0 to output "Watch" as the first position in the text. Again, the code is excellent as is, just need it to do a bit more. txtSearchString.SelStart = StringPos -1 did not seem to work...Please advise.
Have a great week-end!
KöllMorgan
|
|
-
-
KöllMorgan


- Joined on 01-13-2007

- Points 15
|
Re: [69] String Functions
Replying to my own post...Hiya!
I found out the trick to grabbing the first word in the string using the above code:
InStr(1," " & YourString & " ", " " & YourSearchString & " ", vbBinaryCompare)
Here in the problem we're now facing. I am not able to read the first word on the next line. say we had:
- Watch out for those manholes covers, they're loose,
- the woman before you almost fell in
Watch (first line) gets picked up
the (second line) does not
I have been asking around about this. Will continue toying around with the code and will report my findings. Any sort of hints you have, I'll play around with it see what happens.
Thanks for your assistance. In a bit!
KöllMorgan
|
|
-
-
KöllMorgan


- Joined on 01-13-2007

- Points 15
|
Re: [69] String Functions
Here we go again:
After hours of debugging, I found out the only instance the first word on the second line does not get picked up is when I physically tab or hit enter and enter or type additional text. In a multiline textbox if VB forces text to next line, the first word will get picked on that second line. So to VB the text is seemingly one straight line though it it adds the additional text below because the textbox ran out of room. Hopefully this makes sense...We're good now. Thanks for reading :-)
|
|
|
Search
Code Samples
New Members
|