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
Re: Very long String problem....
Welcome to the forums. :wave:
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?
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.
Re: Very long String problem....
1 Attachment(s)
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.
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 .. ?
Re: Very long String problem....
It should not be to much trouble to convert the string to an array. How about...
vb Code:
Option Explicit
Private Type iCoordinate2D
X As Integer
Y As Integer
End Type
Dim iCoord() As iCoordinate2D
Private Sub Form_Load()
GetCoords ("100-200,200-300,400-500") 'or load it from a file, control or a RES.
End Sub
Private Sub GetCoords(CoordString As String)
Dim StrCoord() As String
Dim StrXY() As String
Dim i As Long
StrCoord() = Split(CoordString, ",")
ReDim iCoord(UBound(StrCoord))
For i = 0 To UBound(StrCoord)
StrXY = Split(StrCoord(i), "-")
iCoord(i).X = CInt(StrXY(0))
iCoord(i).Y = CInt(StrXY(1))
'Debug.Print iCoord(i).X, iCoord(i).Y
Next i
End Sub
What are the coords for anyway?
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 ?..
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?