Jump to content

StringSplit


Scanzee
 Share

Recommended Posts

$Bedrag = 13750

$Money = StringSplit($Bedrag ,"")

$Gold = $Money[1]

$SilverPlate = $Money[2]

$Silver = $Money[3] & $Money[4] & $Money[5]

$Label04ID = GUICtrlCreateLabel("Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver", 530, 20,300,20)

---------------------------------------------------------------------------------------------------------------------------

This part of the script works until you do $Bedrag - 10000...:s

When you do $Bedrag - 10 or any low value there is no problem until he has to change $Money[1]

What am I doing wrong?!

Scanzee Products <Scanzee@hotmail.com>

Link to comment
Share on other sites

just do ask your array how long it is:

$Bedrag = 13750
$Money = stringsplit ($Bedrag, "")
select
case $Money[0] = 5
$Gold = $Money[1]
$SilverPlate = $Money[2]
$Silver = $Money[3] & $Money[4] & $Money[5]
case $Money[0] = 4
$Gold = 0
$SilverPlate = $Money[1]
$Silver = $Money[2] & $Money[3] & $Money[4]
case $Money[0] = 3
$Gold = 0
$SilverPlate = 0
$Silver = $Money[1] & $Money[2] & $Money[3]
case $Money[0] = 2
$Gold = 0
$SilverPlate = 0
$Silver = $Money[1] & $Money[2]
case $Money[0] = 1
$Gold = 0
$SilverPlate = 0
$Silver = $Money[1]
endselect
$Label04ID = GUICtrlCreateLabel("Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver", 530, 20,300,20)

maybe this is what you're looking for

Link to comment
Share on other sites

#Include <String.au3>
$Bedrag = 13750
$Money = stringsplit ($Bedrag, "")
$a = 0
$Gold = 0
$SilverPlate = 0
$Silver = 0
for $i = $Money[0] to 1 step -1
$a = $a + 1
if $a < 4 then
$Silver = $Money[$i]
elseif $a = 4 then
$SilverPlate = $Money[$i]
elseif $a > 4 then
$Gold = $Money[$i]
endif
next
$Gold = _stringreverse($Gold)
$Silver = _stringreverse($Silver)
$Label04ID = GUICtrlCreateLabel("Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver", 530, 20,300,20)

don't know if thats shorter but will still work if you got 1million and more

Link to comment
Share on other sites

it looks long... i understand... i think

just call it in a function...kinda like this idea

Dim $Money[8], $gold, $silver, $SilverPlate

$Bedrag = 13750
Money(); call the function

$Label04ID = GUICtrlCreateLabel("Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver", 530, 20,300,20)


; main script




; ---------------------------------- functions -------------------------------------

Func Money()
$Money = stringsplit ($Bedrag, "")

If $Money[0] = 5 Then
$Gold = $Money[1]
$SilverPlate = $Money[2]
$Silver = $Money[3] & $Money[4] & $Money[5]
EndIf

If $Money[0] = 4 Then
$Gold = 0
$SilverPlate = $Money[1]
$Silver = $Money[2] & $Money[3] & $Money[4]
EndIf

If $Money[0] = 3 Then
$Gold = 0
$SilverPlate = 0
$Silver = $Money[1] & $Money[2] & $Money[3]
EndIf

If $Money[0] = 2 Then
$Gold = 0
$SilverPlate = 0
$Silver = $Money[1] & $Money[2]
EndIf

If $Money[0] = 1 Then
$Gold = 0
$SilverPlate = 0
$Silver = $Money[1]
EndIf
EndFunc

you can place either of Nuffilein805 codes in the function.... or use mine

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

#Include <String.au3>
$Bedrag = 13750
$Money = stringsplit ($Bedrag, "")
$a = 0
$Gold = 0
$SilverPlate = 0
$Silver = 0
for $i = $Money[0] to 1 step -1
$a = $a + 1
if $a < 4 then
$Silver = $Money[$i]
elseif $a = 4 then
$SilverPlate = $Money[$i]
elseif $a > 4 then
$Gold = $Money[$i]
endif
next
$Gold = _stringreverse($Gold)
$Silver = _stringreverse($Silver)
$Label04ID = GUICtrlCreateLabel("Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver", 530, 20,300,20)

