Results 1 to 9 of 9

Thread: Very long String problem....

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Very long String problem....

    Trying to store a long long list of x y coordinates. This can be done in a comma delimted file and read into VB ....but I dont want to have a seperate file outside the exe file...

    The string is eg. string = "300 400, 234 345, 233 235 "
    Except the string is very very long series of co ordinates, I cannot simply cut and paste this into the code it seems it is far to long to include this way...

    .....what can i do? im used to actionscript.. lol

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Very long String problem....

    Welcome to the forums.

    If you don't want to use any form of external file, then I would look into using a Resource File.

    Are you familiar with VB Resource Files?

  3. #3
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Very long String problem....

    I would definitely use a Resource file, I would also not store them as a string, I would store them in an array of the appropriate numerical data type. Perhaps Integer, that would cover you if all the coords were within the range -32,768 to 32,767. It would take up much less memory and you could process the numbers much quicker.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Very long String problem....

    Hopefully this will help.

    Cyborg's Resource File Tutorial

  5. #5
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Very long String problem....

    I was thinking more on the lines of raw array data stored in an embedded *.RES.
    That tutorial, as good as it is, is for making a custom resource file which presumably is not embedded into the executable. I'll post a little project with some embedded string and array data later tonight (GMT) if anyone is interested.

    Edit: Embedded Res file example. I did not bother with any string data but I really think numbers should be stored as numbers. It's fairly crude but it should be enough to get you going. I enjoyed making it, I hope it helps.
    Attached Files Attached Files
    Last edited by Milk; Mar 8th, 2007 at 09:23 PM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Re: Very long String problem....

    Thanks guys, I setup a res file and put in a string (for now) and its all recognised and working.

    ...with regards to storing as an integer / array..



    For Array - Dont I have to have a string / integer to feed to the array? I cant just eg. define array(100-200,200-300, 400-500)

    For integer, I take it i just amend my existing As string statements to as Integer .. ?

  7. #7
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Very long String problem....

    It should not be to much trouble to convert the string to an array. How about...
    vb Code:
    1. Option Explicit
    2.  
    3. Private Type iCoordinate2D
    4.  X As Integer
    5.  Y As Integer
    6. End Type
    7.  
    8. Dim iCoord() As iCoordinate2D
    9.  
    10. Private Sub Form_Load()
    11.  GetCoords ("100-200,200-300,400-500") 'or load it from a file, control or a RES.
    12. End Sub
    13.  
    14. Private Sub GetCoords(CoordString As String)
    15.  Dim StrCoord() As String
    16.  Dim StrXY() As String
    17.  Dim i As Long
    18.  StrCoord() = Split(CoordString, ",")
    19.  ReDim iCoord(UBound(StrCoord))
    20.  For i = 0 To UBound(StrCoord)
    21.   StrXY = Split(StrCoord(i), "-")
    22.   iCoord(i).X = CInt(StrXY(0))
    23.   iCoord(i).Y = CInt(StrXY(1))
    24.   'Debug.Print iCoord(i).X, iCoord(i).Y
    25.  Next i
    26. End Sub
    What are the coords for anyway?

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Re: Very long String problem....

    These coords are mouse cursor movement coords, the res is loaded in as a string and split into an array.


    ..what I mean is that I can get it all working at the moment, with a RES file loading in as a string into VB and then converting it into a array. same as you hav

    someone above said it is better to load it from the res as an integer?.. as it takes less memory space and generally handles better than if it was set as string type.

    is this just a case of chaning :

    From :
    CoordString As String to CoordString As Integer ?..

  9. #9
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Very long String problem....

    Quote Originally Posted by spikeuk25
    CoordString As String to CoordString As Integer?..
    Afraid not, CoordString As Integer will give you a single integer.

    There are three bits of code posted here which I hope you can use/modify for your project. Two little projects in the attached zip and that snip just above. All the examples are using an array of a user defined type where each array element consists of two integers, X and Y. So in these same examples to find out what coordinate 17 was I could type debug.print iCoord(17).X, iCoord(17).Y
    The above snip cuts a string up into an array of X and Y Integers, the first project in the zip saves these same arrays to disk, the second project extracts these arrays from the RES.

    Do you follow?
    Last edited by Milk; Mar 9th, 2007 at 05:06 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