Board Logo
« Colour on Statictext / graphics »

Welcome Guest. Please Login or Register.
Nov 21st, 2009, 9:22pm



Conforums Terms of Service | Membership Rules | Home | Help | Search | Recent Posts | Notification | Format Your Message | Vista/Win7 FAQ

Please use the forums Search feature before asking. For best results select only the categories, which describe your need best.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is to long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.
To register at the Just BASIC Files Archive Site, please follow the instructions given in File Archives - Important Registration Information.

Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Colour on Statictext / graphics  (Read 233 times)
donjohnson24
New Member
Image

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 13
xx Colour on Statictext / graphics
« Thread started on: Oct 31st, 2009, 8:26pm »

Hi,

Having completed my RACENITE program I was encouraged to have a go at a QUIZ program that also needed updating.

Again it runs in mainwin, but occasionally, I would like to pop up a large window with the quiz round title writ large.

The following code seems to work, and enables me to just press any key to close the window. I stumbled around to get this code, but no doubt it can be improved or done a better way.

Two questions - how can I change the colour from black on white - I've tried every combination of commands from the help files, but nothing seem to work. Is it because I'm using statictext boxes?

The second question is about the focus not really being returned to the main screen after this subroutine, unless I press ENTER a couple of times. Is there something I've left out - other subroutines return OK.

Any help would be appreciated

Code:
[dsprdtitl]
    UpperLeftX = 20
    UpperLeftY = 200
    WindowWidth = 1200
    WindowHeight = 500
    statictext #graph.txt, "", 400, 100, 400, 100
    statictext #graph.txt1, "", 100, 200, 1000, 300
    open " " for graphics_nsb as #graph
    #graph "trapclose [quit]"
    print #graph, "when characterInput [quit]"
    print #graph, "setfocus"
    print #graph.txt, "!font arial_black 36 italic"
    print #graph.txt1, "!font arial_black 48"
    str$ = "Round  " + str$(rd)
    l = len(rdnm$)
    str1$ = ""
    l = (20 - l) / 2
    for i = 1 to l
        str1$ = str1$ + " "
    next i
    str1$ = str1$ + rdnm$(rd)
    #graph.txt, str$
    #graph.txt1, str1$
    input r$
    WAIT
    [quit]
    close #graph
    return
 
« Last Edit: Oct 31st, 2009, 8:34pm by donjohnson24 » User IP Logged

Don Johnson (not the Film Star!)
e-mail me: donjohnson24@btinternet.com
personal web: http://www.donjohnson24.co.uk
Psycho
Member in Training
ImageImage

member is offline

Avatar




PM

Gender: Male
Posts: 26
xx Re: Colour on Statictext / graphics
« Reply #1 on: Oct 31st, 2009, 11:47pm »

Since you're opening a graphics window, I would forget about the statictext and simply display your information with a graphic print statement ("\").
I threw some dummy code at the beginning of this to test the gosub and return. When running, the focus returned back to the main window after closing the graphic display.

Code:
    print "hello"
    input "Please hit enter ";d$
    gosub [dsprdtitl]
    input "Now we're back at the main window with focus ";d$
    wait

[dsprdtitl]
    UpperLeftX = 20
    UpperLeftY = 200
    WindowWidth = 1200
    WindowHeight = 500
    open " " for graphics_nsb as #graph
    #graph "trapclose [quit]"
    print #graph, "when characterInput [quit]"
    print #graph, "color red"
    print #graph, "place 350 250"
    print #graph, "font arial 72"
    str$ = "Round  " + str$(rd)
    l = len(rdnm$)
    str1$ = ""
    l = (20 - l) / 2
    for i = 1 to l
        str1$ = str1$ + " "
    next i
    str1$ = str1$ + rdnm$(rd)
    #graph, "\ ";str$
    #graph, "setfocus"
    input r$
    WAIT

[quit]
    close #graph
    return


 


John "Psycho" Siejkowski
User IP Logged

donjohnson24
New Member
Image

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 13
xx Re: Colour on Statictext / graphics
« Reply #2 on: Nov 1st, 2009, 1:48pm »

Thank you, John

This was just what I was trying to do, but could not print to a graphics window no matter what I tried.

