Announcement

Collapse
No announcement yet.

Button text from a variable? (yes I searched)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Vince_4D
    replied
    Hi,

    No worries. I'm glad it worked smoothly on your side.
    Should you need any further assistance, don't hesitate to inform us.

    Best regards,

    Leave a comment:


  • Fixxer
    replied
    Oh dang you nailed it! I'm not sure how I missed that other than to say it got lost in the clutter of me trying to get the app written. Me and the Internal Functions manual (and the 4DGL manual) are like old friends- I've read and reread all of them dozens of times over the years, and I guess I just missed it.

    I can't thank you enough- it works like a charm!

    Leave a comment:


  • Vince_4D
    replied
    Hi,

    To use the function gfx_Button2(...), you won't need to use a string pointer (Refer to InternalFunctions documentation). But you will need to set the size of the text using txt_Width(x) and txt_Height(x).
    Code:
    var text[10];   // text buffer
    var x := 50 ,y := 50;                   // location
    var width := 150, height := 100;        // button dimension
    var color := WHITE, textcolour := RED;
    
    var count;
    var prevTime;
    
    func main()
    
        putstr("Mounting...\n");
        if (!(file_Mount()))
            while(!(file_Mount()))
                putstr("Drive not mounted...");
                pause(200);
                gfx_Cls();
                pause(200);
            wend
        endif
    
        gfx_Cls();
        txt_Width(5);
        txt_Height(5);
        gfx_Set(SCREEN_MODE,LANDSCAPE) ;
    
        repeat
    
            if(sys_T() - prevTime > 1000)
                count++;
                if(count>=100) count := 0;
    
                if(count<10)
                    to(text); print("0",count);
                else
                    to(text); print(count);
                endif
                gfx_Button2(1, x, y, width, height, color, textcolour, text);
                prevTime := sys_T();
            endif
        forever
    endfunc
    Best regards,

    Leave a comment:


  • Fixxer
    replied
    Hi Vince, thank you for replying. I tried what you said before posting and it didn't seem to want to work.

    My post above was an example, and I figured out that while your answer does in fact work, in reality I was trying to use "gfx_Button2" so I could set the size of the buttons, and for some reason, THAT doesn't work (using the string pointer as you indicated). I tried setting up the text attributes before calling Button2 and I still can't seem to get it working.

    I'll keep plugging away at it and post anything I come up with here.

    Thanks big!

    Leave a comment:


  • Vince_4D
    replied
    Hi, welcome to the forum.

    You can do it by utilizing the string pointer. Refer to the code below.
    Code:
    var text[10];   // text buffer
    var x := 50 ,y := 50;        // location
    var count;
    var prevTime;
    
    func main()
    
        putstr("Mounting...\n");
        if (!(file_Mount()))
            while(!(file_Mount()))
                putstr("Drive not mounted...");
                pause(200);
                gfx_Cls();
                pause(200);
            wend
        endif
    
        gfx_Cls();
    
        gfx_Set(SCREEN_MODE,LANDSCAPE) ;
    
        repeat
    
           if(sys_T() - prevTime > 500)
                count++;
                if(count>=100) count := 0;
    
                if(count<10)
                    to(text); print("0",count);
                else
                    to(text); print(count);
                endif
                gfx_Button(1, x, y, RED, WHITE, 1, 5, 5, str_Ptr(text));
                prevTime := sys_T();
            endif
    
        forever
    endfunc
    Hope this helps.

    Best regards,
    Last edited by Vince_4D; 27th December 2018, 12:41 PM.

    Leave a comment:


  • Fixxer
    started a topic Button text from a variable? (yes I searched)

    Button text from a variable? (yes I searched)

    Hi all, I was wondering if anybody has come up with a (simple) way to use a variable to supply button text to gfx_Button. I have a function that uses a numerical argument to determine where to draw the button, and I want the button text to reflect the number passed.

    Essentially it would look like this:



    var mynumber;

    mynumber := 44;

    gfx_Button2(1, x, y, 50, 50, buttoncolor, textcolor, [DEC2Z]mynumber);



    so if mynumber is, say, 27, it will draw a button with "27" as the button text. If mynumber is 9, it will draw a button with "09" as the button text.

    I tried searching and there are a couple posts, but I have been unable to get it to work.

    Seems like it should be pretty straightforward. If not, then it should be.

    Anybody out there have anything that might help? Thanks in advance :-)
Working...
X