473,804 Members | 3,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_After Update()

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

If Not IsNull(MemoFiel d) 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_LostF ocus()

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

If Not IsNull(MemoFiel d) 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 1697

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.T ext) + 1) Mod 9 = 0 Then
KeyAscii = 0
End If
Case 32
' Test position
If (Len(Me.Text0.T ext) + 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_BeforeUpd ate(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.Te xt) Mod 9
Case 0, 8
' OK
Case Else
Cancel = True
MsgBox "You must complete the code"
With Me.Text0
.SelStart = Len(Me.Text0.Te xt)
.SelLength = 0
End With
End Select
End Sub

Private Sub Text0_AfterUpda te()
' 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(varInpu t(intCount), 8 - btCount, 1)) * 2 ^
btCount
Next
strOutput = strOutput & Chr(btChar)
Next
Me.Text1 = strOutput
End Sub

Private Sub Text1_AfterUpda te()
' 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(strInpu t, 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.r r.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.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_After Update()

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

If Not IsNull(MemoFiel d) 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_LostF ocus()

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

If Not IsNull(MemoFiel d) 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
2619
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, Students.LastNM, Students.FirstNM, Students.MI, Students.DOB, Students.GenderCD, Students.EthnicityCD, Students.EligibilityCD, Students.UBInitiative, Students.NCESSchID, Students.ProjEntryDT, Students.ProjReEntDT, Students.LastSerDT, Students.Reason,...
2
28634
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 (); // Get the stream associated with the response.
5
3666
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 written in file are not the sent bytes. Copy and paste the following lines to observe my problem. What can I do to resolve problem ? Only System.Text.Encoding.ASCII write the same number of bytes, but not the good bytes. Someone can help me. Thanks by...
13
14274
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 longer, e.g. cyrillic would be 2 bytes per character. Is there a safe and easy way to notice non-7bit-Ascii input? Cheers,
14
6426
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 I go about doing it ? Thanks
4
1401
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 against my database. Currently the way it is coded, the text box will pass one name only to the next page, which then gets formed into the SQL query. I will provide some examples of the code that is used to perform this task... Ok, when you...
19
11427
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 conversion is appreciated. $ gcc -o test test.c md5.c $ ./test "J?n??CBW? ?}"
11
3601
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 Read_bin(ByVal ruta As String) Dim cadena As String = "" Dim dato As Array If File.Exists(ruta) = True Then
399
12970
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 to python-3000@python.org In summary, this PEP proposes to allow non-ASCII letters as identifiers in Python. If the PEP is accepted, the following identifiers would also become valid as class, function, or variable names: Löffelstiel,...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10320
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9150
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.