I've searched the Help files again, but reference to using '\' as a graphic "print" statement eludes me. No wonder I couldn't make simple printing work.

With regard to the focus - this is probably a problem within the my program. If the call to the graphics window is followed by an 'input' statement, everything is as expected.

However, if it is followed by my 'get a single character input' function [getanswer] I have to press Enter twice to get entries to be accepted.

This is the function

Code:
[getanswer]
function geta(c,n)
        locate c, n
        print "?";
        a$ = input$(1)
        locate c, n
        print "  "
        geta = 0
end function
 


and this is segment that calls the graphics subroutine [dsprdtitl] - in two places: once when the quiz round is selected, and again if '9' selected as an action command.

A single keypress whilst the graphic window is displayed closes it and returns focus to mainwin.

The same effect - needing two 'Enter' s occurs after the graphics subroutine [dspwin] is called.

'r = geta(45,19)' is used below in place of ' input a$'

Code:
[[runquiz]
        gosub [menu4] 
        [inprd]
        locate 12,2
        print "           ";
        locate 13,2
        input a$
        r2$ = a$
        rd = val(r2$)
        if rd < 1 or rd > 10 then
            goto [inprd]
        end if
        locate 12,2
        print "           ";
        gosub [dsprdtitl]
        [rerun]
        locate 12,2
        print using ("##",rd)
        locate 22,2
        print rdnm$(rd);
        gosub [tmsdisp] ' display teams
        gosub [scdisp]  ' display scores
        if sc(rd,1) = 0 then  'no scores for this round yet
            for tm = 1 to 20   'so get some
                gosub [getscore]
            next tm
        end if
        [start1] 'await next action command
        r = geta(45,19)
        if upper$(a$) = "X" then
            return
        end if
        tm = instr(tm$, upper$(a$)) 'get Team No from letter
        if tm > 0 and tm < 21 then
            gosub [getscore] ' get a score for team selected
            goto [start1]
        end if
        r4$ = a$ ' now choose which action
        select case r4$
        case "0"
            goto [inprd]
        case "1"
            gosub [scdisp] '  display round scores
        case "2"
            gosub [rtotdisp]  'display running total scores
        case "3"
            gosub [gtotdisp]   ' total scores  for all rounds
        case "4"
            gosub [position] 'displays ranking of teams
            gosub [menu4]   ' then redisplays current screen
            goto [rerun]
        case "5"
            gosub [dsprdtitl]  'graphic display of round title
        case "6"
            gosub [dspwin]  ' graphics display of winners
        end select
        goto [start1]
    return

[menu4]
    cls
    locate 2,2
    print"Round No."
    locate 3,4
    print"('ENTER' retains 'old' data"
    locate 2,6
    print"Tm  Sc          Name            Tm  Sc           Name"
    locate 2,8
    print"A                               B"
    locate 2,9
    print"C                               D"
    locate 2,10
    print"E                               F"
    locate 2,11
    print"G                               H"
    locate 2,12
    print"I                               J"
    locate 2,13
    print"K                               L"
    locate 2,14
    print"M                               N"
    locate 2,15
    print"O                               P"
    locate 2,16
    print"Q                               R"
    locate 2,17
    print"S                               T"
    locate 15,19
    print "Round/Team/eXit (0/A - T/X)";
    locate 2,20
    print "1-Rnd Sc, 2-Run Tot, 3-Ovl Tot, 4-Leaders, 5-Rnd Tttl, 6-Win";
    return
 


As all of the action in this program is associated with keyboard entries, I try to make action selections possible with a single key entry, rather than a letter/number followed by Enter. For entering scores or team names, the normal 'input function is used.

Unfortunately, I have assumed that there will be 10 rounds, so single key entry for round selection is not possible. I'm considering reducing the rounds to nine . . . .

Any suggestions about my double 'Enter' requirement would be appreciated.

Don
« Last Edit: Nov 1st, 2009, 2:22pm by donjohnson24 » User IP Logged

Don Johnson (not the Film Star!)
e-mail me: donjohnson24@btinternet.com
personal web: http://www.donjohnson24.co.uk
Welopez
Moderator
ImageImageImageImageImage

member is offline

Avatar

Never underestimate the power of human stupidity. - Robert A. Heinlein


Homepage PM

Gender: Male
Posts: 3841
xx Re: Colour on Statictext / graphics
« Reply #3 on: Nov 1st, 2009, 2:03pm »

It might simplify matters if you used only the MAINWIN or only the graphics window, Don. Moving back and forth can get confusing, as well as requiring different syntax.

The method for printing text to a graphic window is in the helpfile. You just didn't search hard enough.
Quote:
print #handle, "\text"
This command displays the specified text at the current pen position. The text is located with its lower left corner at the pen position.

Each additional \ in the text will cause a carriage return and line feed. For example, print #handle, "\text1\text2" will cause text1 to be printed at the pen position, and then text2 will be displayed directly under text1.

also... print #handle, "|text"


This command works like print #handle, "\text" above, but uses the | character instead of the \ character, which allows display of the character a ( \ ).

Notice there is a difference between the backslash (\) and the forward slash (/).

Good luck to you!
User IP Logged

donjohnson24
New Member
Image

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 13
xx Re: Colour on Statictext / graphics
« Reply #4 on: Nov 1st, 2009, 2:17pm »

Yes, Mea Culpa - I have now found the print function, but I probably missed it as it appeared to be to do with pens . . . .

The use of / instead of \ was a typo - which I have now corrected.

The point of having the graphics window is to provide a large text display - with colour - as a reminder of the name of the round being played, and to display the winners for easy viewing. I'd do the whole thing in graphics - but can't get a single key entry function.

I can probably live with the double Enter thing, but I will keep on trying to solve it - perhaps with the help of you wise gurus out there

Thanks again for your help
« Last Edit: Nov 1st, 2009, 2:21pm by donjohnson24 » User IP Logged

Don Johnson (not the Film Star!)
e-mail me: donjohnson24@btinternet.com
personal web: http://www.donjohnson24.co.uk
Welopez
Moderator
ImageImageImageImageImage

member is offline

Avatar

Never underestimate the power of human stupidity. - Robert A. Heinlein


Homepage PM

Gender: Male
Posts: 3841
xx Re: Colour on Statictext / graphics
« Reply #5 on: Nov 1st, 2009, 3:04pm »

Here is an example of code which takes INPUT from a graphicbox located off screen, and prints text to the window for graphics. I know this is not precisely what you want to do... but it should point you in the right direction with no need to press the ENTER button.
Code:
WindowWidth=400
WindowHeight=400
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)

