473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How could bytes be converted into ASCII in a secret code form for students?

For some of my secondary students studying bits and bytes, I'd like to
make a form in which they can create secret codes with bytes. I'd like
the form to have a memo field that can only accept 0s and 1s and
spaces. I was envisioning the following:

--On after update or so, check the memo and only allow groups of eight
0s and 1s, and only single spaces.

--If students typed groups with < or > eight 0s or 1s, show a msgbox to
alert the them of their errors.

--With the click of a cmdbutton, show the students the result of their
byte coding either in a second memo field or in a report field.

My main problem is that I don't really know how to program ;-) Would
this whole coding of secret coding thing be possible?

I do have some cool code that I've come across that removes double,
triple, and all extra spaces from fields. It also inserts a period at
the end of the data in case the user forgot. Here's this code:
____________________

Private Sub MemoField_AfterUpdate()

Dim myLength As Long
Dim mydata As String
Dim lastchar As String
Dim X As Long
Dim temphold As String

If Not IsNull(MemoField) Then
mydata = Trim(MemoField)
myLength = Len(MemoField)
lastchar = Right(MemoField, 1)

End If

If lastchar = "." Or mydata = "" Then
Else
MemoField = mydata & "."
End If

temphold = ""
mydata = ""
For X = 1 To myLength
lastchar = Mid(MemoField, X, 1)
If temphold = " " And lastchar = " " Then
GoTo getnext
Else
temphold = lastchar
mydata = mydata & temphold
End If
getnext:
Next
MemoField = mydata

End Sub
____________________

Private Sub MemoField_LostFocus()

Dim myLength As Long
Dim mydata As String
Dim lastchar As String

If Not IsNull(MemoField) Then
mydata = Trim(MemoField)
myLength = Len(MemoField)
lastchar = Right(MemoField, 1)
End If

If lastchar = "." Or mydata = "" Then
Else
mydata = mydata & "."
MemoField = mydata
End If

End Sub
____________________

Many thanks in advance.

Feb 4 '06 #1
2 1681

Put 2 text boxes (Text0 and Text1) on a form then copy the following code to
the module behind the form
Private Sub Text0_KeyPress(KeyAscii As Integer)
' This tests that the only printable characters entered are 0,1 or <space>
' It also tests that the allowable printable characters are in the correct
position
Select Case KeyAscii
Case 48, 49
If (Len(Me.Text0.Text) + 1) Mod 9 = 0 Then
KeyAscii = 0
End If
Case 32
' Test position
If (Len(Me.Text0.Text) + 1) Mod 9 <> 0 Then
KeyAscii = 0
End If
Case Is < 32
' do nothing
Case Else
'throw away
KeyAscii = 0
End Select
End Sub

Private Sub Text0_BeforeUpdate(Cancel As Integer)
' This checks that the total length of the code entered is correct
' i.e groups of eight digits terminated by a space.
Select Case Len(Me.Text0.Text) Mod 9
Case 0, 8
' OK
Case Else
Cancel = True
MsgBox "You must complete the code"
With Me.Text0
.SelStart = Len(Me.Text0.Text)
.SelLength = 0
End With
End Select
End Sub

Private Sub Text0_AfterUpdate()
' This converts the bit code to ASCII and
' enters it into Text1
Dim varInput As Variant
Dim intCount As Integer
Dim btCount As Byte
Dim btChar As Byte
Dim strOutput As String

varInput = Split(Me.Text0.Text, " ")
For intCount = LBound(varInput) To UBound(varInput)
btChar = 0
For btCount = 0 To 7
btChar = btChar Or _
Val(Mid(varInput(intCount), 8 - btCount, 1)) * 2 ^
btCount
Next
strOutput = strOutput & Chr(btChar)
Next
Me.Text1 = strOutput
End Sub

Private Sub Text1_AfterUpdate()
' This converts the ASCII to bit code and
' enters it into Text0
Dim varInput As Variant
Dim intCount As Integer
Dim btCount As Byte
Dim btChar As Byte
Dim strInput As String
Dim strOutput As String

