|
-
September 13th, 2004, 10:25 AM
#1
String variable
How can I determine if a String variable contains a valid string? For numeric variables I can use IsNumeric, is there something similar for text?
-
September 13th, 2004, 10:28 AM
#2
Re: String variable
What do you consider a "valid string"? You could check for characters that you don't want or characters that you must have by using InStr.
I'd rather be wakeboarding...
-
September 13th, 2004, 10:52 AM
#3
Re: String variable
I would consider a valid string anything containing ascii codes 32 - 126.
1) How do I traverse through each letter in a string?
2) How do I convert a letter to an ascii code in vb?
My vb is a little rough I'm used to c++.
-
September 13th, 2004, 10:57 AM
#4
Re: String variable
You could try the following:
Code:
dim x as integer
dim strCharacter as string
dim lglValidString as boolean
for x = 1 to len(string)
strCharacter = mid$(string,x,1)
if asc(strCharacter) > 31 or asc(strCharacter) < 127 then
lglValidString = True
Else
lglValidString = False
Exit For
End If
Next
If Not lglValid String Then
......
End If
HTH
JP
JP
Please remember to rate all postings. 
-
September 13th, 2004, 11:03 AM
#5
Re: String variable
the following function replaces anything that is not in the range 0 to 9 or 'a' to 'z' with a minus sign:
Code:
Private Sub cleanseBackupComment()
backupComment = LCase$(backupComment)
backupComment = Replace$(backupComment, " ", "_")
'clean the comment up.. replace all chars not in 0 - 9 to a - z with a minus
Dim charNum As Integer
'up to 0
For charNum = &H0 To &H2F
backupComment = Replace$(backupComment, Chr$(charNum), "-")
Next charNum
'from 9 to underscore (5F)
For charNum = &H3A To &H5E
backupComment = Replace$(backupComment, Chr$(charNum), "-")
Next charNum
backupComment = Replace$(backupComment, Chr$(&H60), "-")
'from z to 255
For charNum = &H7B To &HFF
backupComment = Replace$(backupComment, Chr$(charNum), "-")
Next charNum
End Sub
the opposite of Chr$() is Asc()
supply chr with a number, it gives a character. supply chr$ with a number, it gives a string of that character, supply asc with a one char string and it gives a number of that string/char:
Chr$(32) -> " "
Asc(" ") -> 32
asc only works on the first given character, so Asc(" abc") only gives 32 for the initial space
AscW is the Unicode version
-
September 13th, 2004, 11:18 AM
#6
Re: String variable
Thanks that's exactly what I was looking for.
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
|