Results 1 to 6 of 6

Thread: Help me in this coding in VB

  1. #1

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Help me in this coding in VB

    Hello sir,
    Help me in this coding
    My recordset contains 11-2, 5-2, 5, 6 datas in no1 field
    I used the below coding to search and replace it with but not working properly.


    Private Sub Command1_Click()
    rs.Open "check1", db, 3, 2

    Dim TestString As String
    TestString = rs.Fields("no1")


    Dim aString As String

    aString = Replace(TestString, "*-*", "*/*")
    MsgBox aString

    End Sub

    The output i got is only 11-2

    Thank you sir.

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Help me in this coding in VB

    Replace(TestString,"-","/")
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: Help me in this coding in VB

    Hello sir,
    I changed that, but it is checking for only first data in recordset
    I need to check for all datas in recordset

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Help me in this coding in VB

    Loop thru the recordset
    Code:
    Do While rs.EOF=False
        ... do stuff
        rs.MoveNext
    Loop
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: Help me in this coding in VB

    Quote Originally Posted by LaVolpe
    Loop thru the recordset
    Code:
    Do While rs.EOF=False
        ... do stuff
        rs.MoveNext
    Loop
    I used this code and i got the answer and now what i need is
    The coding is checking and replacing only "-" and "/".
    (ie) 11-2 becomes 11/2
    But the same recordset also contains data like this 5,6,7 etc
    i need this to be replaced by 5/1, 6/1, 7/1 etc
    Pls help me in this coding.
    Thank you sir.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Help me in this coding in VB

    Well, you will need to do 2 things.
    1. If there is a dash then replace it with a slash
    2. If there is not a dash then add /1
    Simply test it first: If InStr(TestString,"-") Then replace else add /1
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width