Home | Reviews | GUIpedia | Forum | Fun500


izidorReading from a line
Before in my BASIC language one command was separated in few lines like: Code: line 10 10 200 200 1 and now I want to make it like this: Code: line>10,10,200,200,1 . I thought to do it with RIGHT$, LEFT$ and MID$, but there are more variables and they can have different values like 10 and 100 (but this could be solved if there would be 010 not 10). And I'm out of ideas. Could anyone help? I already posted this topic on Pete's QB site but nobody seems to respond and I know that here people know this kind of stuff so if anyone can help me please help.
2009-11-248:29 AM

BrandonRe:Reading from a line
Well if you want: [code]line,10,10,200,200,1[/code] then just use regular old INPUT #1, VAR$ and it will work like that. That's the easiest way, but if you truly want the > then you would use instr() which tells you how far to LEFT$,RIGHT$, or MID$. There's more info on that command: http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgInstr
2009-11-249:02 AM

izidorRe:Reading from a line
Thanks but I'm not sure that it will work in QB64.
2009-11-249:19 AM

BrandonRe:Reading from a line
Well the command will, the command is a QBASIC command, its also in FreeBASIC.
2009-11-249:26 AM

pharoahRe:Reading from a line
You might find my Qbasic version of PHP's explode() function helpful. If you give it a source string, a delimiter string, and an array, it fills the array with substrings that are cut apart using the delimiter. For example, if I gave it "hello|world|Qbrowse|wins" and made the delimiter "|" you'd get an array of: "hello", "world", "Qbrowse", "wins". Here's the code: [code] '$DYNAMIC DECLARE SUB explode (source$, delimiter$, destination$()) CLS DIM destiny$(1) parseme$ = "One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten" with$ = ", " explode parseme$, with$, destiny$() PRINT (UBOUND(destiny$) + 1); "substrings found:" FOR i = 0 TO UBOUND(destiny$) PRINT i; "==> "; destiny$(i) NEXT REM $STATIC SUB explode (source$, delimiter$, destination$()) '$DYNAMIC work$ = source$ delimiter.length% = LEN(delimiter$) DO IF LEFT$(work$, delimiter.length%) = delimiter$ THEN next.element$ = "" next.part = delimiter.length% + 1 IF next.part > LEN(work$) THEN work$ = "" ELSE work$ = MID$(work$, next.part) END IF ELSE loc.instr% = INSTR(work$, delimiter$) IF loc.instr% = 0 THEN next.element$ = work$ work$ = "" ELSE next.element$ = LEFT$(work$, loc.instr% - 1) next.part = loc.instr% + delimiter.length% IF next.part > LEN(work$) THEN work$ = "" ELSE work$ = MID$(work$, next.part) END IF END IF END IF old.ubound% = UBOUND(destination$) DIM dummy.array$(old.ubound% + 1) FOR x% = 0 TO old.ubound% dummy.array$(x%) = destination$(x%) NEXT IF substrings.found% > 0 THEN REDIM destination$(substrings.found%) END IF FOR x% = 0 TO old.ubound% destination$(x%) = dummy.array$(x%) NEXT ERASE dummy.array$ destination$(substrings.found%) = next.element$ substrings.found% = substrings.found% + 1 LOOP UNTIL work$ = "" END SUB [/code] A bit messy, but it works. Here's the tutorial I wrote to go with it (for QML News): http://docs.google.com/View?id=dg3rsr27_369xtfgpvss
2009-11-2410:58 AM

izidorRe:Reading from a line
Thank you Pharoah (I feel kinda strange saying it), but I will go with Brandon's way. Brandon, can you show me a example for VAR$ or some tutorial, please?
2009-11-243:50 PM

trollyRe:Reading from a line
[code] open "script.cmd" for input as 1 while not eof(1) readcmd: input #1,cmd$ select case cmd$ case "line": input #1,x1% input #1,y1% input #1,x2% input #1,y2% input #1,c% line (x1%,y%)-(x2%,y2%),c% case "rectangle": input #1,x1% input #1,y1% input #1,x2% input #1,y2% input #1,c% line (x1%,y%)-(x2%,y2%),c%,b ... case else goto readcmd end select wend close 1 [/code]
2009-11-243:57 PM

izidorRe:Reading from a line
I can't believe how simple this is, but thank you, thank you and once again thank you. Now I can finally have finish BBasic.
2009-11-244:43 PM

izidorRe:Reading from a line
You wont believe how stupid I am. While I was comparing yours(trolly's) and mine code I noticed that the only difference was you use SELECT CASE and I use IF. And because I always thought that with my code something like: [color=#FF0000]line,1,1,50,50,1[/color] won't work so I never tried it, but now i tried it and it works. I really feel like a fool now. Sorry for wasting your time people. :(
2009-11-244:52 PM

BASIC Programming Help


2021 Brandon Cornell