Jump to content

[Solved]stringsplit array problem...


Recommended Posts

here's what I want and what it does and doesn't do...

I have a GUI with combobox. Either they can select a input ($combo) from the combobox or give their own input.

the input from the file is working.

now comes the issue.

if teh input is not on $IDfile then I want the value to be written to consolewrite. Later Ill change that to iniwrite.

Giftsender.ini
[Userlist]
users=|11111|22222|33333|44444|55555|

$IDfile = IniRead("C:\giftsender.ini", "Userlist", "users", ""); this gives 
$ALL_IDS = StringSplit($IDfile,"|",1)
For $1ID  In $ALL_IDS
;ConsoleWrite(GUICtrlRead($combo) & @LF)    
If GUICtrlRead($combo) <> $1ID Then
    ConsoleWrite(GUICtrlRead($combo) & @LF)
Else
    EndIf
Edited by Overlord
Link to comment
Share on other sites

$IDfile = IniRead("C:\giftsender.ini", "Userlist", "users", ""); this gives
$ALL_IDS = StringSplit($IDfile,"|",1)
for $i = 0 to $ALL_IDS[0]
    if stringlen($ALL_IDS[$i] > 0 Then
        if $ALL_IDS[$i] <> GUICtrlRead($combo) Then
            ConsoleWrite("Read ID " & $ALL_IDS[$i] & " does not equal selected combo box value" & @crlf)
        Else
            ConsoleWrite("Read ID " & $ALL_IDS[$i] & " equals selected combo box value" & @crlf)
        endif
    endif
next

Link to comment
Share on other sites

ok...

Read ID 7 does not equal selected combo box value

Read ID 11111 does not equal selected combo box value

Read ID 22222 does not equal selected combo box value

Read ID 33333 does not equal selected combo box value

Read ID 44444 equals selected combo box value

Read ID 55555 does not equal selected combo box value

Where does the 7 come from????

Link to comment
Share on other sites

I just need to have it checked what's in $IDfile against the current input.

if the current input is already in $IDfile then do nothing, else add it...

Kafu his example isn't getting me any further....

with my example I don't get a 7 anywhere...

Link to comment
Share on other sites

All you need to do is:

$IDfile = IniRead("C:\giftsender.ini", "Userlist", "users", "")
$ALL_IDS = StringSplit($IDfile, "|", 1)
For $i = 1 To $ALL_IDS[0]
    If StringLen($ALL_IDS[$i]) > 0 Then
        If $ALL_IDS[$i] <> GUICtrlRead($combo) Then
            ConsoleWrite("Read ID " & $ALL_IDS[$i] & " does not equal selected combo box value" & @CRLF)
        Else
            ConsoleWrite("Read ID " & $ALL_IDS[$i] & " equals selected combo box value" & @CRLF)
        EndIf
    EndIf
Next

This is will skip the reading of the amount but still keep the array

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

All you need to do is:

$IDfile = IniRead("C:\giftsender.ini", "Userlist", "users", "")
$ALL_IDS = StringSplit($IDfile, "|", 1)
For $i = 1 To $ALL_IDS[0]
    If StringLen($ALL_IDS[$i]) > 0 Then
        If $ALL_IDS[$i] <> GUICtrlRead($combo) Then
            ConsoleWrite("Read ID " & $ALL_IDS[$i] & " does not equal selected combo box value" & @CRLF)
        Else
            ConsoleWrite("Read ID " & $ALL_IDS[$i] & " equals selected combo box value" & @CRLF)
        EndIf
    EndIf
Next

This is will skip the reading of the amount but still keep the array

still not working as it should. probably I'm just to dumb to get it...

here's the output when you select 11111 from the list:

Read ID 11111 equals selected combo box value

Read ID 22222 does not equal selected combo box value

Read ID 33333 does not equal selected combo box value

Read ID 44444 does not equal selected combo box value

Read ID 55555 does not equal selected combo box value

and this is when I type in 99999 to the combobox:

Read ID 11111 does not equal selected combo box value

Read ID 22222 does not equal selected combo box value

Read ID 33333 does not equal selected combo box value

Read ID 44444 does not equal selected combo box value

Read ID 55555 does not equal selected combo box value

now If I understand teh above code correct, it will add the new value currently 4 times (since there are 5 values now) to my inifile.

and the second one with 99999 will add it 5 times since it doesn't match??

or am I misinterpreting something here?

just tested once more...aint doing the trick...

here's result:

Read ID 11111 does not equal selected combo box value

Read ID 22222 does not equal selected combo box value

Read ID 33333 equals selected combo box value

Read ID 44444 does not equal selected combo box value

Read ID 55555 does not equal selected combo box value

here's what's in my ini now:

[userlist]

users=|11111|22222|33333|44444|55555|

TEST=33333

but this 33333 was not supposed to be filled in since 33333 is alread on the list... I want only the values added that aren't on the list...

Edited by Overlord
Link to comment
Share on other sites

The leading and trailing pipe might be messing you up too. Because of those, the array becomes 7 elements, the 11111 would actually be the second element and the 55555 would be the 6th.

Edit: Or maybe I'm just confused.... So you already have a given list of users. When someone enters something in the combo box you want to be able to check if the input is already a part of the list and, if not, add it?

Edited by MrMitchell
Link to comment
Share on other sites

yeah I figured that out also later. but that doesn't solve my current problem...

and I just realized my question is a bit wrong...

it should stringsplit on the | which it does and then start looking if $ALL_IDS[1] OR $ALL_IDS[2] OR $ALL_IDS[3] OR $ALL_IDS[4] OR ... = GUICtrlRead($combo)

and if none is equal then it should write to ini. the way the code is now it will always write. even if the value is inside...

if I follow the logic step it's takin now then it goes as follows...

stringsplit and compare:

input = 33333

split becomes 11111 <> write to ini

2nd becomes 22222 <> write again to ini

3th becomes 33333 = input, don't write to ini

4th becomes 44444 <> write again to ini

and so on and on...

Link to comment
Share on other sites

Edit: Or maybe I'm just confused.... So you already have a given list of users. When someone enters something in the combo box you want to be able to check if the input is already a part of the list and, if not, add it?

THAT would be exactly what I'm looking for...for the last 4h lol

Link to comment
Share on other sites

$IDfile = IniRead("C:\giftsender.ini", "Userlist", "users", "")
$ALL_IDS = StringSplit($IDfile, "|", 1)
For $i = 1 To $ALL_IDS[0]
    If StringLen($ALL_IDS[$i]) > 0 Then
        If $ALL_IDS[$i] <> GUICtrlRead($combo) Then
            ConsoleWrite("Read ID " & $ALL_IDS[$i] & " does not equal selected combo box value" & @CRLF)
        EndIf
    EndIf
Next

With your | you have 6 in in the first array but then because you stringsplit it it will add one more to that list hence why we are start from 1 in the FOR statement. All you need down then is taking out the function equals if you don't want to write it. Also this is only writing it to the console so each time it isn't doing anything, we leave that to you.

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

sigh... and STILL not working...

this is not what I need... this will write always to ini...

just check...

$IDfile ="|11111|22222|33333|44444|55555|"

I checked with value 44444

Read ID 11111 does not equal selected combo box value >> will write to ini

Read ID 22222 does not equal selected combo box value >> will write to ini

Read ID 33333 does not equal selected combo box value >> will write to ini

Read ID 55555 does not equal selected combo box value >> will write to ini

however 11111, 22222, 33333 and 55555 ARE part off the $IDfile that gets split so shouln't be added....

Link to comment
Share on other sites

You should loop through your entire array and look for a match with every iteration. Make that whole set of code it's own function. If it finds a match then use Return (for instance Return 1 to indicate there's a duplicate) to get out of the function. If it doesn't find a match then let the function continue and add the input to the INI file, or Return 0 and use that to run code that will add the input to the INI file.

