Page 1 of 1

Posted: Mon May 13, 2002 1:25 pm
by BackupUser
Restored from previous forum. Originally posted by willinyork.

Hi there. I am having some trouble with strings :( Basically, I have a file which consists of one large string like this:

VOL10199VOL20147VOL301100VOL401100VOL50121VOL6017VOL701100VOL801100

and this string should break down like this:

VOL101 99 VOL201 47 VOL301 100 VOL401 100 VOL501 21 VOL601 7 VOL701 100 VOL801 100

the "vol101" etc are the "dividers" in the file. The numbers inbetween each divider could be either 1, 2, or 3 digits long. Is it possible to read the value between the dividers into some variables? I wrote some code like this:

vol101start=FindString(qlbfile$,"VOL101",0)+6
vol201start=FindString(qlbfile$,"VOL201",0)+6

vol101end=vol201start-1

sound101vol$=Mid(qlbfile$,vol101start,vol101end)
sound101vol=Val(sound101vol$)

but it closes my app when I open a window which displays the value of "sound101vol". Likewise it closes the PB debugger if I open the "display variables" window.

Any advice would be appreciated, I am very confused!

Posted: Mon May 13, 2002 2:42 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

You are using MID wrong. Change you formula to something like this...


qlbfile$="VOL10199VOL20147VOL301100VOL401100VOL50121VOL6017VOL701100VOL801100"

vol101start=FindString(qlbfile$,"VOL101",1)
vol201start=FindString(qlbfile$,"VOL201",1)
vol101end=(vol201start-1)-(vol101start+5)

vol301start=FindString(qlbfile$,"VOL301",1)
vol201end=(vol301start-1)-(vol201start+5)

vol401start=FindString(qlbfile$,"VOL401",1)
vol301end=(vol401start-1)-(vol301start+5)

; etc ...

sound101vol$=Mid(qlbfile$,vol101start+6,vol101end)
sound201vol$=Mid(qlbfile$,vol201start+6,vol201end)
sound301vol$=Mid(qlbfile$,vol301start+6,vol301end)

MessageRequester("",sound101vol$+Chr(10)+sound201vol$+Chr(10)+sound301vol$,0)


This is a quick working example. You could probably use loops to reduce the amount of code.

Posted: Mon May 13, 2002 2:50 pm
by BackupUser
Restored from previous forum. Originally posted by jreimers.
Hi there. I am having some trouble with strings :( Basically, I have a file which consists of one large string like this:
Hello willinyork, this should do it:


; wherever this string comes from
a$="VOL10199VOL20147VOL301100VOL401100VOL50121VOL6017VOL701100VOL801100VOL901345"

Structure volumes
volstring.s
volvalue.l
EndStructure
NewList my.volumes()
startpos = FindString(a$,"VOL", 0)

;CallDebugger (be careful with this loop)
While startpos
AddElement(my())
help$ = Mid(a$,startpos,6)
my()\volstring = help$
helppos = FindString(a$, "VOL" , startpos+6)

If helppos = 0 ; Important for last element!
my()\volvalue = Val(Mid(a$,startpos+6,Len(a$)+1-(startpos+6)))
Else
my()\volvalue = Val(Mid(a$,startpos+6,helppos-(startpos+6)))
EndIf
startpos = helppos
Wend

OpenConsole()
ResetList(my())

While NextElement(my())
PrintN(my()\volstring+" = "+Str(my()\volvalue))
Wend
PrintN("Press a key ...")
Input()
CloseConsole()

greeting jreimers