Jump to content

add a stringlen to a number


MariusN
 Share

Recommended Posts

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:

Link to comment
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 :)

Link to comment
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.

Link to comment
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 :(

Link to comment
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 :(
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...