We need you!

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

MaximumASP

Info

[69] String Functions

Last post 01-14-2007 5:00 PM by KöllMorgan. 24 replies.
Page 2 of 2 (25 items) < Previous 1 2
Sort Posts: Previous Next
  • 05-06-2003 5:34 PM In reply to

    Hmm, sounds like a plan. Basically the users would just write VB code and the program executes it? Cool, but is there some simple way for a user to create a form (like loading a .frm file and using it as an actual form) or would I have to have some datafile with positions for all the controls?
    • Post Points: 0
  • 05-07-2003 3:08 PM In reply to

    • Smile005
    • Top 10 Contributor
    • Joined on 06-17-2001
    • United States
    • Guru
    • 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]Beer-==-==---==-=--=-==-===--===-=-=-====----===--=--==-====-==---==-==-=-==-===--==[/b][/1]
    [2]"No trees were destroyed in the creation of this site, however, a significant number of electrons were terribly inconvenienced."

    Beer- [black]Smile005[/black] :) ([orange]Nexus005@yahoo.co.uk[/orange])[/b][/2][1]
    Chat by MSN: [/1]BeerNexus005@yahoo.co.uk[/b][/1],
    My new site: Beer[orange]Marc Pritchard[/orange][/b],
    My joke site: Beer[orange]www.rofljokes.co.uk[/orange][/b]
    • Post Points: 0
  • 05-07-2003 5:40 PM In reply to

    Aah, I see. Now, do I use VBScript or my own limited command system? Lol. I'ma go with the script here. But... Couldn't users just make custom DLLs with preset function names and my program call them? And as for the GUI, what do you suggest? This program is an editor for various games so they may need to make anything. If, say, a file contained the name of a control type, could I read that into a string and create that control on a form? I know I have a lot of questions but I've never made something like this before.
    • Post Points: 0
  • 05-08-2003 3:06 PM In reply to

    • Smile005
    • Top 10 Contributor
    • Joined on 06-17-2001
    • United States
    • Guru
    • 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]Beer-==-==---==-=--=-==-===--===-=-=-====----===--=--==-====-==---==-==-=-==-===--==[/b][/1]
    [2]"No trees were destroyed in the creation of this site, however, a significant number of electrons were terribly inconvenienced."

    Beer- [black]Smile005[/black] :) ([orange]Nexus005@yahoo.co.uk[/orange])[/b][/2][1]
    Chat by MSN: [/1]BeerNexus005@yahoo.co.uk[/b][/1],
    My new site: Beer[orange]Marc Pritchard[/orange][/b],
    My joke site: Beer[orange]www.rofljokes.co.uk[/orange][/b]
    • Post Points: 0
  • 02-25-2004 7:09 PM In reply to

    • gena_st
    • Not Ranked
    • Joined on 02-25-2004
    • New Member
    • Points 35

    Trim not working on variables

    I have a string set up as follows:
    bookTitle = "     Perelandra"

    I want to trim it down to be:
    bookTitle = "Perelandra"

    However, no variations on the Trim, LTrim and RTrim commands seem to work on the variables.  Is there code for trim the text stored in a variable?


    Edit: Under further analysis, I realized the the space before the title was actually a tab character.  Is there a way to time those off easily?
    • Post Points: 0
  • 02-17-2005 7:58 AM In reply to

    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.

    • Post Points: 0
  • 12-06-2005 12:58 PM In reply to

    i know i am answering to an oldest question left unanswered..

     but.. i just wanted to answer it..

     just for some one who is searching on a specific topic ...and end up in finding only questions...
     
    like wat i am doing now..

    dont try to trim "     perlandra"
    instead do this...
         bookTitle = "     Perelandra"
         booktitle=trim(booktiltle)
    ..
    bye,
    KOTI.
    • Post Points: 0
  • 01-13-2007 5:52 PM In reply to

    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

     

    • Post Points: 5
  • 01-14-2007 3:27 AM In reply to

    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

     

    • Post Points: 5
  • 01-14-2007 5:00 PM In reply to

    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 :-)

    • Post Points: 5
Page 2 of 2 (25 items) < Previous 1 2