Results 1 to 18 of 18

Thread: string contains 1 numeric character

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    string contains 1 numeric character

    Ugh.. could not figure this out. Can someone help me? How to check if an input string contains at least 1 numeric character?

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

    Re: string contains 1 numeric character

    Try this: If myString Like "*[0-9]*" Then ...
    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}

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: string contains 1 numeric character

    Also like this: If myString Like "*#*" Then
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: string contains 1 numeric character

    An alternative:
    Code:
    Dim MyString As String
    MyString = "hasdsjljx d4 kdkja z " ' Sample string
    For I = 48 To 57
        If InStr(MyString, Chr$(I)) Then
            MsgBox "MyString contains numeric character " & Chr$(I) & "."
            Exit For
        End If
    Next
    Doctor Ed

  5. #5
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: string contains 1 numeric character

    An alternative, but you don't drink bucks fizz when it's an alternative to champagne :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  6. #6
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: string contains 1 numeric character

    Quote Originally Posted by smUX View Post
    An alternative, but you don't drink bucks fizz when it's an alternative to champagne :-)
    But, once upon a time, Like did not exist. For ... Next, Instr() and Chr$() have been around for 25 years or so?
    Doctor Ed

  7. #7
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: string contains 1 numeric character

    Quote Originally Posted by Code Doc View Post
    But, once upon a time, Like did not exist. For ... Next, Instr() and Chr$() have been around for 25 years or so?
    But Like does exist, hence an alternative might not be that useful. I'll concede that there's a chance that they're writing in an early enough version of VB (no idea which that'd be, of course) that doesn't have Like in it, so it's an alternative, but normally when you evolve (for instance from instr/chr to Like) you don't use devoluted methods and stick with the most recent unless you're at a disadvantage (much like how many people feel about VB6 and upgrading to NET but we won't go into that :-))
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  8. #8
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: string contains 1 numeric character

    CD, it may not be the latest option but it's definitely clever.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  9. #9
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: string contains 1 numeric character

    Quote Originally Posted by CDRIVE View Post
    CD, it may not be the latest option but it's definitely clever.
    I don't see it clever at all. It looks like you just come back from Saturn.
    Can you tell when LIKE was first introduced in Visual Basic? Just last year? Before or after SELECT CASE?
    Quote Originally Posted by smUX
    don't drink bucks fizz when it's an alternative to champagne
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  10. #10
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: string contains 1 numeric character

    Quote Originally Posted by anhn View Post
    I don't see it clever at all. It looks like you just come back from Saturn.
    Well yes, a very astute observation.

    Insults aside, Doc's code may not be the best solution for this topic but I don't think it or I deserve the ridicule that seems to flow quite freely from some. Personally, I will keep Doc's code in mind because the concept may find use elsewhere.

    Here's a rule I try to live by.

    Don't gratuitously insult people that are not facing and standing directly in front of you, because it's the trade mark of a Weasel.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

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

    Re: string contains 1 numeric character

    I have to side with CDrive here. Lately, there has been sarcasm, flaming, degrading comments posted in responses to code freely provided.

    If the code is wrong, then point out the errors without slamming the poster.
    If the code is correct, point out a more efficient and/or easier method, but don't insult in the process.
    There is absolutely nothing wrong with being courteous, remember we are all volunteers here and of different levels of experience.

    With any language, many times there are multiple ways to say the same thing. It may not be the "best" way to say it, but if it isn't the wrong way, then maybe, just maybe, the end result will be that someone learned something new to them, whether they use it or not.

    Edited: I'm sure some of us are rather friendly with others and the sarcasm may be enjoyed by both parties when aimed at each other. But if you aren't acquaintances, then sarcasm is almost always interpreted as derogatory/insult by the receiver.
    Last edited by LaVolpe; Jan 14th, 2010 at 10:09 AM.
    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}

  12. #12
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: string contains 1 numeric character

    I agree completely with LV.

  13. #13
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: string contains 1 numeric character

    Quote Originally Posted by LaVolpe View Post
    If the code is wrong, then point out the errors without slamming the poster.
    If the code is correct, point out a more efficient and/or easier method, but don't insult in the process.
    Where does Code Doc's post fit in here, the original code was correct, but Doc's was not more efficient nor easier :-P

    Anyway, my intent toward Doc was merely joking around, he's entitled to post alternative answers...I was just pointing out how useful the suggestion was considering the fact that Like had already been posted.
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  14. #14
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: string contains 1 numeric character

    Quote Originally Posted by smUX View Post
    Anyway, my intent toward Doc was merely joking around, he's entitled to post alternative answers...I was just pointing out how useful the suggestion was considering the fact that Like had already been posted.
    Agree!
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  15. #15
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: string contains 1 numeric character

    Quote Originally Posted by anhn View Post
    I don't see it clever at all. It looks like you just come back from Saturn.
    Can you tell when LIKE was first introduced in Visual Basic? Just last year? Before or after SELECT CASE?
    Like appears to have been introduced with VB4 in 1995. Select Case goes back to at least VB3 which was introduced in 1991, but I'm not sure what relevance that has because I don't see that mentioned anywhere else in the thread.

    I only posted my alternative because I thought it was possible that OP had never used Like before and might be unfamiliar with it. Sorry to have upset so many apple carts by trying to be helpful.
    Doctor Ed

  16. #16
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: string contains 1 numeric character

    Quote Originally Posted by Code Doc View Post
    Like appears to have been introduced with VB4 in 1995. Select Case goes back to at least VB3 which was introduced in 1991, but I'm not sure what relevance that has because I don't see that mentioned anywhere else in the thread.
    A good research CodeDoc. I really don't know when.
    Perhaps LIKE was adapted from ANSI SQL.
    It seems SELECT CASE was in QBasic?
    I didn't mean to insult you, just make fun.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  17. #17
    Member
    Join Date
    Jan 2010
    Posts
    34

    Re: string contains 1 numeric character

    Quote Originally Posted by Code Doc View Post
    Like appears to have been introduced with VB4 in 1995. Select Case goes back to at least VB3 which was introduced in 1991, but I'm not sure what relevance that has because I don't see that mentioned anywhere else in the thread.

    I only posted my alternative because I thought it was possible that OP had never used Like before and might be unfamiliar with it. Sorry to have upset so many apple carts by trying to be helpful.
    nah select case goes way farther back.. to VB1 for DOS, and of course before that QuickBASIC and QBASIC.

    your way will do the trick. another (bad) alternative of course would be:

    Code:
    MyString$ = "blahblahblahblal345hjkb kdfg" 'sample string
    
    containsanumber = False
    For n = 1 To Len(MyString$)
      tempval = Asc(Mid$(MyString$, n, 1))
      If tempval > 47 And tempval < 58 Then containsanumber = True: Exit For
    Next n

  18. #18
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    Re: string contains 1 numeric character

    Begin using this code in this way...

    Code:
    Dim Item1 As Byte
    
    Public Sub Form_Load()
    Item1 = "0"
    
    End Sub
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

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