Sign in to follow this  
Followers 0
Damein

Problem with StringSplit?

4 posts in this topic

So I have this code, and it works so long as I don't use a number with more than one digit.

So, its just a test to figure out how to fix a problem in my other script.

Example:

2*2*2*2 comes out as: 16

Which, that works out correctly.

But:

2*22 comes out as: 4, not 44.

Here's the code:

Global $StoreProblemGrid, $result, $StartingNumber, $Count, $NumberToStartWith, $SaveNumbers

            $StoreProblemGrid = InputBox(0, "Test", "Input problem")
            $result = StringSplit($StoreProblemGrid, "*")
            $StartingNumber = $result[0]
            $Count = 1
            $State = 0
            $StartingNumber -= 1
            $NumberToStartWith = $result[1]
            Do
                $Count += 1
                $StartingNumber -= 1
                $NumberToStartWith *= $result[$Count]
                If $StartingNumber = 0 Then
                $SaveNumbers = ""
                $state = 1
                $Count = ""
                MsgBox(0, "Test", $NumberToStartWith)
                $NumberToStartWith = ""
            EndIf
        Until $state = 1

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You have quite a mess in there - I didn't even try to debug your code, I just re-wrote it:

Global $StoreProblemGrid, $compos, $result

    $result = 1
    $StoreProblemGrid = InputBox(0, "Test", "Input problem")
    $compos = StringSplit($StoreProblemGrid, "*")
    For $i = 1 To $compos[0]
        $result *= $compos[$i]
    Next
    MsgBox(0, "Test", $result)

Edit: BTW - StringSplit returns the number of elements in [0], so first element will be [1] -> $StartingNumber = $result[1] ... if you want to debug your code ...

Edited by enaiman

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

Edit: BTW - StringSplit returns the number of elements in [0], so first element will be [1] -> $StartingNumber = $result[1] ... if you want to debug your code ...

You're right. Use Flag = 2 to disable the return of the count.

$array = StringSplit($string,"",2)

Hi ;)

Share this post


Link to post
Share on other sites

Try this short-cut.

Destination orientated, not the journey.

MsgBox(0, "Test Result", "Answer: " & Execute(InputBox("Test", "Input a valid mathematical expression." & _
        @CRLF & 'e.g. Enter "cos(240*Atan(1)/180) * 22"' & @CRLF & _
        'Should return: "11"', "cos(240*Atan(1)/180) * 22")), 3)

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