PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How to Split Numbers?-VBForums
Results 1 to 11 of 11

Thread: How to Split Numbers?

  1. #1

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,613

    Exclamation How to Split Numbers?

    The VB split function doesn't seem to work with numbers.
    How do we split Numeric data and store it in a numeric array?

    e.g. I wish to get this working. Is there any quick way to do this other than looping and filling each element.

    VB Code:
    1. Dim nArray() As Long
    2. nArray = Split("12 8 234 234 234 234 8 456 09 23")
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to Split Numbers?

    Like this?
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim nArray(), x As Long, s$
    5.   nArray() = Array("12 8 234 234 234 234 8 456 09 23", " ")
    6.   For x = 0 To UBound(nArray)
    7.     s = s & nArray(x) & vbCrLf
    8.   Next x
    9.   MsgBox s
    10. End Sub

    I didn't convert it to LONG, but that's easy.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,683

    Re: How to Split Numbers?

    Dim nArray
    nArray = Split("12 8 234 234 234 234 8 456 09 23", " ")


    tested this, works ok
    the list of numbers has to be a string, convert them when you return them from the array

    pete

  4. #4

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,613

    Re: How to Split Numbers?

    Quote Originally Posted by dglienna
    Like this?
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim nArray(), x As Long, s$
    5.   nArray() = Array("12 8 234 234 234 234 8 456 09 23", " ")
    6.   For x = 0 To UBound(nArray)
    7.     s = s & nArray(x) & vbCrLf
    8.   Next x
    9.   MsgBox s
    10. End Sub

    I didn't convert it to LONG, but that's easy.
    Oh No! This is not what I want. Your code returns just 2 elements in the nArray (one with the same string and other with a blank space). I want all the 10 numbers discrete.

    In my first post, If we define nArray as String, it works. But I want nArray to be a numeric array instead of a String array.

    Westconn: It's the same thing. It is storing string in the Variant array. I just want a numeric array (to pass it to another function).
    Last edited by Pradeep1210; Jun 25th, 2005 at 03:51 AM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to Split Numbers?

    Sorry, I looked up split. I'll try to figure out with numerics.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim nArray$(), x As Long, s$, na() As Long
    5.   nArray() = Split("12 8 234 234 234 234 8 456 09 23", " ")
    6.   ReDim na(UBound(nArray))
    7.   For x = 0 To UBound(nArray)
    8.     na(x) = Val(nArray(x))
    9.     s = s & nArray(x) & vbCrLf
    10.   Next x
    11.   MsgBox s
    12. End Sub

    EDIT: You can use array() if each item is separated by ",", so maybe you could parse the items, and then use array?
    Last edited by dglienna; Jun 25th, 2005 at 04:04 AM.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,683

    Re: How to Split Numbers?

    VB Code:
    1. Sub mysub()
    2. Dim nArray, larray() As Long
    3. nArray = Split("12 8 234 234 234 234 8 456 09 23", " ")
    4. ReDim larray(UBound(nArray))
    5. For i = 0 To UBound(nArray)
    6.     larray(i) = CLng(nArray(i))
    7.     Next
    8.  
    9. End Sub

    pete

  7. #7

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,613

    Re: How to Split Numbers?

    David & Pete:
    Both the codes are much the same - Looping and filling the array with numeric values.
    Isn't there any way to do this in a line or two (like we Split strings in just one line!) ?

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,683

    Re: How to Split Numbers?

    i don't believe you you can have a list of numbers that are anything but a string, so somewhere you have to convert them after they are separated

    pete

  9. #9

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,613

    Re: How to Split Numbers?

    I remember one thread talking about changing the DataType of arrays without the need for another array. I can't locate that thread
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: How to Split Numbers?

    http://www.vbforums.com/showthread.php?t=316508

    Contains conversion functions and how to use the Split Function()

    I'm sure you can convert an array just liek you can convert a standard variable, AFAIK but i've not teste dit.

    Pino

  11. #11

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,613

    Re: How to Split Numbers?

    Quote Originally Posted by Pino
    http://www.vbforums.com/showthread.php?t=316508

    Contains conversion functions and how to use the Split Function()

    I'm sure you can convert an array just liek you can convert a standard variable, AFAIK but i've not teste dit.

    Pino
    Ohh.. there's nothing here that I want.

    The Split function returns a STRING array. I want this to be a LONG array. That's all.
    I remember a thread talking about changing the datatype of arrays using some API or something a few days back... but I can't locate that thread now.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width