|
Post by angelo2449 on Jan 21, 2020 14:57:37 GMT -5
Hi Guys, I have to get a string with> TAB <.
How can I do?
Thank you.
|
|
|
Post by Rod on Jan 21, 2020 15:54:22 GMT -5
Chr$(9)?
|
|
|
Post by angelo2449 on Jan 21, 2020 17:53:09 GMT -5
Does not work
|
|
|
Post by metro on Jan 21, 2020 18:10:09 GMT -5
|
|
|
Post by Chris Iverson on Jan 21, 2020 19:45:10 GMT -5
CHR$(9) is the character for a tab. If it's not matching what text you're getting, then either that text isn't using tabs, or the text is being converted into something else before being passed to you.
Where are you getting the text from?
|
|
|
Post by tsh73 on Jan 22, 2020 2:05:43 GMT -5
some tests. How TAB (chr$(9)) is treated in textbox and texteditor. Code below, puts something like "abc"+chr$(9)+"ABC" then reads it back and types character by character. (also I tried removing printing - instead pasting "12"<TAB>"34", and see how it got character by character) So: textbox - * CHR$ from code looks like tab, behaves like tab (moving cursor jumps over it) * pasting from clipboard - looks like tab, behaves like tab So everything looks OK for me
texteditor - * CHR$ from code DOESNT't looks like there is anything (I see xyzXYZ), BUT 1) moving cursor shows like something like invisible space occupies half of X and cursor position moved half character after that - really may be my Windows issue? Win10 64) . 2) selecting, copying it and pasting to Notepad shows that indeed TAB is there
* pasting from clipboard - looks like tab, but moving cursor shows TAB got replaced by 4 spaces. Getting it from code and printing characters gor 4 chr$(32) (spaces). Copying it back copied 4 spaces.
So, LB texteditor doesn't like TABs that much.
nomainwin
WindowWidth = 464 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
textbox #main.textbox1, 26, 16, 100, 25 texteditor #main.texteditor2, 30, 56, 100, 100 button #main.button3, "Button Caption", [button3Click], UL, 142, 11, 122, 25 button #main.button4, "Button Caption", [button4Click], UL, 142, 51, 122, 25 texteditor #main.log, 150, 96, 296, 255 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "untitled" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
wait
[quit.main] Close #main END
[button3Click] 'Perform action for the button named 'button3' 'put text with TAB here 'read it back 'put to log #main.textbox1 "abc"+chr$(9)+"ABC" #main.textbox1 "!contents? var$" call toLog var$ wait
[button4Click] 'Perform action for the button named 'button4' #main.texteditor2 "xyz"+chr$(9)+"XYZ" #main.texteditor2 "!contents? var$" call toLog var$ wait
sub toLog var$ #main.log "Got:";var$ #main.log "-------------" for i = 1 to len(var$) c$=mid$(var$,i,1) #main.log i;" ";asc(c$);" ";c$ next #main.log "-------------"
end sub
results
Got:abc ABC ------------- 1 97 a 2 98 b 3 99 c 4 9 5 65 A 6 66 B 7 67 C ------------- Got:xyz XYZ
------------- 1 120 x 2 121 y 3 122 z 4 9 5 88 X 6 89 Y 7 90 Z 8 13
9 10
10 13
11 10
-------------
|
|
|
Post by angelo2449 on Jan 22, 2020 3:47:43 GMT -5
I tried with values from 1 to 255 but nobody inserts the> TAB <.
|
|
|
Post by tsh73 on Jan 22, 2020 4:05:25 GMT -5
code above, line #main.textbox1 "abc"+chr$(9)+"ABC" inserts real working TAB.
If your code doesn't work - show your code
|
|
|
Post by tsh73 on Jan 22, 2020 4:13:32 GMT -5
Also, CHR$(9) prints to file real TAB
' !! fix the filename to your taste fileName$="c:\stuff\2.txt" open fileName$ for output as #1 #1 "abc"+chr$(9)+"ABC" close #1
print "wait a second.." timer 1000, [nx] wait
[nx] timer 0
run "notepad.exe ";fileName$
|
|
|
Post by angelo2449 on Jan 23, 2020 17:24:27 GMT -5
Tanks ths73
|
|
|
Post by angelo2449 on Jan 24, 2020 2:56:21 GMT -5
I find it curious that direct printing gives the wrong result while the one on file the right one.
StringaIn$ = "1,chiodo,045.330675568N,008.573565683E,219.4669"
Pos1 = instr(trim$(StringaIn$), ",", 1) Pos2 = instr(trim$(StringaIn$), ",", Pos1 + 1) Pos3 = instr(trim$(StringaIn$), ",", Pos2 + 1) Pos4 = instr(trim$(StringaIn$), ",", Pos3 + 1) Pos5 = instr(trim$(StringaIn$), "#", Pos4 + 1)
S1$ = left$(StringaIn$, Pos1 - 1) S2$ = mid$(StringaIn$, Pos1 + 1, Pos2 - Pos1 - 1) S3$ = mid$(StringaIn$, Pos2 + 1, Pos3 - Pos2 - 1) S4$ = mid$(StringaIn$, Pos3 + 1, Pos4 - Pos3 - 1) S5$ = mid$(StringaIn$, Pos4 + 1)
' 1 ' chiodo ' 045.330675568N ' 008.573565683E ' 219.4669
if left$(S3$, 1) = "0" then S3$ = mid$(S3$, 2) end if
if left$(S3$, 1) = "0" then S3$ = mid$(S3$, 2) end if
if left$(S4$, 1) = "0" then S4$ = mid$(S4$, 2) end if
if left$(S4$, 1) = "0" then S4$ = mid$(S4$, 2) end if
' 1,chiodo,045.330675568N,008.573565683E,219.4669 ' 1, p1, ?, 45.320688277N, 8.590295419E, 208.725
Linea$ = S1$ + "," + chr$(9) + S2$ + "," + chr$(9) + "?," + chr$(9) + S3$ + "," + chr$(9) + S4$ + "," + chr$(9) + S5$
open "D:\AltProvvisori\Corretto.dat" for output as #1 print #1, Linea$ close #1
print S1$ print S2$ print S3$ print S4$ print S5$ print Linea$
|
|
|
Post by Rod on Jan 24, 2020 4:15:50 GMT -5
Are we confusing the TAB( function. This is quite different from the tab chr$(9)
TAB( function is used to format output in the mainwin or for printing.
|
|
|
Post by tsh73 on Jan 24, 2020 6:01:54 GMT -5
Hm, that's really interesting Here 's the code
PRINT "aa" + CHR$(9) + "BB" PRINT "aabbcc" + CHR$(9) + "BB" PRINT "aabbccdd" + CHR$(9) + "BB" PRINT "aabbccddee" + CHR$(9) + "BB" PRINT "aa" + CHR$(32) + "BB"
Results I see in LB mainwin console: TAB does not visible, SPACE - visble Moving over it with cursor keys shows nothing
aaBB aabbccBB aabbccddBB aabbccddeeBB aa BB
Results I see after cut'n'paste to Notepad: real TAB character, text after aligned to next 8th character, cursor jumps over all visible gap
aa BB aabbcc BB aabbccdd BB aabbccddee BB aa BB
QBASIC results (man, had to fire virtual machine) looks same as Notepad
C:\Program Files\QB>QBASIC.EXE aa BB aabbcc BB aabbccdd BB aabbccddee BB aa BB
Press any key to continue
|
|
|
Post by Rod on Jan 24, 2020 9:59:12 GMT -5
We started this discussion talking about strings, when in fact the task is to format text in the mainwin. Given we have been provided a function, tab(n) to tab in the mainwin that would suggest it does not know how to handle chr$(9). So the display cannot use the chr$(9) but it is not lost in the string.
I have not had time to check but we should look at the "filter bad characters" preferences flag to see if it makes a difference.
If I was formatting output for the mainwin I would either use a fixed width font and add spaces or use the , command. While I knew it existed I have never really used the tab(n) function.
'we can separate columns with tab(n), a comma, or spaces 'for spacing to work well best use a fixed width font PRINT "aa" + tab(20) + "BB" PRINT "aabbcc" + tab(20) + "BB" PRINT "aabbccdd" + tab(20) + "BB" PRINT "aabbccdd","BB","Note the , tabs a fixed amount each time." print "aabbccdd";" ";"BB" PRINT "aabbccddee" + tab(20) + "BB" PRINT "aa" + CHR$(32) + "BB"
|
|
|
Post by angelo2449 on Jan 24, 2020 14:07:12 GMT -5
OK all clear! I have tested string formatting in mainwin without doing it in any other way too. The discussion was however interesting and formative. Well done, thank you,
|
|