Split string, execute function, delete split. (1 Viewer)

Dranoweb

Registered User.
Local time
Today, 19:02
Joined
Sep 28, 2009
Messages
68
I had a eureka moment.
Rather obvious one actually.

I realised that all my strings are a fixed length, bar one combination.

I just dragged it all into excel, saved, and imported into access with a fixed delimiation (first row set as containing headers).

Exported back to excel, transposed the columns, and exported back into access again.

long winded I know, but only has to be done a few times.

Anyway, I now have each packet split into an individual row in a table that I can work with.

I'll keep working on this at a later date though as I will have a need to delimiate a string into set lengths in the future.
 
Local time
Today, 04:02
Joined
Mar 4, 2008
Messages
3,856
This is totally doable. It is unfortunate that you didn't give us a sample of your input and it's corresponding desired result.

Coming late to the game, I'd like to get the rules straight:
1. All of your strings will be 45 real live (not morse) characters. See number 10 below.
2. The only real live characters in any string will be D, I, S, U, 0, 7, 8, and 9.
3. All 45 character strings will begin with the translated letter "D", which is represented in the string by "_.."
4. After the "D", there will always be some multiple of 5 number characters (each represented by 25 morse code elements) that represent the numeric characters 1 through 0 and are translated into a real live number via the table you presented.
5. After at least one of the 5 number characters has come (after the "D"), there will be the string "IS" which is represented by the morse code string ".....".
6. More 5 number strings (25 morse characters each).
7. After at least one of the 5 number characters has come (after the "IS"), there will be the string "IU" which is represented by the morse code string "...._".
8. More 5 number strings (25 morse characters each).
9. The character "I" in morse code which is represented by the mc string "..".
10. If everything I've said above is totally accurate, there's something you haven't told us because there is no way to represent sets of 5 numbers and 6 characters within 45 characters. Proof: 45 - 6 (represented the 6 control characters) = 39; 39 is not evenly divisible by 5. What did we miss?

Does that sum it up accurately (after answering for the anomaly)? If so, this is an incredibly simple task as each of the numeric characters start with at least 3 "_" mc characters and there is absolutely no way possible of misinterpreting the "IS" (".....") or the "IU" ("...._") as part of numbers. Even if the data is error prone, there are some nice features of the coded set that still make it easy to manually interpret the string.

Something like this might work:
Code:
Function TestMorse() As String
Dim l_strOut As String
    l_strOut = TranslateDranowebsString("_..______________________........_______________________......_________________________...")
    'Debug.Print l_strOut
    TestMorse = l_strOut
End Function
Function TranslateDranowebsString(p_strIn As Variant) As String
Dim l_strDElement As String
Dim l_strSElement As String
Dim l_strUElement As String
Dim l_iISLocation As Integer
Dim l_iIULocation As Integer
Dim l_strOut As String
    TranslateDranowebsString = "!!Error!!"
    If Left(p_strIn, 3) = "_.." And Right(p_strIn, 2) = ".." Then 'it begins with "D" and ends with "I"
        On Error GoTo end_function
        '29
        l_iISLocation = InStr(1, p_strIn, "....._")  'With "IS" somewhere in the middle
        If l_iISLocation = 0 Then
            TranslateDranowebsString = "!!Error!! - Does not contain 'IS' followed by a number"
            GoTo end_function
        End If
        
        '59
        l_iIULocation = InStr(l_iISLocation + 5 + 5, p_strIn, "....__")   'With "IU somewhere after "IS" and it's first 5 numbers.
        If l_iIULocation = 0 Then
            TranslateDranowebsString = "!!Error!! - Does not contain 'IU' followed by a number"
            GoTo end_function
        End If
        l_strDElement = Mid(p_strIn, 4, l_iISLocation - 4) 'It's the data between the 4th character and the "IS"
        l_strSElement = Mid(p_strIn, l_iISLocation + 5, l_iIULocation - l_iISLocation - 5) 'correct for the length of "IU"
        l_strUElement = Mid(p_strIn, l_iIULocation + 5, Len(p_strIn) - (2 + 4 + l_iIULocation)) 'correct for the length of "IU" and "I"
        
        If Len(l_strDElement) Mod 5 <> 0 Or Len(l_strSElement) Mod 25 <> 0 Or Len(l_strUElement) Mod 25 <> 0 Then
            TranslateDranowebsString = "!!Error!! - There don't seem to be enough numbers in the string"
            GoTo end_function
        End If
        
        l_strOut = "D Element: " + TranslateDranowebsNumberStrings(l_strDElement) + vbCrLf
        l_strOut = l_strOut + "S Element: " + TranslateDranowebsNumberStrings(l_strSElement) + vbCrLf
        l_strOut = l_strOut + "U Element: " + TranslateDranowebsNumberStrings(l_strUElement)
        
        TranslateDranowebsString = l_strOut
       
    End If
    

