Sign in to follow this  
Followers 0
Adolfik

Transform data to be readable

7 posts in this topic

Hi everyone :blink:

So I got a specific data string which looks like

0041002137293/66840/1279759439/1279494808/370248530/1/0/5/1544/...

It's much much longer, but what I'd like to get of it is:

1:0041002137293

2:66840

3:1279759439

4:.....

5:.....

6:1

7:0

and so on

Great thanks ;)

Share this post


Link to post
Share on other sites



So easy, you just needed to read help file and would have find StringSplit() function :blink:

This is what you need:

$stringData = Stringsplit("0041002137293/66840/1279759439/1279494808/370248530/1/0/5/1544", "/", 1)

For $i = 1 to $StringData[0]        
    Msgbox (0, "",  $StringData[$i])
Next

Share this post


Link to post
Share on other sites

Big thanks!

I did some changes and it works in a simple script

$text        =fileread("data.txt")  ;read textfile
$test = StringSplit($text,"/", 1)

 Msgbox (0, "data","thing1: " & $test[8] & " thing2 " & $test[9]&"/"&$test[10]&" thing3: " &$test[14]&" thing4: "&$test[15])

but when I try to put it into a script with loop it gives me error ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

I don't want it to display all the info from data.txt but just just few essential values

Here is a part of script I use

If $zdata<>Binary("") Then 
                                    $test = StringSplit((BinaryToString ($zdata)) ,"/", 1)
                                    Msgbox (0, "hello","info: " & $test[8] & " info " & $test[9]&"/"&$test[10]&" info: " &$test[14]&" info: "&$test[15])
                                    $timeout=TimerInit(); got data reset timeout timer
                                    TCPSend($sock,$zdata)
                                    EndIf

It fails on msgbox.... and anywhere else where I want to use these values(it is displayed but script fails right after)

Share this post


Link to post
Share on other sites

Read what StringSplit is doing (SciTe - F1, and look for StringSplit)

You will see that the output is an array - once you reference "non-existing" members of that array you get the same error. Answer your $test[14] or $test[15] might not exist = the string does not have so many groups.

Solution: see how many elements the array has and whatever you do, do not go over the number of elements.


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

#5 ·  Posted (edited)

It fails on msgbox.... and anywhere else where I want to use these values(it is displayed but script fails right after)

As enaiman said you get the above error when you refer to an index that doesn't exist.

For example if StringSplit() returned an array with 5 elements and you want to get lets say $test[9] you get the above error.

Just make sure to use correct indexes, and keep in mind that the data in the file you read may change (i think) and these indexes may change too. I'm not very clear about what do you want to do with this, however I think you got the idea in what you need to correct....

Edited by ALTIN

Share this post


Link to post
Share on other sites

Thanks for answers :blink:

I will ask another question (I hope it's the last one)

so is there any way to stop whole script to terminate when this error occurs?

or maybe I can somehow check how long received string is, and just do nothing when it's too short.

If $zdata<>Binary("") Then 
                                    
        $test = StringSplit((BinaryToString ($zdata)) ,"/", 1)  
$timeout=TimerInit(); got data reset timeout timer
                                    TCPSend($sock,$zdata)
    sth like If $test got more than 15 values then                              
Msgbox (0, "hello","info: " & $test[8] & " info " & $test[9] & "/" & $test[10] & " info: " & $test[14] & " info: " & $test[15])
if else msgbox(0,"error","error")
EndIf

Share this post


Link to post
Share on other sites

Adolfik,

maybe I can somehow check how long received string is

If you look at StringSplit in the Help file, you will see that the [0] element of the returned array contains the count of the returned strings - so it is easy to see if you have enough to fill your MsgBox. :blink:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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