LB Booster
« output to gui problem formating numbers »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:20am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: output to gui problem formating numbers  (Read 424 times)
hammerjit
New Member
Image


member is offline

Avatar




PM


Posts: 26
xx 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
 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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:
chr$(13)+chr$(10) 

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.
User IP Logged

hammerjit
New Member
Image


member is offline

Avatar




PM


Posts: 26
xx 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.
User IP Logged

hammerjit
New Member
Image


member is offline

Avatar




PM


Posts: 26
xx 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?
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx 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
 
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls