Sign in to follow this  
Followers 0
dorit30

StringSplit Problam

23 posts in this topic

;StringSplit ( "string", "delimiters" [, flag ] )

$days = StringSplit($Mylist, @CR)

MsgBox(0, "Dayz are: ", $days[1])

MsgBox(0, "Dayz are: ", $days[2])

enc..

this is Fine BUT when i use :

MsgBox(0, "Dayz are: ", $days[1]+$days[2]) i got only the the $days[1] character display why not the sum of them

Whats wrong

or this :

$days[1] = $d1

$days[2] = $d2

$alldays = $d1+$d2

MsgBox(0, "Dayz are: ", $alldays) this give error

Why i cant sum variable ?

Share this post


Link to post
Share on other sites



Do you want the SUM or do you want to concatenate the characters ?

In other words: What goes in and what is it you want the result to be ?


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Do you want the SUM or do you want to concatenate the characters ?

In other words: What goes in and what is it you want the result to be ?

I split the Variables so i want sum all Variables that i split

Example :

$mylist = 1,4,5,6...

$days = StringSplit($Mylist, ",")

now $days[0] = 1 $days[1] = 4 enc i need 1+4 the sum

10nx

Share this post


Link to post
Share on other sites

I split the Variables so i want sum all Variables that i split

Example :

$mylist = 1,4,5,6...

$days = StringSplit($Mylist, ",")

now $days[0] = 1 $days[1] = 4 enc i need 1+4 the sum

10nx

StringSplit() will produce an Array where the first value will be the number of values, not the first value.

Now, just put what you want in a script we can run and show us what is wrong ...


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

well for:

$mylist = '1,4,5,6'

$days = StringSplit($Mylist, ",")

$days[0] is going to be in number of indexes, in this case 4. Skip $days[0] and your results should be correct.

Example:

$mylist = '1,4,5,6'
$days = StringSplit($Mylist, ",")

$totaldays = $days[1]+$days[2]
ConsoleWrite($totaldays&@CRLF)

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

Kerros what you write i already know this is not the problam But 10nx anyway

I Copy Paste the all script Like Joe Said maybe you guys can slove that

;Sniff 1

$dbname = "X:\DatabBase.mdb"

$tblname = "TableName"

$fldname = "FieldName"

$format = "Date"

$data = @MON & "/" & @MDAY & "/" & StringRight(@YEAR, 2)

;Simple read Field Function

Func _ReadOneFld($_sql, $_dbname, $_field)

Dim $_output

$adoCon = ObjCreate ("ADODB.Connection")

$adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $_dbname)

$adoRs = ObjCreate ("ADODB.Recordset")

$adoRs.CursorType = 1

$adoRs.LockType = 3

$adoRs.Open ($_sql, $adoCon)

With $adoRs

If .RecordCount Then

While Not .EOF

$_output = $_output & .Fields ($_field).Value & @CRLF

.MoveNext

WEnd

EndIf

EndWith

$adoCon.Close

Return $_output

EndFunc

;Use the Func

$query = "SELECT * FROM " & $tblname

$strData = _ReadOneFld($query, $dbname, $fldname)

;------------------------------------------ Write 2 file

$filez = "c:\output.txt"

FileWrite ( $filez, $strData)

;------------------------------------------

;untill here its work fine| I got $strData and want the sum of the table i rip

$days = StringSplit($strData, @CR) ; its have to be @CR cause its mdb output

MsgBox(0, "Dayz are: ", $days[1]+$days[2]..untill the end of the $strData)

Results = the sum of the Mdb table i rip from the table (if u know a better way Welcome)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I am sure you can just make a simple script that we can run to show what goes wrong... this script cannot be used to test ...

... and no need to PM me , just stick to the thread...

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Ok i cant sum

$days = StringSplit($strData, @CR)

MsgBox(0, "Dayz are: ", $days[1]+$days[2])

i got only the $days[1]

why it doesnt count $days[2]

Share this post


Link to post
Share on other sites

.... I give up when you can't produce a simple script for me to replicate your problem ....

:)

There is no problem, only a "problam".

Share this post


Link to post
Share on other sites

.... I give up when you can't produce a simple script for me to replicate your problem ....

:)

i dont get you I give u the all script , then sampleS what else u want?

how can i split array into values and then sum them what so hard to understand?

But 10nx anyway

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Which part of my question is unclear ? When i copy&paste your script into SciTE and press F5 then what do you think happens ?