GRAPHICBOX #demo.gbx, 1000, 100, 20, 40

OPEN "Demo" FOR GRAPHICS_nsb AS #demo
PRINT #demo, "trapclose [quit]"
[loopHere]
PRINT #demo.gbx, "when characterInput [getIt]"
PRINT #demo.gbx, "setfocus"
WAIT
[getIt]
    key$ = Inkey$
    key$=UPPER$(key$)
    x=x+2
    y=y+14
    PRINT #demo, "PLACE "; x; " "; y
    PRINT #demo, "DOWN"
    PRINT #demo, "\";SPACE$(x);key$
    goto [loopHere]

WAIT
[quit]
    CLOSE #demo
    END
 
User IP Logged

donjohnson24
New Member
Image

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 13
xx Re: Colour on Statictext / graphics
« Reply #6 on: Nov 2nd, 2009, 10:36am »

Thanks for the suggestions, but the idea is to display a sort of 'pop-up' window to present information to the audience in larger/colourful text.

I'm happy for the program user to press 'Enter' to close the window, it was the extra couple of 'Enters' needed to get back to the correct point in the program after closing the window that was the problem.

It would appear that if the next input function is 'input a$' then everything works fine. However, if 'a$ = input$(1)' is used things are confused. Another factor may be that my 'a$ = input$(1)' is contained inside a function.

My solution has been to include the line 'Press ENTER to close window' in the window text, and to include 'input "Press Enter to Continue "; a$' after the call to the window subroutine. This gives a consistent action, no matter what form the next input statement has, so I'm happy.

Its' curious though . . . . . . huh

The full QUIZ program is in the Archive - again under Games.

Don



« Last Edit: Nov 2nd, 2009, 10:37am by donjohnson24 » User IP Logged

