Author Topic: Visual basic code, simple (non SGDK related)  (Read 12774 times)

Gohst

  • Regular
  • **
  • Posts: 31
    • View Profile
    • http://mybrain.ej.am
    • Email
Visual basic code, simple (non SGDK related)
« on: 2005-04-16, 07:24:26 PM »
OK, so I've been messing around with morse code recently and I thought it would be easier to have a thing where you type in a word and it comes out as morse code. So it would check the letter, then place it in another form with its corresponing dots and dashes..

SGDK would be checked and S = ... G = --. D = -.. K = -.-

SGDK = ... --. -.. -.-

It would remove punctuation ( a full stop would add confusion ) and upper and lower case don't matter. And it would decode back again so you can give it to a friend and pass messages.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Visual basic code, simple (non SGDK related)
« Reply #1 on: 2005-04-17, 04:33:13 PM »
Useful if you've got a telegraph lying around, but otherwise, there are better ways to do things.  Binary, for example.  And it's easier, too.  Don't need to do it by cases for each letter.

For example, to convert any string to binary:

Code: [Select]
Private Function strToBin(str As String) As String
    Dim output As String, i As Integer
    For i = 1 To Len(str)
        output = output & bin(Asc(Mid(str, i, 1)))
    Next i
    strToBin = output
End Function

Private Function bin(ByVal intIn As Integer) As String
    Dim output As String, j As Integer, k As Integer
    Do
        j = Int(intIn / 2)
        k = intIn - j * 2
        intIn = j
        output = CStr(k) & output
    Loop While intIn <> 0
    bin = output
End Function
Edward Dassmesser

Gohst

  • Regular
  • **
  • Posts: 31
    • View Profile
    • http://mybrain.ej.am
    • Email
Visual basic code, simple (non SGDK related)
« Reply #2 on: 2005-04-18, 04:57:42 AM »
Nah binary would be... nerdy ha ha

Well anyway you dont need caps for each letter the case doesn't matter in morse code. It would remove punctuation (astrixes brackets exclamation marks etc etc) so it would probably be just simple as setting it to recognise

a or A and converting it to .-

I'm pretty sure you can use numbers to detemine what letters to convert so setting them for lower and upper case would be pretty easy, wouldn't it?

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Visual basic code, simple (non SGDK related)
« Reply #3 on: 2005-04-18, 09:44:28 AM »
Not caps, cases.  That is to say, you don't have to say:

select case ucase(letter)
    case "A"
        out = ".-"
    case "B"
        out = "--"
'etc
end select

because you can't calculate the morse code for each letter.  And if you do binary, you get to keep punctuation and capitalization and everything, which is a good thing in my opinion.  It makes it easier to read when you decode it.
Edward Dassmesser

Gohst

  • Regular
  • **
  • Posts: 31
    • View Profile
    • http://mybrain.ej.am
    • Email
Visual basic code, simple (non SGDK related)
« Reply #4 on: 2005-04-18, 08:27:21 PM »
Well yeah. Probably. But sending a message in morse code is cooler than sending it in binary though, wouldn't you agree? They would only be short messages though, not sending War and Peace here!  ;D

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Visual basic code, simple (non SGDK related)
« Reply #5 on: 2005-04-18, 09:01:09 PM »
Well, if you're going for cool, then sending it encrypted into an image or in ancient greek would be cool too.

Actually, that would be cool.  Or cooler still, would be to convert it to morse code, then create an algorithm to load into a sound program (i.e. Goldwave) that would actually make the dots and dashes.
Edward Dassmesser

Gohst

  • Regular
  • **
  • Posts: 31
    • View Profile
    • http://mybrain.ej.am
    • Email
Visual basic code, simple (non SGDK related)
« Reply #6 on: 2005-04-18, 09:03:39 PM »
Thats just crazy. and I don't know anything about VB in the first place so thats why I asked for help. I can't create algorithms or anything.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Visual basic code, simple (non SGDK related)
« Reply #7 on: 2005-04-19, 05:53:51 AM »
Here's some code that you can use to convert morse code back to normal letters.  Enter periods for dits and minuses for dahs and spaces for letter separators.  As you type it will convert the dits and dahs typed into in Text1 to letters and numbers displayed in Text2 using international morse code (not American Morse code).  Just put this code into a VB form that has 2 textboxes and run it:
Code: [Select]

