|
-
Jan 13th, 2010, 01:40 PM
#1
Thread Starter
Frenzied Member
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?
-
Jan 13th, 2010, 01:50 PM
#2
Re: string contains 1 numeric character
Try this: If myString Like "*[0-9]*" Then ...
-
Jan 13th, 2010, 05:04 PM
#3
Re: string contains 1 numeric character
Also like this: If myString Like "*#*" Then
-
Jan 13th, 2010, 08:14 PM
#4
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
-
Jan 13th, 2010, 08:42 PM
#5
PowerPoster
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.
-
Jan 13th, 2010, 09:55 PM
#6
Re: string contains 1 numeric character
 Originally Posted by smUX
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?
-
Jan 13th, 2010, 10:29 PM
#7
PowerPoster
Re: string contains 1 numeric character
 Originally Posted by Code Doc
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.
-
Jan 14th, 2010, 12:16 AM
#8
-
Jan 14th, 2010, 07:55 AM
#9
Re: string contains 1 numeric character
 Originally Posted by CDRIVE
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?
 Originally Posted by smUX
don't drink bucks fizz when it's an alternative to champagne
-
Jan 14th, 2010, 09:36 AM
#10
Re: string contains 1 numeric character
 Originally Posted by anhn
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?? 
-
Jan 14th, 2010, 10:02 AM
#11
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.
-
Jan 14th, 2010, 10:33 AM
#12
Re: string contains 1 numeric character
I agree completely with LV.
-
Jan 14th, 2010, 12:23 PM
#13
PowerPoster
Re: string contains 1 numeric character
 Originally Posted by LaVolpe
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.
-
Jan 14th, 2010, 05:32 PM
#14
Re: string contains 1 numeric character
-
Jan 14th, 2010, 06:29 PM
#15
Re: string contains 1 numeric character
 Originally Posted by anhn
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.
-
Jan 14th, 2010, 10:22 PM
#16
Re: string contains 1 numeric character
 Originally Posted by Code Doc
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.
-
Jan 15th, 2010, 01:50 AM
#17
Member
Re: string contains 1 numeric character
 Originally Posted by Code Doc
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
-
Jan 15th, 2010, 05:35 AM
#18
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|