Sign in to follow this  
Followers 0
Scanzee

StringSplit

19 posts in this topic

$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>

Share this post


Link to post
Share on other sites



$Bedrag = 13750

$Money = StringSplit($Bedrag ,"")

gives a 6 level array

and works for you r comparison

$Bedrag = 13750 - 10000

$Money = StringSplit($Bedrag ,"")

does not give 6 levels

only 5 levels

thus your array split will not work

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

So what do I have to do?!

Do you have anything for my sow it will work?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks for that but has someone maybe a shorter way to do all this.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Yeah how fast you can mess up a script..B)

Thanks a lot guys..

Share this post


Link to post
Share on other sites

Yeah how fast you can mess up a script..B)

Thanks a lot guys..

?????

please explain

8)


NEWHeader1.png

Share this post


Link to post
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?!

Share this post


Link to post
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)

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

You don't have to understand that..B)

Where do you live?!

Share this post


Link to post
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)

Share this post


Link to post
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

Share this post


Link to post
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?)

Share this post


Link to post
Share on other sites

Oh darn! B)

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?)

now that is a good one...

what if he had 13 gold

8)


NEWHeader1.png

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