|
Post by Mark Dunham on Apr 12, 2019 14:48:27 GMT -5
Is there a way to format text in the texteditor so it is justified. I want to make my text line up and look really clean. Thank you in advance for all the help. The xml file I am using is attached that will work with my code.
'THIS IS MY XML PARSER IT NEEDS MORE WORK 'BUT WILL WORK FOR NOW nomainwin
'ARRAY ITEMS$(ID,NAME,WEIGHT) dim items$(100,3) idcount = 1 namecount = 1 weightcount = 1 id$ = "002"
open "test.xml" for input as #xml myXML$ = INPUT$(#xml, LOF(#xml)) close #xml
parse$ = UPPER$(myXML$)
tagpos = INSTR(parse$, "<ID>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+4, endpos - tagpos-4) items$(idcount,1) = tag$ idcount = idcount + 1 tagpos = INSTR(parse$,"<ID>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<NAME>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+6, endpos - tagpos-6) items$(namecount,2) = tag$ namecount = namecount + 1 tagpos = INSTR(parse$,"<NAME>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<WEIGHT>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+8, endpos - tagpos-8) items$(weightcount,3) = tag$ weightcount = weightcount + 1 tagpos = INSTR(parse$,"<WEIGHT>",endpos)'NEEDED TO EXIT LOOP wend
'PRINT A SPECIFIC ITEMS NAME 'for x = 1 to idcount - 1 'if items$(x,1) = id$ then print items$(x,2) 'next x
'PRINT ALL ITEMS IN A NICE FORMAT 'print "ID:"; TAB(15); "Name:"; TAB(43); "Weight:" 'for i = 1 to idcount - 1 'print items$(i,1), items$(i,2), items$(i,3) 'next i
'end [Main] WindowWidth = 640 WindowHeight = 480
texteditor #Parse.Editor, 25, 25, 500, 300
open "Parsing XML" for window as #Parse #Parse, "trapclose [Parse.Quit]"
for i = 1 to idcount - 1 #Parse.Editor, items$(i,1); " "; items$(i,2); " "; items$(i,3) next i
wait
[Parse.Quit] close #Parse end
|
|
|
Post by Mark Dunham on Apr 16, 2019 15:55:00 GMT -5
So I have tried a few more things and I think I might be closer to formatting the text in the texteditor. I have changed how I am formatting the data before I display it in the texteditor. I am going to look at some other functions built in to see if I can get all the weights to line up in a nice column. If anyone has any input I would be glad to hear it. for i = 1 to idcount - 1 x = 5 List$ = SPACE$(x) + items$(i,1) + SPACE$(x) + items$(i,2) + SPACE$(x+10) + items$(i,3) #Parse.Editor, List$ '#Parse.Editor, " "; items$(i,1); " "; items$(i,2); " "; items$(i,3) next i
|
|
|
Post by Carl Gundel on Apr 16, 2019 20:14:27 GMT -5
So I have tried a few more things and I think I might be closer to formatting the text in the texteditor. I have changed how I am formatting the data before I display it in the texteditor. I am going to look at some other functions built in to see if I can get all the weights to line up in a nice column. If anyone has any input I would be glad to hear it. for i = 1 to idcount - 1 x = 5 List$ = SPACE$(x) + items$(i,1) + SPACE$(x) + items$(i,2) + SPACE$(x+10) + items$(i,3) #Parse.Editor, List$ '#Parse.Editor, " "; items$(i,1); " "; items$(i,2); " "; items$(i,3) next i
It helps a lot to use a monospaced font such as courier or lucida console. Most fonts are variable width and do not align well at all.
|
|
|
Post by Rod on Apr 17, 2019 2:24:20 GMT -5
You might also measure the maximum width needed for each data item.
'THIS IS MY XML PARSER IT NEEDS MORE WORK 'BUT WILL WORK FOR NOW nomainwin
'ARRAY ITEMS$(ID,NAME,WEIGHT) dim items$(100,3) idcount = 1 namecount = 1 weightcount = 1 id$ = "002"
open "test.xml" for input as #xml myXML$ = INPUT$(#xml, LOF(#xml)) close #xml
parse$ = UPPER$(myXML$)
tagpos = INSTR(parse$, "<ID>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+4, endpos - tagpos-4) length=len(tag$) if id<length then id=length items$(idcount,1) = tag$ idcount = idcount + 1 tagpos = INSTR(parse$,"<ID>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<NAME>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+6, endpos - tagpos-6) length=len(tag$) if nm<length then nm=length items$(namecount,2) = tag$ namecount = namecount + 1 tagpos = INSTR(parse$,"<NAME>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<WEIGHT>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+8, endpos - tagpos-8) length=len(tag$) if wt<length then wt=length items$(weightcount,3) = tag$ weightcount = weightcount + 1 tagpos = INSTR(parse$,"<WEIGHT>",endpos)'NEEDED TO EXIT LOOP wend
'PRINT A SPECIFIC ITEMS NAME 'for x = 1 to idcount - 1 'if items$(x,1) = id$ then print items$(x,2) 'next x
'PRINT ALL ITEMS IN A NICE FORMAT 'print "ID:"; TAB(15); "Name:"; TAB(43); "Weight:" 'for i = 1 to idcount - 1 'print items$(i,1), items$(i,2), items$(i,3) 'next i
'end [Main] WindowWidth = 640 WindowHeight = 480
texteditor #Parse.Editor, 25, 25, 500, 300
open "Parsing XML" for window as #Parse #Parse, "trapclose [Parse.Quit]" #Parse "font courier 12"
for i = 1 to idcount - 1 x = 5 List$ = items$(i,1) + SPACE$(id-len(items$(i,1))+1) + items$(i,2) + SPACE$(nm-len(items$(i,2))+1) + items$(i,3) #Parse.Editor, List$
next i wait
[Parse.Quit] close #Parse end
|
|
|
Post by Mark Dunham on Apr 17, 2019 7:16:54 GMT -5
So I have tried a few more things and I think I might be closer to formatting the text in the texteditor. I have changed how I am formatting the data before I display it in the texteditor. I am going to look at some other functions built in to see if I can get all the weights to line up in a nice column. If anyone has any input I would be glad to hear it. for i = 1 to idcount - 1 x = 5 List$ = SPACE$(x) + items$(i,1) + SPACE$(x) + items$(i,2) + SPACE$(x+10) + items$(i,3) #Parse.Editor, List$ '#Parse.Editor, " "; items$(i,1); " "; items$(i,2); " "; items$(i,3) next i
It helps a lot to use a monospaced font such as courier or lucida console. Most fonts are variable width and do not align well at all. Thank you Carl I will change the font so it is monospaced.
|
|
|
Post by Mark Dunham on Apr 17, 2019 7:20:17 GMT -5
You might also measure the maximum width needed for each data item. 'THIS IS MY XML PARSER IT NEEDS MORE WORK 'BUT WILL WORK FOR NOW nomainwin
'ARRAY ITEMS$(ID,NAME,WEIGHT) dim items$(100,3) idcount = 1 namecount = 1 weightcount = 1 id$ = "002"
open "test.xml" for input as #xml myXML$ = INPUT$(#xml, LOF(#xml)) close #xml
parse$ = UPPER$(myXML$)
tagpos = INSTR(parse$, "<ID>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+4, endpos - tagpos-4) length=len(tag$) if id<length then id=length items$(idcount,1) = tag$ idcount = idcount + 1 tagpos = INSTR(parse$,"<ID>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<NAME>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+6, endpos - tagpos-6) length=len(tag$) if nm<length then nm=length items$(namecount,2) = tag$ namecount = namecount + 1 tagpos = INSTR(parse$,"<NAME>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<WEIGHT>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+8, endpos - tagpos-8) length=len(tag$) if wt<length then wt=length items$(weightcount,3) = tag$ weightcount = weightcount + 1 tagpos = INSTR(parse$,"<WEIGHT>",endpos)'NEEDED TO EXIT LOOP wend
'PRINT A SPECIFIC ITEMS NAME 'for x = 1 to idcount - 1 'if items$(x,1) = id$ then print items$(x,2) 'next x
'PRINT ALL ITEMS IN A NICE FORMAT 'print "ID:"; TAB(15); "Name:"; TAB(43); "Weight:" 'for i = 1 to idcount - 1 'print items$(i,1), items$(i,2), items$(i,3) 'next i
'end [Main] WindowWidth = 640 WindowHeight = 480
texteditor #Parse.Editor, 25, 25, 500, 300
open "Parsing XML" for window as #Parse #Parse, "trapclose [Parse.Quit]" #Parse "font courier 12"
for i = 1 to idcount - 1 x = 5 List$ = items$(i,1) + SPACE$(id-len(items$(i,1))+1) + items$(i,2) + SPACE$(nm-len(items$(i,2))+1) + items$(i,3) #Parse.Editor, List$
next i wait
[Parse.Quit] close #Parse end
Rod, do you have an example you could post. I think I have an idea but sometimes a crumb helps. Thanks for the feedback as always.
|
|
|
Post by Rod on Apr 17, 2019 10:32:10 GMT -5
The code I posted is doing so it finds the maximum length of the data items and uses that and pads out spaces on the right to keep it all lined up.
|
|
|
Post by Mark Dunham on Apr 17, 2019 11:20:19 GMT -5
The code I posted is doing so it finds the maximum length of the data items and uses that and pads out spaces on the right to keep it all lined up. Doh, I will check it out thank you Rod. I think I need more sleep or coffee or both lol Cheers
|
|
|
Post by Mark Dunham on Apr 17, 2019 21:14:37 GMT -5
You might also measure the maximum width needed for each data item. 'THIS IS MY XML PARSER IT NEEDS MORE WORK 'BUT WILL WORK FOR NOW nomainwin
'ARRAY ITEMS$(ID,NAME,WEIGHT) dim items$(100,3) idcount = 1 namecount = 1 weightcount = 1 id$ = "002"
open "test.xml" for input as #xml myXML$ = INPUT$(#xml, LOF(#xml)) close #xml
parse$ = UPPER$(myXML$)
tagpos = INSTR(parse$, "<ID>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+4, endpos - tagpos-4) length=len(tag$) if id<length then id=length items$(idcount,1) = tag$ idcount = idcount + 1 tagpos = INSTR(parse$,"<ID>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<NAME>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+6, endpos - tagpos-6) length=len(tag$) if nm<length then nm=length items$(namecount,2) = tag$ namecount = namecount + 1 tagpos = INSTR(parse$,"<NAME>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<WEIGHT>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+8, endpos - tagpos-8) length=len(tag$) if wt<length then wt=length items$(weightcount,3) = tag$ weightcount = weightcount + 1 tagpos = INSTR(parse$,"<WEIGHT>",endpos)'NEEDED TO EXIT LOOP wend
'PRINT A SPECIFIC ITEMS NAME 'for x = 1 to idcount - 1 'if items$(x,1) = id$ then print items$(x,2) 'next x
'PRINT ALL ITEMS IN A NICE FORMAT 'print "ID:"; TAB(15); "Name:"; TAB(43); "Weight:" 'for i = 1 to idcount - 1 'print items$(i,1), items$(i,2), items$(i,3) 'next i
'end [Main] WindowWidth = 640 WindowHeight = 480
texteditor #Parse.Editor, 25, 25, 500, 300
open "Parsing XML" for window as #Parse #Parse, "trapclose [Parse.Quit]" #Parse "font courier 12"
for i = 1 to idcount - 1 x = 5 List$ = items$(i,1) + SPACE$(id-len(items$(i,1))+1) + items$(i,2) + SPACE$(nm-len(items$(i,2))+1) + items$(i,3) #Parse.Editor, List$
next i wait
[Parse.Quit] close #Parse end
Rod that looks awesome. It was exactly what I was trying to do thank you for the input as always I was thinking of something like that but I know it was going to be a ways off and maybe convoluted that solution is clean and simple. Thank you Cheers.
|
|
|
Post by Mark Dunham on Apr 18, 2019 15:20:58 GMT -5
With everyone's help my code is really cleaned up I am going to try to see what I can get working to add more entries to the XML file in the XML format that I have but we will see if I can get that working. This is still using the attached text.xml file I originally attached to my post. I did add functionality to remove the default texteditor edit menu thankls to Alyce's tutorial. Thanks Rod and Carl for the help with this.
'THIS IS MY XML PARSER IT NEEDS MORE WORK 'BUT WILL WORK FOR NOW nomainwin
'ARRAY ITEMS$(ID,NAME,WEIGHT) dim items$(100,3) idcount = 1 namecount = 1 weightcount = 1 id$ = "002"
open "test.xml" for input as #xml myXML$ = INPUT$(#xml, LOF(#xml)) close #xml
parse$ = UPPER$(myXML$)
tagpos = INSTR(parse$, "<ID>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+4, endpos - tagpos-4) length = len(tag$) if id < length then id = length items$(idcount,1) = tag$ idcount = idcount + 1 tagpos = INSTR(parse$,"<ID>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<NAME>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+6, endpos - tagpos-6) length = len(tag$) if nm < length then nm = length items$(namecount,2) = tag$ namecount = namecount + 1 tagpos = INSTR(parse$,"<NAME>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<WEIGHT>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+8, endpos - tagpos-8) length = len(tag$) if wt < length then wt = length items$(weightcount,3) = tag$ weightcount = weightcount + 1 tagpos = INSTR(parse$,"<WEIGHT>",endpos)'NEEDED TO EXIT LOOP wend
'PRINT A SPECIFIC ITEMS NAME 'for x = 1 to idcount - 1 'if items$(x,1) = id$ then print items$(x,2) 'next x
'PRINT ALL ITEMS IN A NICE FORMAT 'print "ID:"; TAB(15); "Name:"; TAB(43); "Weight:" 'for i = 1 to idcount - 1 'print items$(i,1), items$(i,2), items$(i,3) 'next i
'end.
[Main] WindowWidth = 640 WindowHeight = 480
statictext #Parse.st1, "ID", 25, 20, 20, 20 statictext #Parse.st2, "Description", 100, 20, 100, 20 statictext #Parse.st3, "Weight", 300, 20, 55, 20 texteditor #Parse.Editor, 25, 40, 500, 300
'textbox #Parse.Textbox, 25,40,500,300 'Stylebits #Parse.Textbox, _WS_VSCROLL OR _ES_MULTILINE, _ES_AUTOHSCROLL, 0, 0 menu #Parse, "&File","E&xit",[Parse.Quit] menu #Parse, "Edit"
open "Parsing XML" for window as #Parse #Parse, "trapclose [Parse.Quit]" #Parse.Editor, "!disable" #Parse, "font courier 12"
hMain=hWnd(#Parse) hMainMenu=GetMenu(hMain) hMainEdit=GetSubMenu(hMainMenu,1) result=RemoveMenu(hMainMenu,hMainEdit) Call DrawMenuBar hWnd(#Parse)
for i = 1 to idcount - 1 List$ = items$(i,1) + SPACE$(id-len(items$(i,1))+5) + items$(i,2) + SPACE$(nm-len(items$(i,2))+5) + items$(i,3) #Parse.Editor, List$ '#Parse.Editor, " "; items$(i,1); " "; items$(i,2); " "; items$(i,3) next i
wait
[Parse.Quit] close #Parse end
'functions: Sub DrawMenuBar hWnd CallDLL #user32, "DrawMenuBar",_ hWnd As ulong, r As boolean End Sub
Function GetSubMenu(hMenuBar,nPos) CallDLL #user32, "GetSubMenu",_ hMenuBar As ulong, nPos As long,_ GetSubMenu As ulong End Function
Function GetMenu(hWnd) CallDLL #user32, "GetMenu",hWnd As ulong,_ GetMenu As ulong End Function
Function RemoveMenu(hMenu,hSubMenu) CallDLL #user32, "RemoveMenu", hMenu As ulong,_ hSubMenu As ulong, _MF_BYCOMMAND As ulong,_ RemoveMenu As boolean End Function
|
|