Function ConvertLetterInternational(MorseLetter As String) As String
   Dim Result As String
   Select Case MorseLetter
      Case ".-"
         Result = "A"
      Case "-..."
         Result = "B"
      Case "-.-."
         Result = "C"
      Case "-.."
         Result = "D"
      Case "."
         Result = "E"
      Case "..-."
         Result = "F"
      Case "--."
         Result = "G"
      Case "...."
         Result = "H"
      Case ".."
         Result = "I"
      Case ".---"
         Result = "J"
      Case "-.-"
         Result = "K"
      Case ".-.."
         Result = "L"
      Case "--"
         Result = "M"
      Case "-."
         Result = "N"
      Case "---"
         Result = "O"
      Case ".--."
         Result = "P"
      Case "--.-"
         Result = "Q"
      Case ".-."
         Result = "R"
      Case "..."
         Result = "S"
      Case "-"
         Result = "T"
      Case "..-"
         Result = "U"
      Case "...-"
         Result = "V"
      Case ".--"
         Result = "W"
      Case "-..-"
         Result = "X"
      Case "-.--"
         Result = "Y"
      Case "--.."
         Result = "Z"
      Case "-----"
         Result = "0"
      Case ".----"
         Result = "1"
      Case "..---"
         Result = "2"
      Case "...--"
         Result = "3"
      Case "....-"
         Result = "4"
      Case "....."
         Result = "5"
      Case "-...."
         Result = "6"
      Case "--..."
         Result = "7"
      Case "---.."
         Result = "8"
      Case "----."
         Result = "9"
      Case ".-.-.-"
         Result = "."
      Case "--..--"
         Result = ","
      Case "..--.."
         Result = "?"
      Case ".----."
         Result = "'"
      Case "-..-."
         Result = "/"
      Case "-.--.-"
         Result = "("
      Case "---..."
         Result = ":"
      Case "-...-"
         Result = "="
      Case "-....-"
         Result = "-"
      Case ".-..-."
         Result = """"
      Case ".--.-."
         Result = "@"
      Case Else
         Result = " "
   End Select
   ConvertLetterInternational = Result
End Function

Private Sub Text1_Change()
   Dim s() As String
   Dim i As Integer
   Dim Result As String
   s = Split(Text1.Text, " ")
   For i = 0 To UBound(s)
      Result = Result & ConvertLetterInternational(s(i))
   Next
   Text2.Text = Result
End Sub

Gohst

  • Regular
  • **
  • Posts: 31
    • View Profile
    • http://mybrain.ej.am
    • Email
Visual basic code, simple (non SGDK related)
« Reply #8 on: 2005-04-19, 06:17:25 AM »
does that make morse code = real words?

if yes then that is very good.

if yes then how would we convert real words back into morse code?

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Visual basic code, simple (non SGDK related)
« Reply #9 on: 2005-04-19, 07:28:46 AM »
Quote from: "Gohst"
Thats just crazy. and I don't know anything about VB in the first place so thats why I asked for help. I can't create algorithms or anything.


Oh, you're asking for help.  You never said.  All you said was

Quote from: "Gohst"
OK, so I've been messing around with morse code recently and I thought it would be easier to have a thing where you type in a word and it comes out as morse code. So it would check the letter, then place it in another form with its corresponing dots and dashes..

SGDK would be checked and S = ... G = --. D = -.. K = -.-

SGDK = ... --. -.. -.-

It would remove punctuation ( a full stop would add confusion ) and upper and lower case don't matter. And it would decode back again so you can give it to a friend and pass messages.


So I thought it was a discussion.  You never actually said "Could anybody help?"  And the algorithm for goldwave isn't really all that hard once you look at it.

For code to convert letters to Morse code, take BlueMonk's code and just switch all the letters with the morse code above them

For example, instead of

Code: [Select]

      Case ".-"
         Result = "A"

it would be
Code: [Select]

      Case "A"
         Result = ".-"


And then, instead of seperating the string into an array using the split function, you would just go through a loop like this

Code: [Select]

   For i = 0 To Len(Text1.text)
      Result = Result & ConvertLetterInternational(mid(text1,text,i,1))
   Next
   Text2.Text = Result
Edward Dassmesser

Gohst

  • Regular
  • **
  • Posts: 31
    • View Profile
    • http://mybrain.ej.am
    • Email
Visual basic code, simple (non SGDK related)
« Reply #10 on: 2005-04-19, 07:44:24 AM »
Could you write a full thing for me like blue monk did? I dont understand VB so i dont know when you put loops in and stuff.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Visual basic code, simple (non SGDK related)
« Reply #11 on: 2005-04-19, 08:47:41 AM »
Code: [Select]

Function CharToMorse(Letter As String) As String
   Dim Result As String
   Select Case MorseLetter
      Case "A"
         Result = ".-"
      Case "B"
         Result = "-..."
      Case "C"
         Result = "-.-."
      Case "D"
         Result = "-.."
      Case "E"
         Result = "."
      Case "F"
         Result = "..-."
      Case "G"
         Result = "--."
      Case "H"
         Result = "...."
      Case "I"
         Result = ".."
      Case "J"
         Result = ".---"
      Case "K"
         Result = "-.-"
      Case "L"
         Result = ".-.."
      Case "M"
         Result = "--"
      Case "N"
         Result = "-."
      Case "O"
         Result = "---"
      Case "P"
         Result = ".--."
      Case "Q"
         Result = "--.-"
      Case "R"
         Result = ".-."
      Case "S"
         Result = "..."
      Case "T"
         Result = "-"
      Case "U"
         Result = "..-"
      Case "V"
         Result = "...-"
      Case "W"
         Result = ".--"
      Case "X"
         Result = "-..-"
      Case "Y"
         Result = "-.--"
      Case "Z"
         Result = "--.."
      Case "0"
         Result = "-----"
      Case "1"
         Result = ".----"
      Case "2"
         Result = "..---"
      Case "3"
         Result = "...--"
      Case "4"
         Result = "....-"
      Case "5"
         Result = "....."
      Case "6"
         Result = "-...."
      Case "7"
         Result = "--..."
      Case "8"
         Result = "---.."
      Case "9"
         Result = "----."
      Case "."
         Result = ".-.-.-"
      Case ","
         Result = "--..--"
      Case "?"
         Result = "..--.."
      Case "'"
         Result = ".----."
      Case "/"
         Result = "-..-."
      Case "("
         Result = "-.--.-"
      Case ":"
         Result = "---..."
      Case "="
         Result = "-...-"
      Case "-"
         Result = "-....-"
      Case """"
         Result = ".-..-."
      Case "@"
         Result = ".--.-."
   End Select
   CharToMorse = Result & " "
