|
-
Oct 27th, 2005, 05:31 PM
#1
Thread Starter
New Member
Newb question plz answer
If i have a string such as "1A2D3B". If i want it to fetch the 1st, 2nd or 3rd number for the left and assign it to N. What code should i type in?
-
Oct 27th, 2005, 05:53 PM
#2
Fanatic Member
Re: Newb question plz answer
something like
VB Code:
n = Left(String, 1)
n = n & Left(String, 3)
n = n & Left(String, 5)
-
Oct 27th, 2005, 06:13 PM
#3
Frenzied Member
Re: Newb question plz answer
What is the purpose of this?
What is N?
How will the string be formatted?
Will the format always be the same?
Where do you get this string from?
What does it represent?
How should the numbers be 'assigned'?
Should each overwrite wha is in N?
Should they be added to eachother?
Should they lined up like Paralinx does?
You can test if a character is numeric with the function IsNumeric(String), which returns a boolean.
You can also test if the character's ascii code is within a certain range.
The ascii code can be obtained with Asc(Character) and is an integer.
-
Oct 27th, 2005, 07:40 PM
#4
Re: Newb question plz answer
What jeroen79 is trying to say is that if you are more specific with your question, we can help you a whole lot better. After all, we are programmers, not psychics. 
Also, specific yet breif thread titles get you even more help. "Newb question plz answer" isn't a good way to go, because there are many who ignor that thread just because it was called that. We had a discussion on this awhile back. It's in my signature located below in a link 
And to help you solve this, this is how you do it:
VB Code:
Option Explicit
Private Sub Form_Activate()
Dim N As String
Dim strVal As String
strVal = "1A2D3B"
N = Mid(strVal, 1, 1)
N = N & Mid(strVal, 3, 1)
N = N & Mid(strVal, 5, 1)
MsgBox N
End Sub
-
Oct 27th, 2005, 07:55 PM
#5
Re: Newb question plz answer
Also, for longer (or shorter) Strings then something like this may help:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim N As Long
N = Extract_Numerals("1A2D3B4C5D6789Z")
MsgBox N
End Sub
Private Function Extract_Numerals(ByVal strToConvert As String) As Long
Dim intCount As Integer
Dim intIdx As Integer
intCount = Len(strToConvert)
For intIdx = 1 To intCount
If IsNumeric(Mid$(strToConvert, intIdx, 1)) Then Extract_Numerals = Extract_Numerals & Mid$(strToConvert, intIdx, 1)
Next
End Function
Last edited by Bruce Fox; Oct 27th, 2005 at 08:01 PM.
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
|