end_function:

End Function

Function TranslateDranowebsNumberStrings(p_strIn As String) As String
Dim l_strOut As String
Dim l_strThisChar As String
Dim i As Integer
    'Debug.Print p_strIn
    For i = 1 To Len(p_strIn) Step 5
        l_strThisChar = Mid(p_strIn, i, 5)
        Select Case l_strThisChar
            Case "_____"
                l_strThisChar = "0"
            Case "____."
                l_strThisChar = "9"
            Case "___.."
                l_strThisChar = "8"
            Case "__..."
                l_strThisChar = "7"
            Case Else
                l_strThisChar = "!!Error - " + l_strThisChar + "!!"
        End Select
        l_strOut = l_strOut + l_strThisChar
    Next
    'Debug.Print l_strOut
    
    TranslateDranowebsNumberStrings = l_strOut
    
End Function

Test it by typing in:
Code:
?testmorse()
in the immediate window.
 

Dranoweb

Registered User.
Local time
Today, 19:02
Joined
Sep 28, 2009
Messages
68
Ok... this certainly turned into a complex topic in a hurry.

The number of 45 may be incorrect, as I based this on an average count of morse characters, on the few "packets" I have been able to translate manually.

45 represented morse characters, and they are 21 real characters.

The strings I have are many, many end to end "detections" (transmitted packets).

As this system, if you can call it that, was not my own design, I know only what was explaind to me by it's designer, while detailed there may be some issues with the information.

I have been dumped with the task of making the dat ausable again, as the original receiver, did not register gaps at the desired interval, in addition there were occasional dropouts, and the receiving software failed to delimiate this also.

I have a suspiscion that there may be another character inserted at regular intervals as a time code of some sort.

The units produce only 10 states at a maximum, so theoretically, only those 10 number combinations listed on page one of this post are actually used.

At any rate here is a sample of what I have:

Code:
-.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- --... .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ----. .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ... ----. ----- ----- ----- .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ----. ..-. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ---.. ..-. .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ..

This chunk came in while unit "number 3" was the only one in operation. A patchy day and I beleive a few dropouts. This is one that has not delimiated properly, and I'm in the process of manually translating it.
 
Local time
Today, 04:02
Joined
Mar 4, 2008
Messages
3,856
But, each character is delineated, by a space. I was under the impression that it was all run-on.

You also have a "Q" character.

This should work to get it in a bit better state:
Code:
Function SecondGoRound() As String
Dim l_strIn As String
Dim l_strOut As String
Dim l_iNext As Integer
Dim i As String
    l_strIn = "-.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- --... .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ----. .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ... ----. ----- ----- ----- .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ----. .. -.. ----- ----- ----- ----- --... .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ----. ..-. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- ----- ---.. ..-. .. ... ----- ----- ----- ----- ---.. .. ..- ----- ----- ----- .."
    i = 0
    Do While Len(l_strIn) > 0
        l_iNext = InStr(1, l_strIn, " ")
        If l_iNext <> 0 Then
            l_strOut = l_strOut + DecodeMorse(Trim(Left(l_strIn, l_iNext)))
        
            l_strIn = Right(l_strIn, Len(l_strIn) - l_iNext)
        Else
            
            'Debug.Print "Done"
            l_strOut = l_strOut + DecodeMorse(Trim(l_strIn))
            l_strIn = ""
        End If
    Loop
    'Debug.Print l_strOut
    l_strOut = Replace(l_strOut, "I", "I" & vbCrLf)
    SecondGoRound = l_strOut
End Function
Function DecodeMorse(p_strIn As String) As String
    Select Case p_strIn
        Case "-.." 'D
            DecodeMorse = "D"
        Case ".." 'I
            DecodeMorse = "I"
        Case "..." 'S
            DecodeMorse = "S"
        Case "..-"
            DecodeMorse = "U"
        Case "..-." 'Q
            DecodeMorse = "Q"
        Case "-----" '0
            DecodeMorse = "0"
        Case "--..." '7
            DecodeMorse = "7"
        Case "---.." '8
            DecodeMorse = "8"
        Case "----." '9
            DecodeMorse = "9"
        Case Else
            DecodeMorse = "!!Error - |" + p_strIn + "| is not defined"
            Debug.Print "!!Error - |" + p_strIn + "| is not defined"
        End Select