don't know if thats shorter but will still work if you got 1million and more

----------------------------------------------------------------

There is some problem with this script btw...

With this script you see this label : 1Gold 3 Silverplate 7 Silver

and it has to be 1Gold 3 Silverplate 750 Silver

Is there a way you can fix it?!

Link to comment
Share on other sites

----------------------------------------------------------------

There is some problem with this script btw...

With this script you see this label : 1Gold 3 Silverplate 7 Silver

and it has to be 1Gold 3 Silverplate 750 Silver

Is there a way you can fix it?!

oooops yes there is

#Include <String.au3>
$Bedrag = 13750
$Money = stringsplit ($Bedrag, "")
$a = 0
$Gold = ""
$SilverPlate = 0
$Silver = ""
for $i = $Money[0] to 1 step -1
$a = $a + 1
if $a < 4 then
$Silver = $Silver & $Money[$i]
elseif $a = 4 then
$SilverPlate = $Money[$i]
elseif $a > 4 then
$Gold = $Gold & $Money[$i]
endif
next
$Gold = _stringreverse($Gold)
$Silver = _stringreverse($Silver)
if $Gold = "" then $Gold = 0
if $Silver = "" then $Silver = 0
$Label04ID = GUICtrlCreateLabel("Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver", 530, 20,300,20)

sorry haven't thought as i wrote the script B)

Link to comment
Share on other sites

Ok that is the one I was looking for!

And please say never to anyone you are going to make some .exe just for fun...

Scanzee Products..B)

do i have to understand what you mean by that?

omg i gotta go to bed i'm tired! 10hours in the forum is enough for today

Link to comment
Share on other sites

Will this work as expected? --

$Bedrag = 13750

$Gold = StringMid($Bedrag, 1, 1)
$SilverPlate = StringMid($Bedrag, 2, 1)
$Silver = StringMid($Bedrag, 3)

$Label04ID = GUICtrlCreateLabel("Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver", 530, 20,300,20)
Link to comment
Share on other sites

Will this work as expected? --

$Bedrag = 13750

$Gold = StringMid($Bedrag, 1, 1)
$SilverPlate = StringMid($Bedrag, 2, 1)
$Silver = StringMid($Bedrag, 3)

$Label04ID = GUICtrlCreateLabel("Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver", 530, 20,300,20)
seems that would work... but his would work for that statement also

the problem was

---------------------------------------------------------------------------------------------------------------------------

This part of the script works until you do $Bedrag - 10000...:s

When you do $Bedrag - 10 or any low value there is no problem until he has to change $Money[1]

What am I doing wrong?!

Scanzee Products <Scanzee@hotmail.com>

your script gives value to the gold.. like this

$Bedrag = 13750 - 10000

$Gold = StringMid($Bedrag, 1, 1)
$SilverPlate = StringMid($Bedrag, 2, 1)
$Silver = StringMid($Bedrag, 3)

$Label04ID = GUICtrlCreateLabel("Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver", 530, 20,300,20)

MsgBox(0,"Test", "Je hebt " & $gold & " Gold " & $Silverplate & " Silverplate " & $Silver &" Silver")

caught-ya smartie.... lol

8)

NEWHeader1.png

Link to comment
Share on other sites

Oh darn! B)

I suppose it depends on precisely how the numbers should be manipulated. We would need clarification from Scanzee to be certain. For instance:

  • 13750 -> 1G, 3S, 750SP.
  • 1375 -> 1G, 3S, 75SP or maybe 0G, 1S, 375SP?...
  • 137 -> ??
  • 123750 -> ???
I would suggest storing the data differently if that's controllable -- e.g. 1-3-750 instead of 13750 because what happens if you have 13 Gold, 7 Silver and 50 SP? (How will you know the difference?)
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...