End Function

Private Sub Text1_Change()
   Dim i As Integer
   Dim Result As String
   For i = 1 To Len(Text1.text)
      Result = Result & CharToMorse(mid(text1.text,i,1))
   Next
   Text2.Text = Result
End Sub


Really, I think it'd be a good thing to play around with VB a bunch and really learn it for yourself.
Edward Dassmesser

Gohst

  • Regular
  • **
  • Posts: 31
    • View Profile
    • http://mybrain.ej.am
    • Email
Visual basic code, simple (non SGDK related)
« Reply #12 on: 2005-04-19, 08:56:23 AM »
I dont use it much and I'm not too interested so I'll just ask if i have a simple problem again in the future. Thanks guys, you rock!

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Homework
« Reply #13 on: 2005-04-20, 04:53:36 AM »
Well, I just hope we didn't do someone else's homework ;)

Gohst

  • Regular
  • **
  • Posts: 31
    • View Profile
    • http://mybrain.ej.am
    • Email
Visual basic code, simple (non SGDK related)
« Reply #14 on: 2005-04-20, 06:31:27 PM »
I wondered if anyone would think this was homework. No, its not I've finished school (i failed the computer class big-time though) and I'm persuing a career in the film industry.

Do you want to see a film I made?


http://gohst.cwhnetworks.com/main.html