;This is when the button is clicked
If isDuplicate() Then
    ;The entry already exists
Else
    ;Add code here to add the input to the INI file since it doesn't already exist
EndIf

Func IsDuplicate()
    For $i = 3 To $ALL_IDS[0]
        If $ALL_IDS[0] Then
            If $ALL_IDS[$i] == String(GUICtrlRead($combo)) Then
                ;Input is already a part of the list, do not add it
                Return 1
            Else
                ;input is not already part of the list
                Return 0
            EndIf
       EndIf
    Next
EndFunc
Link to comment
Share on other sites

You should loop through your entire array and look for a match with every iteration. Make that whole set of code it's own function. If it finds a match then use Return (for instance Return 1 to indicate there's a duplicate) to get out of the function. If it doesn't find a match then let the function continue and add the input to the INI file, or Return 0 and use that to run code that will add the input to the INI file.

;This is when the button is clicked
If isDuplicate() Then
    ;The entry already exists
Else
    ;Add code here to add the input to the INI file since it doesn't already exist
EndIf

Func IsDuplicate()
    For $i = 3 To $ALL_IDS[0]
        If $ALL_IDS[0] Then
            If $ALL_IDS[$i] == String(GUICtrlRead($combo)) Then
                ;Input is already a part of the list, do not add it
                Return 1
            Else
                ;input is not already part of the list
                Return 0
            EndIf
       EndIf
    Next
