hello, here two new questions from my side:
a) "string$ function"
FUNCTION TBMAIN () AS LONG LOCAL msg AS STRING LOCAL l AS INTEGER msg = "thinBasic is a BASIC-Compiler." l = LEN(msg) MSGBOX msg MSGBOX 0, STRING$(l, "-") 'how to set an underline for a string ? ' for example : ' "thinbasic is a compiler" ' ------------------------- ' END FUNCTION
b) loop question (similar to a problem I try to convert from freebasic to thinbasic): how I can use this command "continue" to follow the loop for three search routines? Can anybody check if my idea with "continue = 1" is a good way?
bye, largoFUNCTION TBMAIN () AS LONG END FUNCTION '--------------------------------------------- FUNCTION filename(BYREF s AS STRING) AS STRING '============================================= DIM a AS LONG,b AS LONG, continue AS LONG DO a=b+1 '-- b=INSTR(a,s,":") : IF b THEN continue do ' original b=INSTR(a,s,":") : IF b THEN continue =1'do b=INSTR(a,s,"\") : IF b THEN continue =1'do b=INSTR(a,s,"/") : IF b THEN continue =1'do EXIT DO LOOP FUNCTION=MID$(s,a) END FUNCTION
Ad A)
Largo, you almost had it correct. Repeat$ function is what you need to build repeated string.
Ad 2)Function TBMain () As Long String msg = "thinBasic is a BASIC-like Interpreter." Long l = Len(msg) MsgBox 0, msg + $CRLF + Repeat$(l, "-") End Function
Option 1
The suggestion Jack just gave is very, very good. When translating code, the best is to use the resources of target language, not just convert line by line.
Option 2
If you would like robot-like translation, in thinBASIC it would look like:
Instead of C-like continue keyword, thinBASIC uses the iterate keyword.Function TBMain () As Long MsgBox 0, filename("C:\xFiles\Ufo.txt") ' -- Displays Ufo.txt End Function '--------------------------------------------- Function filename(s As String) As String '============================================= Long a, b Do a = b + 1 b = InStr(a, s, ":") : If b Then Iterate Do b = InStr(a, s, "\") : If b Then Iterate Do b = InStr(a, s, "/") : If b Then Iterate Do Exit Do Loop Function = Mid$(s,a) End Function
I personally dislike the name of continue keyword a lot. Why? Because when I read code, it looks like the code should continue on next line, but it does something different. The iterate keyword is a bit more specific in my opinion.
Option 3
Use the thinBASIC functions! Why write own function to extract file name, when you have it ready for use
Uses "file" Function TBMain () As Long MsgBox 0, FILE_PathSplit("C:\xFiles\Ufo.txt", %PATH_FILEEXT) ' -- Displays Ufo.txt End Function
Petr
Last edited by Petr Schreiber; 25-09-2012 at 17:24.
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
this will work
Alias Iterate As Continue
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
thank you all and for fast replies iterate is working here. thanks michael, jack for alternative ways. good to see that's more to learn for me. next questions will come about convertion of "cast" function (function=cast(long,a)) with peek or strptr/varptr problems here with freebasic to thinbasic. I will show my example next time. you're good guys here! bye,largo
Bookmarks