Author |
Topic: output to gui problem formating numbers (Read 425 times) |
|
hammerjit
New Member
member is offline
Posts: 26
|
|
output to gui problem formating numbers
« Thread started on: Jun 17th, 2015, 08:44am » |
|
Hi, I am having problem with this. My text file sample is like this
Jones, Joyce, 22, 5.6 Newman, Bill, 26, 0.35 Abercrombe, Tom Cruise, 35, 1254.25 Belton, Mindy, 28, 1245687.8 Doyle, Barbara, 15, 1040.05
I want to output to gui and format the last columns as "#,###,###.##"
My code (as below) when executed only show value for first record and the balance rows are blank.
Can someone help me out?
Code:
c=0
dim last$(50),first$(50),age$(50),phone$(50)
dim recnum(50)
nomainwin
WindowWidth = 688
WindowHeight = 575
statictext #main.statictext1, "StaticText Caption", 38, 66, 100, 440
statictext #main.statictext2, "StaticText Caption", 148, 66, 100, 440
statictext #main.statictext3, "StaticText Caption", 248, 66, 100, 440
statictext #main.statictext4, "StaticText Caption", 348, 66, 100, 440
open "Showing Records directly from File" for window as #main
print #main, "font ms_sans_serif 0 16"
open "C:\myTestData.txt" for input as #fo
c=0
while eof(#fo)=0
c=c+1
input #fo, name$
last$(c)=name$
input #fo, name$
first$(c)=name$
input #fo, q$
age$(c)=q$
input #fo, q$
phone$(c)=q$
wend
close #fo
recnum=c
showRec1$=""
showRec2$=""
showRec3$=""
showRec4$=""
for i=1 to recnum
showRec1$=showRec1$+last$(i)+chr$(10)+chr$(13)
showRec2$=showRec2$+first$(i)+chr$(10)+chr$(13)
showRec3$=showRec3$+age$(i)+chr$(10)+chr$(13)
showRec4$=showRec4$+phone$(i)+chr$(10)+chr$(13)
next i
print #main.statictext1,showRec1$
print #main.statictext2,showRec2$
print #main.statictext3,showRec3$
print #main.statictext4,using("###,###.##",showRec4$)
[main.inputLoop] 'wait here for input event
wait
END
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: output to gui problem formating numbers
« Reply #1 on: Jun 17th, 2015, 10:42am » |
|
on Jun 17th, 2015, 08:44am, hammerjit wrote:Hi, I am having problem with this. |
|
I can see a few problems with your code. Firstly, your CRLF sequences are in the wrong order (you are using LFCR!). Change them to:
Code: Secondly you are passing a string instead of a number to the USING function here:
Code:using("###,###.##",showRec4$) Thirdly you seem to be hoping that USING() can format a whole list of numbers in one go. It can't - it can only format a single number. So you will need to call USING() for each value in the list; this is most easily done when you construct the list:
Code:showRec4$=showRec4$+using("###,###.##",val(phone$(i)))+chr$(13)+chr$(10) Richard.
|
|
Logged
|
|
|
|
hammerjit
New Member
member is offline
Posts: 26
|
|
Re: output to gui problem formating numbers
« Reply #2 on: Jun 18th, 2015, 06:22am » |
|
Thanks Richard, that was a great help. Got it to work.
|
|
Logged
|
|
|
|
hammerjit
New Member
member is offline
Posts: 26
|
|
Re: output to gui problem formating numbers
« Reply #3 on: Jun 19th, 2015, 07:02am » |
|
Hi Richard, supposedly with this same code and text file, I want to display each record in 2 lines, can it be done?
eg
<first line>Jones Joyce <2nd line> 22 5.6 <blank line> <3rd line>Newman Bill <4th line> 26 0.35 <blank line> etc....
Asking this since in my actual data, I want to display 15 columns and it is not wide enough currently
Or is there another possible solution?
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: output to gui problem formating numbers
« Reply #4 on: Jun 19th, 2015, 07:32am » |
|
I think you better have it scrolled. You can use Listbox and use Stylebits to add horisontal scrollbar (I just found stylebits at LB forum - I do not use them so have no idea) Code:' Form created with the help of Freeform-J v.261006
' Generated on Jun 19, 2015 at 10:17:41
nomainwin
WindowWidth = 328
WindowHeight = 310
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
N=40 'as big as you need
dim array$(N)
listbox #main.listbox1, array$(, [listbox1DoubleClick], 22, 16, 272, 250
Stylebits #main.listbox1, _WS_HSCROLL, 0,0, 0
open "untitled" for window as #main
print #main, "trapclose [quit.main]"
print #main, "font courier_new 8" 'you need monospaced font so columns neatly stack up
'populate listbox array. Make it big (run several times)
for k = 1 to 5
restore
for i = 1 to 5
j=j+1
read a1$, a2$, n1, n2
array$(j)=padr$(a1$,12)+padr$(a2$,10)+" "+using("###",n1)+" "+using("#######.##",n2)
next
next
'reload listbox
#main.listbox1 "reload"
wait
[quit.main]
Close #main
END
[listbox1DoubleClick] 'Perform action for the listbox named 'listbox1'
'Insert your own code here
wait
data Jones, Joyce, 22, 5.6
data Newman, Bill, 26, 0.35
data Abercrombe, "Tom Cruise", 35, 1254.25
data Belton, Mindy, 28, 1245687.8
data Doyle, Barbara, 15, 1040.05
'-------------------------------
'adds spaces from the left until 'n' symbols
'if n<len(a$) returns left$(a$,n)
function padl$(a$,n)
padl$ = left$(space$(n-len(a$))+a$,n)
end function
'adds spaces from the right until 'n' symbols
'if n<len(a$) returns left$(a$,n)
function padr$(a$,n)
padr$ = left$(a$+space$(n-len(a$)),n)
end function
|
|
Logged
|
|
|
|
|