Don Johnson (not the Film Star!)
e-mail me: donjohnson24@btinternet.com
personal web: http://www.donjohnson24.co.uk
Welopez
Moderator
ImageImageImageImageImage

member is offline

Avatar

Never underestimate the power of human stupidity. - Robert A. Heinlein


Homepage PM

Gender: Male
Posts: 3841
xx Re: Colour on Statictext / graphics
« Reply #7 on: Nov 2nd, 2009, 11:36am »

Or it may be that you are using reserved words as variables in your code. Check the "Reserved Word List" in the help file. You may not get in trouble using them, no one will amputate your fingers, but your code will probably not behave as you want it to. When you write your code, reserved words should be avoided the way CIA field agents avoid TV cameras.
Quote:
AND, APPEND, AS, BEEP, BMPBUTTON, BMPSAVE, BOOLEAN, BUTTON, BYREF, CALL, CASE, CHECKBOX, CLOSE, CLS, COMBOBOX, CONFIRM, DATA, DIALOG, DIM, DO, DUMP, ELSE, END, ERROR, EXIT, FIELD, FILEDIALOG, FILES, FOR, FUNCTION, GET, GLOBAL, GOSUB, GOTO, GRAPHICBOX, GRAPHICS, GROUPBOX, IF, INPUT, KILL, LET, LINE, LISTBOX, LOADBMP, LONG, LOOP, LPRINT, MAINWIN, MAPHANDLE, MENU, NAME, NEXT, NOMAINWIN, NONE, NOTICE, ON, ONCOMERROR, OR, OPEN, OUTPUT, PLAYMIDI, PLAYWAVE, PRINT, PROMPT, PUT, RADIOBUTTON, RANDOM, RANDOMIZE, READ, READJOYSTICK, REDIM, REM, RESTORE, RETURN, RUN, SCAN, SELECT, STATICTEXT, STOP, STOPMIDI, SUB, TEXT, TEXTBOX, TEXTEDITOR, THEN, TIMER, UNLOADBMP, UNTIL, WAIT, WINDOW, WEND, WHILE, WORD, XOR

FUNCTIONS:

Note that the opening parenthesis is part of the function name:

