Sign in to follow this  
Followers 0
MariusN

add a stringlen to a number

8 posts in this topic

last q for today...If you look at the below code

Func _message()

    $font = "Times New Roman"
    GUICreate("Timer Settings", 330, 100)
    GUICtrlCreateLabel("Timer set to an interval of", 10, 30, 210)
    GUICtrlSetFont(-1, 14, 800, 0, $font)
    GUICtrlCreateLabel($input, 220, 30, -1)
    GUICtrlSetFont(-1, 14, 800, 0, $font)
    GUICtrlSetColor(-1, 0x3333FF)
    $string = StringLen ($input)
    $total = 240+$string ; <-----the string will be 2 digits
    MsgBox(0,"",$total);<--- this actually SHOWS 242
    GUICtrlCreateLabel("seconds", $total, 30, 60);<---but it doesnt get added here
    GUICtrlSetFont(-1, 14, 800, 0, $font)

    GUISetState()

    While 1
        Sleep(2000)
        ExitLoop
    WEnd
    GUIDelete()
EndFunc

The $total (left align of "seconds") doesnt accept 242 as an input, but 240 instead...

What am i doing wrong here?

thanks guys... :mellow:

Share this post


Link to post
Share on other sites



GUICtrlCreateLabel("seconds", $total, 30, 60, 90)

Just specify the width of the label and it will be OK; the text simply couldn't fit in the default dimensions.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I FOUND MY PROB...IM A D**K...LOL

I just found out that 1 digit is about = 5 which means I must add 240+($string*6)

Edited by MariusN

Share this post


Link to post
Share on other sites

I guess you're lacking sleep :mellow:

I don't have your "input" box but have a look at how I tested your script:

$font = "Times New Roman"
    GUICreate("Timer Settings", 400, 150)
    GUICtrlCreateLabel("Timer set to an interval of", 10, 30, 210)
    $string = StringLen ("qwjkjksdfsdffhjksdfhsjdfdsfksdfsdfdsdffffffffdfsfdsfds")
    $total = 240+$string ; 
    GUICtrlSetFont(-1, 14, 800, 0, $font)
    GUICtrlCreateLabel($total, 220, 30, 30)
    GUICtrlSetFont(-1, 14, 800, 0, $font)
    GUICtrlSetColor(-1, 0x3333FF)
    GUICtrlCreateLabel(" seconds", $total, 30, 90);<---but it doesnt get added here
    GUICtrlSetFont(-1, 14, 800, 0, $font)

    GUISetState()

    While 1
        Sleep(2000)
        ExitLoop
    WEnd

Just play with the string length and you'll see that the label moves accordingly.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Did you even try your own code? The input goes exactly where you tell it to, there's no problem here.

$GUI = GUICreate("Timer Settings", 330, 100)
$total = 240+StringLen ("12") ; <-----the string will be 2 digits
$Label = GUICtrlCreateLabel("seconds", $total, 30, 60);<---but it doesnt get added here
$array = ControlGetPos($GUI, "", $Label)
ConsoleWrite($array[0] & @CRLF)

For the future, please post a working (runnable), and short reproducer. People don't like to wade through unnessary code, or write the basics just to see the problem. As a bonus, there is also a high chance that you find the answer to your question when writing the reproducer.

Share this post


Link to post
Share on other sites

Did you even try your own code? The input goes exactly where you tell it to, there's no problem here.

$GUI = GUICreate("Timer Settings", 330, 100)
$total = 240+StringLen ("12") ; <-----the string will be 2 digits
$Label = GUICtrlCreateLabel("seconds", $total, 30, 60);<---but it doesnt get added here
$array = ControlGetPos($GUI, "", $Label)
ConsoleWrite($array[0] & @CRLF)

For the future, please post a working (runnable), and short reproducer. People don't like to wade through unnessary code, or write the basics just to see the problem. As a bonus, there is also a high chance that you find the answer to your question when writing the reproducer.

Yep...my OWN code *-proud-* :mellow:

this made it for me ---> $total = 230+($string*8)

...due to the font size etc, the "8" works 100%

Thanks for all the help and effort from you guys...much appreciated :(

Share this post


Link to post
Share on other sites

I guess you're lacking sleep :mellow:

I don't have your "input" box but have a look at how I tested your script:

$font = "Times New Roman"
    GUICreate("Timer Settings", 400, 150)
    GUICtrlCreateLabel("Timer set to an interval of", 10, 30, 210)
    $string = StringLen ("qwjkjksdfsdffhjksdfhsjdfdsfksdfsdfdsdffffffffdfsfdsfds")
    $total = 240+$string ; 
    GUICtrlSetFont(-1, 14, 800, 0, $font)
    GUICtrlCreateLabel($total, 220, 30, 30)
    GUICtrlSetFont(-1, 14, 800, 0, $font)
    GUICtrlSetColor(-1, 0x3333FF)
    GUICtrlCreateLabel(" seconds", $total, 30, 90);<---but it doesnt get added here
    GUICtrlSetFont(-1, 14, 800, 0, $font)

    GUISetState()

    While 1
        Sleep(2000)
        ExitLoop
    WEnd

Just play with the string length and you'll see that the label moves accordingly.

...talking about sleep...I just woke up...maybe that's the trick :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0