End Function

Test it with:
Code:
?secondgoround
in the immediate window.
 

Dranoweb

Registered User.
Local time
Today, 19:02
Joined
Sep 28, 2009
Messages
68
I must have accidentally pasted my manual transcription. I have manually added the spaces there to values I could astertain as correct.

Unfortunately, I don't recall a "q" anywhere in it.

The untouched strings do not contain spaces. - hence the difficulty.
 

Dranoweb

Registered User.
Local time
Today, 19:02
Joined
Sep 28, 2009
Messages
68
I have to thank everyone for their wonderful input.

I have managed to get my data chopped up into managable portions using fixed delimiation when importing into access.

The code provided has assisted me in sorting out the anomalous data left behind.

This isn't going to be an ongoing thing, rather a means of storing the archives in a more usable fashion.

I will however have another interesting project, based on a similar principle in the near future, but I will reserve that for another thread.

Thanks again for your time and effort, I can certainly see that you all like a challenge and I can relate well to the urge to keep at it.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:02
Joined
Sep 12, 2006
Messages
15,662
I have to thank everyone for their wonderful input.

I will however have another interesting project, based on a similar principle in the near future, but I will reserve that for another thread.

Thanks again for your time and effort, I can certainly see that you all like a challenge and I can relate well to the urge to keep at it.

interesting or irritating?

its amazing how much time contributors will spend on some things isnt it!
 

Dranoweb

Registered User.
Local time
Today, 19:02
Joined
Sep 28, 2009
Messages
68
When I first made the post, I didn't have the whole story myself.

I simply had a pile of data thrown at me and given the task of interpreting it.

I would point out that replies here are optional, and if one finds this topic irritating, that they are under no obligation to reply.

My original post was to do with how to handle a string in a particular way. This question was answered exceptionally well - and I thank all who contributed.

the applications and actual data involved in this project could be also considered sensitive, and hence I am instructed to reveal only what is necessary to resolve the issues that I am experiencing.

As you may be aware, the internet connects a great variety of different people and places. If data security is an issue, one cannot make it's encryption technique public.

I understand the disappointment in the futility that some of you may feel, and I can only apologize for that. However, I have been instructed to redesign the system altogether.

This situation is equally frustrating for myself, this also limits the time for a perfect solution. I now have (with the help of contributors here) a solution that "works" in an adequate fashion, enough to solve the immediate issues.

Once again, the help and advice is HIGHLY appreciated, please do not think otherwise.
 

Dranoweb

Registered User.
Local time
Today, 19:02
Joined
Sep 28, 2009
Messages
68
Just for the benfit of those who contributed, I did finally get this working.

After a long rodeal struggling with access, I ended up turning to vba in excel. This meant one less step.

The coding operates a little differently, but the basic functions appear to work just as well in access's version of vba.

I ended up with two text boxes, (textbox1) for the string and (textbox2) for the decoded morse.

A button obviously was included to execute the code, and the code is as follows:

Private Sub CommandButton3_Click()
Dim Strtxt As String
Dim Chartxt As String

Strtxt = TextBox1.Text
Chartxt = Left$(Strtxt, 2)
TextBox2.Text = Chartxt
'CODE HANDLER STARTS HERE
If TextBox2.Text = ".----" Then
TextBox3.Text = TextBox3.Text + "1"
End If


'END CODE HANDLER
If TextBox1.Text = "" Then
Else
TextBox1.Text = Right$(TextBox1.Text, Len(TextBox1.Text) - 2)
End If
End Sub

I have not included all the hard coded conversions, but this should be enough to demonstarate the process.

Again, thanks for the assistance, the irritation was worthwhile as the end result works better than expected.
 

Dranoweb

Registered User.
Local time
Today, 19:02
Joined
Sep 28, 2009
Messages
68
I know this is an old thread, but i just crossed paths with it in search of ther more pressing matters. Just wanted to take the time to thank everyone who posted. You all put in considerable time it seems, and it did help me resolve my issues in the end.

So thankyou once again everyone.
 

Users who are viewing this thread

Top Bottom