EndFuncoÝ÷ Ûú®¢×»-#f`zÛbhÂËZ®Ø§«tß ,ÒÝê®j[-ë-®)àʬ¥vËZ®Ö­Ô   l¡@hºwméò¢çhm«Þ¶!yÉ"¶Ü"/(²Ø¦¦íj{b²ØZ·*.®Øb"Yè·
+·jëÚ''hzÊ'yÆ¥réZ¶*'¶§z+azºÞ¶êç³Z+Ð(uëajÜ(®K"²«y«­¢+Ù%%ÍÕÁ±¥Ñ ÀÌØí11}%L¤Q¡¸(%5Í ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½ÐíQ¡¹ÑÉä±Éäá¥ÍÐÅÕ½Ðì¤)±Í(%5Í    ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí½Ñ¼Á±¥¹Ñ¼Ñ¡¥±ÅÕ½Ðì¤)¹%()Õ¹%ÍÕÁ±¥Ñ¡    åIÀÌØíÙÉÉä¤(%½ÈÀÌØí¤ôÄQ¼U   ½Õ¹ ÀÌØíÙÉÉ䤴Ä($%%ÀÌØíÙÉÉålÀÌØí¥tôôMÑÉ¥¹¡U%
ÑɱI ÀÌØí½µ¼¤¤Q¡¸IÑÕɸÄ(%9áÐ($(%IÑÕɸÀ)¹Õ¹ìôôÐí%ÍÕÁ±¥Ñ

I added the ByRef and changed all the reference to that variable but can't change your $combo

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

Why do you need to split the ini key content?

Edit: Moi mistake.

No mistake, but a good idea m8 :D...

$Iniread = IniRead("C:\giftsender.ini", "Userlist", "users", "")
$new_value = GUICtrlRead($combo)
if StringInStr($Iniread,"|" & $new_value & "|") Then
    ConsoleWrite("Read ID " & $new_value & " found..." & @crlf)
Else
    ConsoleWrite("Read ID " & $new_value & " NOT found..." & @crlf)
    if not StringRight($Iniread,1) = "|" Then; ensure all values are enclosed by | (for stringinstr() check)
        $new_value = "|" & $new_value & "|"
    Else
        $new_value = $new_value "|"
    endif
    IniWrite("C:\giftsender.ini", "Userlist", "users", $Iniread & $new_value); add new value to ini
endif
Edited by KaFu
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...