Need Help With Some Visual Basic 6 Code.

DY357LXDY357LX Playing since day 1. Still can't Comm.England Join Date: 2002-10-27 Member: 1651Members, Constellation
edited June 2004 in Off-Topic
<div class="IPBDescription">Replacing Characters. Kinda Weird. Help?</div> I need help with some VB6 code. Yes I know VB sucks, blah
blah blah. Onto the request.

Example 1:
=======
If the user was type a URL into the URL bar, any gaps
they typed would be replaced with a dash ("-").
For example,:
www.natural selection.org would come out as
www.natural-selection.org see?


Example 2:
========
Lets say the user inputs the words:
"Hello I Am A Natural Selection Player"
into the text box. I need the output to
be displayed as:
"Hello-I-Am-A-Natural-Selection-Player".
So the spaces would be replaced with dashes.

Someone told me to use the Replace() function but I
don't know how to use it and Google hasn't turned up
anything useful. If you can help, please do so.
Example code would be great and i'll release the
program and source code here when its complete.
(Currently 90% complete, I need this code and some layout
alterations.) If you wish to guide me via PM, X-Fire or MSN
then feel free.
X-Fire: DY357LX
MSN : tylrdiablos-at-hotmail-dot-com
PM : The usual method
telekinesis: Move the pen next to my right speaker
and get it to write the code on notepad provided.

Please help poor DY :-/

Comments

  • CForresterCForrester P0rk(h0p Join Date: 2002-10-05 Member: 1439Members, Constellation
    edited June 2004
    Okay, it's a shot in the dark. (I know nothing about programming in VB) But give this a shot:

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->Replace(-, )<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    EDIT: Err, if you meant that you want to replace spaces with dashes:
    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->Replace( ,-)<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    <!--QuoteBegin-CForrester+Jun 13 2004, 12:01 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (CForrester @ Jun 13 2004, 12:01 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Okay, it's a shot in the dark. (I know nothing about programming in VB) But give this a shot:

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->Replace(-, )<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    EDIT: Err, if you meant that you want to replace spaces with dashes:
    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->Replace( ,-)<!--c2--></td></tr></table><div class='postcolor'><!--ec2--> <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    Nah, it just brings up a bunch of "Expected Expression" errors.
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    That's easy.

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->Dim x as String;
    x = "whatever.url.com/whatever"
    x = Replace(x, " ", "-")<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
  • CodemanCodeman Join Date: 2002-11-21 Member: 9497Members, Constellation, Reinforced - Shadow
    <a href='http://msdn.microsoft.com' target='_blank'>http://msdn.microsoft.com</a> is your friend.

    MSDN online is more up-to-date than the copies which ship with various products (including my old Visual C++ 6)
  • Hand_Me_The_Gun_And_Ask_Me_AgainHand_Me_The_Gun_And_Ask_Me_Again Join Date: 2002-02-07 Member: 178Members
    Will Visual Basic do regular expressions?
  • camO_ocamO_o Join Date: 2004-04-19 Member: 28028Members
    edited June 2004
    Function Replace(Expression As String, Find As String, Replace As String, [Start As Long = 1], [Count As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare]) As String

    say that strText = "www.natural-selection.org"
    strText = Replace (strText, "-", " ")

    you have to format it like so because Replace is a function, thus it returns a value when it's called, which is then placed into strText.

    edit: frigging guy with wierd avatar beat me :X
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    <!--QuoteBegin-Hand Me The Gun And Ask Me Again+Jun 13 2004, 05:56 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Hand Me The Gun And Ask Me Again @ Jun 13 2004, 05:56 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Will Visual Basic do regular expressions? <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    Yes but it takes some form of voodoo I believe.
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    <!--QuoteBegin-camO.o+Jun 13 2004, 12:23 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (camO.o @ Jun 13 2004, 12:23 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> edit: frigging guy with wierd avatar beat me :X <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    By like a whole day. :P
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    OK sorry to bring this back up.
    The code is working... kinda. Everytime I type a dash
    in a textbox the typing cursor goes back to the beginning
    of the textbox.
    So if I was to type
    "www.natural selection.org" it would display as
    "selection.orgwww.natural-"

    Er... can anyone tell me how to fix that please?
    I'm looking through the textbox fields but nothing
    seems to indicate this.
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    there is a function to set the cursor in the text box. Call that, and have it set the cursor to the end. What is the end you ask? The length of the string - 1.
Sign In or Register to comment.