It doesn't run nor produce the problem you see.

Now since i gave up the guessing game a while ago, i need exact information and a script that runs to be able to help you here.

oh and as far as your question about whats to hard to understand: I understand what you want to accomplish and the shown code is not showing anything obvious wrong THUS we need a script we can run and reproduces the problem you see... its a simple and that ...

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

There is no problem, only a "problam".

as u know Problam = PRO-Lam and Problem = ppl that instead of hlp others lol on them

Share this post


Link to post
Share on other sites

as u know Problam = PRO-Lam and Problem = ppl that instead of hlp others lol on them

Don't go there ... it was just a joke ...nothing more ..nothing less....

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Hi,

what jos means, I think, is thta you post something like this, which works OK; then show us what doe snot work?

Best Randall

#include<array.au3>
$strData="1"&@CR&"2"&@CR&"3"&@CR&"4"&@CR&"5"&@CR&"6"&@CR&"7"
$days = StringSplit($strData, @CR)
_ArrayDisplay($days)
MsgBox(0, "Dayz are: ", $days[1]+$days[2])

Share this post


Link to post
Share on other sites

Which part of my question is unclear ? When i copy&paste your script into SciTE and press F5 then what do you think happens ?

It doesn't run nor produce the problem you see.

Now since i gave up the guessing game a while ago, i need exact information and a script that runs to be able to help you here.

oh and as far as your question about whats to hard to understand: I understand what you want to accomplish and the shown code is not showing anything obvious wrong THUS we need a script we can run and reproduces the problem you see... its a simple and that ...

ok i try again

how can i split array into values and then sum them CAN YOU SHOW ME A FORMULA OR WAY OR COMMAND

i cant give u Sample cause i dont know how to build it Sorry , I just Start to script great Tool my english as you see is very poor

the only way i found to split a Array StringSplit i try it an its doesnt working....

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

(Jeeezzzz ... my Dutch - English translator must be performing badly today.. but am in a very very patient mode today :) )

I cannot tell you how to do it when your code already looks good at first glance and as randallc also explained/clearified: create a script for us that shows what fails.

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

ok i try again

how can i split array into values and then sum them CAN YOU SHOW ME A FORMULA OR WAY OR COMMAND

i cant give u Sample cause i dont know how to build it Sorry , I just Start to script great Tool my english as you see is very poor

the only way i found to split a Array StringSplit i try it an its doesnt working....

$split = StringSplit('5 10 15 20', ' ')
$sum = $split[1] + $split[2] + $split[3] + $split[4]
MsgBox(0, '', $sum)

Or if you don't know how many values you have:

$split = StringSplit('5 10 15 20', ' ')
$sum = 0
For $i = 1 to $split[0]
    $sum += $split[$i]
Next
MsgBox(0, '', $sum)

*Edit: Although I bet I know what the problem is... in the initial post you're splitting by @CR but you probably need to split by @CRLF, because otherwise your math is like (5 + @LF10 + @LF15 + @LF20) which = 5.

Perhaps try splitting by @LF instead, and then wrap with int.

$split = StringSplit('5' & @CRLF & '10', @LF)
$sum = 0
For $i = 1 to $split[0]
    $sum += Int($split[$i])
Next
MsgBox(0, '', $sum)
Edited by Saunders

Share this post


Link to post
Share on other sites

Hi,

what jos means, I think, is thta you post something like this, which works OK; then show us what doe snot work?

Best Randall

#include<array.au3>
$strData="1"&@CR&"2"&@CR&"3"&@CR&"4"&@CR&"5"&@CR&"6"&@CR&"7"
$days = StringSplit($strData, @CR)
_ArrayDisplay($days)
MsgBox(0, "Dayz are: ", $days[1]+$days[2])
ok the problem is : When i run this script

#include<array.au3>

$strData="1"&@CR&"2"&@CR&"3"&@CR&"4"&@CR&"5"&@CR&"6"&@CR&"7"

$days = StringSplit($strData, @CR)

_ArrayDisplay($days)

MsgBox(0, "Dayz are: ", $days[1]+$days[2])

Its work Great and the output = 3 (OK 10nx GOD 10nx PPL I love u all)

BUT the big BUT when i do the same thing from my $strData i just got the first value in this case its 1

OUTput = 1 and its wrong it has to be 3 ok till here ?

if u said the problem is that i rip the $strData from a Mdb table and it can only use like your sample i have to put the valueS myself i understand But if i can use variable instead of this why its not work?

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