Results 1 to 5 of 5

Thread: Newb question plz answer

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    1

    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?

  2. #2
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Newb question plz answer

    something like
    VB Code:
    1. n = Left(String, 1)
    2. n = n & Left(String, 3)
    3. n = n & Left(String, 5)

  3. #3
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    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.

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    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:
    1. Option Explicit
    2.  
    3. Private Sub Form_Activate()
    4.  
    5.     Dim N As String
    6.     Dim strVal As String
    7.  
    8.     strVal = "1A2D3B"
    9.  
    10.     N = Mid(strVal, 1, 1)
    11.    
    12.     N = N & Mid(strVal, 3, 1)
    13.    
    14.     N = N & Mid(strVal, 5, 1)
    15.    
    16.     MsgBox N
    17.  
    18. End Sub

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Newb question plz answer

    Also, for longer (or shorter) Strings then something like this may help:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim N As Long
    5.  
    6.     N = Extract_Numerals("1A2D3B4C5D6789Z")
    7.  
    8.     MsgBox N
    9.  
    10. End Sub
    11.  
    12. Private Function Extract_Numerals(ByVal strToConvert As String) As Long
    13. Dim intCount As Integer
    14. Dim intIdx As Integer
    15.  
    16.     intCount = Len(strToConvert)
    17.  
    18.     For intIdx = 1 To intCount
    19.         If IsNumeric(Mid$(strToConvert, intIdx, 1)) Then Extract_Numerals = Extract_Numerals & Mid$(strToConvert, intIdx, 1)
    20.     Next
    21.  
    22. 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
  •  



Click Here to Expand Forum to Full Width