strInput = Me.Text1.Text
For intCount = 1 To Len(strInput)
btChar = Asc(Mid(strInput, intCount, 1))
For btCount = 0 To 7
strOutput = strOutput _
& Abs(((btChar And (2 ^ (7 - btCount))) = (2 ^ (7 -
btCount))))
Next
strOutput = strOutput & " "
Next
If Len(strOutput) > 1 Then
strOutput = Left(strOutput, Len(strOutput) - 1)
End If
Me.Text0 = strOutput
End Sub
--

Terry Kreft
"Arnold" <ee*******@kc.rr.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
For some of my secondary students studying bits and bytes, I'd like to
make a form in which they can create secret codes with bytes. I'd like
the form to have a memo field that can only accept 0s and 1s and
spaces. I was envisioning the following:

--On after update or so, check the memo and only allow groups of eight
0s and 1s, and only single spaces.

--If students typed groups with < or > eight 0s or 1s, show a msgbox to
alert the them of their errors.

--With the click of a cmdbutton, show the students the result of their
byte coding either in a second memo field or in a report field.

My main problem is that I don't really know how to program ;-) Would
this whole coding of secret coding thing be possible?

I do have some cool code that I've come across that removes double,
triple, and all extra spaces from fields. It also inserts a period at
the end of the data in case the user forgot. Here's this code:
____________________

Private Sub MemoField_AfterUpdate()

Dim myLength As Long
Dim mydata As String
Dim lastchar As String
Dim X As Long
Dim temphold As String

If Not IsNull(MemoField) Then
mydata = Trim(MemoField)
myLength = Len(MemoField)
lastchar = Right(MemoField, 1)

End If

If lastchar = "." Or mydata = "" Then
Else
MemoField = mydata & "."
End If

temphold = ""
mydata = ""
For X = 1 To myLength
lastchar = Mid(MemoField, X, 1)
If temphold = " " And lastchar = " " Then
GoTo getnext
Else
temphold = lastchar
mydata = mydata & temphold
End If
getnext:
Next
MemoField = mydata

End Sub
____________________

Private Sub MemoField_LostFocus()

Dim myLength As Long
Dim mydata As String
Dim lastchar As String

If Not IsNull(MemoField) Then
mydata = Trim(MemoField)
myLength = Len(MemoField)
lastchar = Right(MemoField, 1)
End If

If lastchar = "." Or mydata = "" Then
Else
mydata = mydata & "."
MemoField = mydata
End If

End Sub
____________________

Many thanks in advance.

Feb 4 '06 #2
Terry,

That's incredible! Thank you so much for your code.

Feb 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DebbieG | last post by:
I have a form based on this query: SELECT Students.LastSerDT, OtherInfo.Served, OtherInfo.HSGradYr, OtherInfo.ActivePart, OtherInfo.Served, Students.SSN, & ", " & & " " & AS Name,...
2
by: SK | last post by:
Hi, I am not able to convert the response stream from HttpWebResponse into bytes properly. Here is the relevent code - HttpWebResponse response = (HttpWebResponse)request.GetResponse (); ...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
13
by: Martin Herbert Dietze | last post by:
Hi, I need to calculate the physical length of text in a text input. The term "physical" means in this context, that I consider 7bit-Ascii as one-byte-per character. Other characters may be...
14
by: abhi147 | last post by:
Hi , I want to convert an array of bytes like : {79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3} into Unicode character with ISO-8859-1 standard. Can anyone help me .. how should...
4
by: =?Utf-8?B?Ym9va2VyQG1ndA==?= | last post by:
Ok, I inherited some code written in vb that is part of a web application. My overall objective is to be able to take multiple names from a "LastName" text box and use those names in my SQL query...
19
by: Serman D. | last post by:
Hi, I have very limited C knowledge. I want to convert to output from a MD5 hash algorithm to printable ascii similar to the output of the md5sum in GNU coreutils. Any help on how to do the...
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.