|
Hello,
I wish to develop a on screen keyboard just like the one which comes with Windows XP so that I can transfer data to any application which is selected for example notepad, webpage, word, excel etc. Any help with code samples is highly appreciated.
Cheers!
|
|
|
|
|
Do you want to do it in C#, or VB.NET ? Please don't cross post.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I'm trying to build a program that does the following. I think I can do everything but make the program load a 20 MB Binary file from the C:\ drive, and:
1. Take a pair of bits from the beginning of the file
2. Consider the bits, and do the following:
--If they are 00 or 11, toss both of them from the file.
--If the are 01 or 10, keep the first bit, and toss the second one from the file.
3. Move on to the next 2 bits. Repeat.
It needs to do this to the entire file. I plan to simply type in the file location (Like c:\documents and settings\my user name\my documents\randump\dump1.bin) into a text box. It is named "find". The parse will be started by a button named "parse".
There are just possible problems:
1. There is a big chance that the amount of bits removed won't be divisible by 8. This will create an uneven byte at the end. Does the computer care, or should I be worried?
2. When the binary files are opened in notepad, they look like characters. The program needs to see the bits, not characters.
I'm a VB noob, so can somebody show me how one is to do this?
And if you need any more information about the form setup, please ask.
Thanks in advance
(I'm not in classes. This ain't homework. I learned everything I know from trial and error, and if I tried that with this, I'd be at this computer until the ends of time.)
|
|
|
|
|
Use an io.binaryreader's readbytes method to read bytes into a bitarray, one of whose constructor overloads takes an array of bytes. Don't lose faith in trial and error so quickly; I didn't know how to do that two minutes ago.
Re: problems:
0. Why are you doing this?
1. Yes, the computer cares. For a solution, think carefully about problem 0. You are for reasons unexplained creating a file that no program but your own will be able to read. You could use fill characters or something; without knowing more about what this file represents, I can't help you more than that. If you don't mind multiplying the file's size by eight, you could use binarywriter's write method, with a boolean variable (one byte in size) representing each bit (one = true, etc.).
2. Notepad is reading the bits as bytes using its default encoding scheme (Unicode? UTF-16? I don't know, I don't care). The method described above won't do that.
Good luck,
Steve
|
|
|
|
|
0: If you have ever heard of Random.org, I am working with the webmaster to supply him with raw data. I run a highly similar setup to his, so all I need to do is run a skew correction algorithm devised by John von Neumann. Since Prof. Haahr's software does this as it's coming out of the radio, I can't use it.
1: Prof. Haahr can take this data and shove it right into a buffer. If no skew correction is applied (the goal of this program), then my data is no good.
2. I ran notepad because I use a splitter to break bit dumps (that are over 900 MB in size each) into 19MB chunks, I wanted to make sure there were no added characters. There was not, so all that needs to happen is Skew Correction.
I'm going to try io.binaryreader, if it's built into VB, but in case that is isn't, where is it, and how do I use it?
Thanks!
|
|
|
|
|
who needs to know? wrote: I'm going to try io.binaryreader, if it's built into VB, but in case that is isn't, where is it, and how do I use it?
It is in the System.IO namespace.
|
|
|
|
|
That is pretty damn cool. Given what you're doing, I suggest building the files of arbitrary size out of the original 900MB dump (even if you have to split it up to make the program run faster), by cutting off once the file reaches a length you have specified. That way it'll always get to a size in bits divisible by 8, and you won't have to worry about cramming non-random bits onto the end.
I believe someone answered the io.binaryreader question, but in general, when faced with a problem of this type in VB, type "system." (including the ".") and use the list that comes up to search through the primary namespaces: io, drawing, etc., which will be marked with "{}" to their left. Learn them; their names are descriptive of what they do (except for system.reflection, which is a whole other ball game). For what you're working with (although you seem to have it sorted), my.computer.filesystem is another good place to look in terms of file management.
I'm not sure "take this data and shove it right up his buffer" is the most politic choice of words. Ha ha.
Steve
|
|
|
|
|
I'm still not fully understanding how to:
Make VB open the file at the location specified in the textbox "find"
Make VB load the file's data
Make VB consider the data 2 bits at a time
Make VB change the file
Sorry, but I'm a little slow.
modified on Monday, February 18, 2008 1:36 PM
|
|
|
|
|
What version of Visual basic are you using? Most of this should be fairly easy to figure out using the Intellisense capabilities of VB .NET. Use a filestream object to load the file in the first place; this combines the steps of opening a file and loading its data. In order to examine the data 2 at a time, use the operations listed in another reply (OR, XOR, etc.): I believe they are methods of the bitarray object. You just want to see whether bit 1 is equal to bit 2 or not, so those comparators should be sufficient.
Do not change the file - that would be a complex and unnecessary process. Rather, create a new and empty bitarray and fill in any bits your algorithm deems necessary. From there, you should be able to write it to a file - just look through the bitarray object's methods and something should come up - write to an array of byte; from there it can be written to a file using a binarywriter(?) object.
Steve
|
|
|
|
|
Don't I need to call a... what's it called... "winshell" to make it load somthing from the drive?
|
|
|
|
|
I guess another posible method is to take the data, and load the raw bits as 1's or 0's into a text box, change them, convert them to characters, and save them to a .bin file.
|
|
|
|
|
No, not really. Or rather, calling Winshell or some similar low-level utility is not, I regret to say, my area of expertise. People who know this sort of thing tend to look upon themselves as "genuine" computer experts, whereas I see them as people who build welding torches that the rest of us use to build skyscrapers. At any rate, before we get too far into rant territory, there's more than one way to skin a cat. The way you mentioned is probably possible, but unnecessary, and I can't help with it - instead you could use the prebuilt VB classes that are the target of the aforementioned gearhead scorn.
As for the textbox method, God forbid. Converting a bit to a character such as a 1 or 0 would be unnecessary, as would putting them in a User Interface element like a textbox - never do something unnecessary. Besides, saving the "1" character will not save a binary 1 - it will save an 8-bit character from the basic 128- or 256-member character set. This will represent a "1" as far as, for example, notepad is concerned, but is not the same as a logical 1.
Use VB's help to look up the classes we've already discussed - it's a valuable asset for examples, general concepts, etc.
Steve
|
|
|
|
|
I still don't understand. I'm sorry, I'm 13 and I'm tryign to understand the most simple programming language available.
|
|
|
|
|
Oohhhhhh, that explains it. I remember being that age and trying to program. Your brain isn't set enough to really get the concepts yet, unless you're very unusual. I was always writing programs that didn't do anything. Look at my last post near the bottom of the page; as for the rest, focus on exactly what you're doing - don't get distracted, and always remember to use the absolute simplest method possible to solve a problem. General syntax for VB can be found on msdn.microsoft.com, but here's some:
Dim a as new object (arguments)
a: is the name of the object
new: this is a specialized function that creates a new instance of an object. An object is like a blueprint, an instance of the object is like a building built from that blueprint. Think of all those identical suburban houses as instances of a House object.
object: can be any object - integer, textbox, filestream, bitarray, whatever. Not everything can be declared as "New."
Arguments are other objects that the object needs to generate an Instance. For example, the BitArray needs to get its bits from somewhere. Therefore, you tell it "use this array of bytes to make an array of bits" by passing in an argument that is an array of bytes.
dim b as byte means make one byte
dim b() as byte means make an array of bytes
dim b(10) as byte means make an array of 11 bytes (0 counts as a number).
This is only a beginning. You've got a long way ahead of you; I'd take a month or so to get really familiar with the objects in question. Use the help files, get to know the buzzwords that have definite, set meanings. Don't give up. If you learn to program at your young age, it'll be in your bones like it never can be if you only learn in University.
|
|
|
|
|
System.Object.New()
System.Collections.BitArray.New()
comes back as a declaration problem, wherever I put them...
|
|
|
|
|
I probably look like the biggest dumbass on the planet.
How to I make a bitarray, how do I name it, and how do I use "new(byte" and make it get somthing from a text box (I'm just testing it out before I mess around with files)
|
|
|
|
|
Dim fs As new IO.FileStream("[Path Here]", IO.FileMode.Open)
Dim b(fs.Length - 1) As Byte
fs.Read(b, 0, fs.Length - 1)
Dim ba As New BitArray(b)
The io.filestream is a fairly abstract concept. A "Stream" in VB is a one-way conduit between object X and the program - a filestream can be used for input or output, depending on the argument supplied. In this case, you're only reading, so we specify IO.FileMode.Open because we want to read from the file.
From here, we
1. create an array of bytes - dim b(size) as byte
2. fill that array from the file (fs.read)
3. use the array now containing the file to fill the bitarray.
You couldn't do this from a textbox because a textbox contains characters, not bits or bytes.
I suggest reading up on the concepts behind this for a little while before continuing - these are fairly advanced concepts if one is not familiar with them, and what you are doing will take considerably more code than the four lines supplied here.
|
|
|
|
|
How do I replace [path here] with it reading from a path from a textbox?
|
|
|
|
|
|
Excellent! One third the way through the proramming!
Now we just need to:
Make it consider the bits in pairs, and change them
Keep it from going over the same bits twice
Save the bits to a file.
The problem I see it this, when I open a binary file in notepad, I see characters. VB is working with the binary, and when it saves, I'm afraid if I open the file up in notepad, ill see "10101001111001" instead of characters.
Prof. Haahr's site will see the binary, and if VB saves it as 10100101, Haahr's site will see: 1111111100000000111111110000000000000000111111110000000011111111, so I want it to save 10100101 (assuming it equals "a") as "a".
You see, heres my problem. I don't trust a computer to do it's job. I wanna make sure that it will do exactly what I expect it to. I don't know if that makes me a bad program!
|
|
|
|
|
How do I make it condsider the bits in pairs, and do this to each one?
IF bit0 = bit1 then (whatever deletes both bits) ELSEIF (toss second bit)
GO ON
REPEAT IF
modified on Monday, February 18, 2008 4:22 PM
|
|
|
|
|
Steve gave you the right solution for getting your data into an array.
To work with bits though you need to learn what the AND, OR, XOR, <<, >> commands mean because computers don't know how to deal with anything smaller than a byte directly. If you google bitwise there are lots of good tutorials that will explain each of them well. The AND command will allow you to isolate the bits you want to test, then you can easily set up a condition statement to to test the number without irrelevent bits infearing. For instance you can isolate the first 2 bits like this
result = yourbyte AND mask
if mask has a binary value like this 11000000 then all the irrelevent bits will become zero and allow you to test for only 2 different numbers.
hope this helps,
Mike
|
|
|
|
|
I have created an application in which there r several forms open and when i click logout button then all the open forms should get closed and login page should get open.so, how do i close all open forms.
coolsatty
|
|
|
|
|
Application.OpenForms Gets a collection of opened forms owned by the application.
Eslam Afifi
|
|
|
|
|
but how do i close it.
coolsatty
|
|
|
|
|