There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop mac malware motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows vista windows xp winxp wireless wmp
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
VB Binary Read/Write


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
BuntyKainth's Avatar
Junior Member with 12 posts.
 
Join Date: Aug 2003
10-Aug-2003, 01:15 PM #1
Question VB Binary Read/Write
Hi i was wondering if there is a way in which i can write some data using vb into a file but in binary format so that if someone opens it it cannot be read. for example a file called
"C:\windows\desktop\bin.dat" cantains that data "HEllo" but in binary.

also having done this is there a way in which i can then open the binary file and read the data and convert it back into text to display within a text field.

ive tryed doing it but something seems to go wrong. i would really appreciate some help on this guys its kinda difficult.

Thankyou have a nice day.
TimCottee's Avatar
Senior Member with 186 posts.
 
Join Date: Oct 2001
Location: Southampton, England
11-Aug-2003, 09:29 AM #2
A simple way of doing this is as follows, all this essentially does is do a replace of characters with others so that it appears to scramble the content. There is no real encryption and it could be decoded if someone wanted to spend the time:

Code:
Private Sub Command1_Click()
    WriteFile "c:\development\test.txt", "Hello there how is this then?"
End Sub

Private Sub Command2_Click()
    MsgBox ReadFile("c:\development\test.txt")
End Sub

Private Sub WriteFile(ByVal FileName As String, ByVal Content As String)
    Open FileName For Binary As #1
    Put #1, , Encode(Content)
    Close #1
End Sub

Private Function ReadFile(ByVal FileName As String) As String
    Open FileName For Input As #1
    ReadFile = Decode(Input(LOF(1), 1))
    Close #1
End Function

Private Function Encode(ByVal Content As String) As String
    Dim aryBytes() As String
    ReDim aryBytes(Len(Content))
    Dim intPos As Integer
    For intPos = 1 To Len(Content)
        intChar = Asc(Mid(Content, intPos, 1)) - 64
        If intChar < 0 Then intChar = intChar + 256
        aryBytes(intPos) = Chr(intChar)
    Next
    Encode = Join(aryBytes, "")
End Function

Private Function Decode(ByVal Content As String) As String
    Dim aryChars() As String
    ReDim aryChars(Len(Content))
    Dim intPos As Integer
    For intPos = 1 To Len(Content)
        intChar = Asc(Mid(Content, intPos, 1)) + 64
        If intChar > 255 Then intChar = intChar - 256
        aryChars(intPos) = Chr(intChar)
    Next
    Decode = Join(aryChars, "")
End Function
BuntyKainth's Avatar
Junior Member with 12 posts.
 
Join Date: Aug 2003
17-Aug-2003, 05:24 PM #3
Wicked dood thats brillient, nice one have a nice day
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:41 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.