ABS(, ACS(, ASC(, ASN(, ATN(, CHR$(, COS(, DATE$(, EOF(, EXP(, INPUT$(, INSTR(, INT(, LEFT$(, LEN(, LOF(, LOG(, LOWER$(, MIDIPOS(, MID$(, MKDIR(, NOT(, RIGHT$(, RMDIR(, RND(, SIN(, SPACE$(, SQR(, STR$(, TAB(, TAN(, TIME$(, TRIM$(, TXCOUNT(, UPPER$(, USING(, VAL(, WORD$(

a$=INPUT$(1) would be a no-no. sad
« Last Edit: Nov 2nd, 2009, 11:37am by Welopez » User IP Logged

tsh73
Senior Member
ImageImageImageImageImage

member is offline

Avatar




PM

Gender: Male
Posts: 931
xx Re: Colour on Statictext / graphics
« Reply #8 on: Nov 2nd, 2009, 12:36pm »

Quote:
It would appear that if the next input function is 'input a$' then everything works fine. However, if 'a$ = input$(1)' is used things are confused. Another factor may be that my 'a$ = input$(1)' is contained inside a function.


I tested, it works the same even without a function.
Probably it's a bug sad
(though it may never be intended to return to mainwindow, though)
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
donjohnson24
New Member
Image

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 13
xx Re: Colour on Statictext / graphics
« Reply #9 on: Nov 3rd, 2009, 11:35am »

on Nov 2nd, 2009, 11:36am, Welopez wrote:
a$=INPUT$(1) would be a no-no. sad


I understand about reserved words, but am puzzled by your last remark.

Can you explain, please?

And to tsh73 - thanks for replicating my problem - at least I know its not just me! undecided

Don
User IP Logged

Don Johnson (not the Film Star!)
e-mail me: donjohnson24@btinternet.com
personal web: http://www.donjohnson24.co.uk
Welopez
Moderator
ImageImageImageImageImage

member is offline

Avatar

Never underestimate the power of human stupidity. - Robert A. Heinlein


Homepage PM

Gender: Male
Posts: 3841
xx Re: Colour on Statictext / graphics
« Reply #10 on: Nov 3rd, 2009, 12:09pm »

Quote:
a$=INPUT$(1) would be a no-no.

When I am puzzled by statements in JB, the first place I go is the helpfile.
Quote:
INPUT$(#handle, items)

The line above gives the correct syntax for usage of INPUT$(). Get from the handle (file, textbox, list, etc), the specified number of items (characters).

I don't see (in your code) where you have specified where your program should find the information you want, only that you want just one item. Computers are very literal. If you don't talk to them in terms they understand, they will snap back and bite you!

Check the helpfile for the proper syntax of INSTR$(.

Good luck to you!


« Last Edit: Nov 3rd, 2009, 12:11pm by Welopez » User IP Logged

JohnDavidson
Administrator
ImageImageImageImageImage

member is offline

Avatar




Homepage PM


Posts: 3745
xx Re: Colour on Statictext / graphics
« Reply #11 on: Nov 3rd, 2009, 1:29pm »

I don't recall ever reading that INPUT$(1) is part of the official command set but this thread does make it seem so.

John
User IP Logged

John Davidson
e-me: johnshomeport@yahoo.com
My JB Page: http://john.jbusers.com/
Did ya Libby yet? http://lblibby.com/
donjohnson24
New Member
Image

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 13
xx Re: Colour on Statictext / graphics
« Reply #12 on: Nov 3rd, 2009, 2:46pm »

on Nov 3rd, 2009, 12:09pm, Welopez wrote:
When I am puzzled by statements in JB, the first place I go is the helpfile.

The line above gives the correct syntax for usage of INPUT$(). Get from the handle (file, textbox, list, etc), the specified number of items (characters).

I don't see (in your code) where you have specified where your program should find the information you want, only that you want just one item. Computers are very literal. If you don't talk to them in terms they understand, they will snap back and bite you!

Check the helpfile for the proper syntax of INSTR$(.

Good luck to you!




Well, thank you for your good wishes, which I will take in the spirit they are given.

However, I'm sure you don't intend to be patronising, but your remarks about 'the first place I go to . . .' seems to assume that people other than yourself do not use helpfiles. I can assure you that I always try to find an answer before seeking help.

I DID find the 'correct' usage of INPUT$, but had earlier been given a tip by Stefan Pendle that stated 'To capture single key strokes in the MainWin you use Input$(1)'. This was in response to a query about getting single key entries in the topic 'Understanding/Using windows and single key entries' in the Novice section. Despite the fact that I had searched the helpfile and not found this particular format, it works fine - apart from the query I raised about the need for double 'Enter's.

I posed the questions about single key entry in the Novice area because I was a newcomer to JB, although I have gained some experience of programming in a variety of languages, mainly self-taught from books - and helpfiles - over the last thirty years. During this time I also have learned that computers can be rather literal, but thanks for reminding me!
« Last Edit: Nov 3rd, 2009, 4:24pm by donjohnson24 » User IP Logged

Don Johnson (not the Film Star!)
e-mail me: donjohnson24@btinternet.com
personal web: http://www.donjohnson24.co.uk
Stefan Pendl
Administrator
ImageImageImageImageImage

member is offline

Avatar

Let's talk JB ...


PM

Gender: Male
Posts: 2158
xx Re: Colour on Statictext / graphics
« Reply #13 on: Nov 3rd, 2009, 4:15pm »

on Nov 3rd, 2009, 1:29pm, JohnDavidson wrote:
I don't recall ever reading that INPUT$(1) is part of the official command set but this thread does make it seem so.

John


The help file topic about the INPUT$(#h, n) command includes a paragraph, which shows how to use it to read single key strokes inside the MainWin.

So yes, this is officially supported.
User IP Logged

Stefan

Any code I post can be used by others in their own projects, there is no need to ask for permission, just give credit if you like

Just BASIC 1.01, Windows Vista Home Premium SP2, AMD Turion X2 RM-70 2GHz, 4GB RAM
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Help | Search | Recent Posts | Notification | Format Your Message | Vista/Win7 FAQ


New Monthly Ad-Free Plan!

$6.99 Gets 50,000 Ad-Free Pageviews!
| Free Shoutboxes | Hookah |

This Board Hosted For FREE By Conforums ©
Get Your Own Free Message Board!